From 6970e7ba135091f648030510beae903d33873528 Mon Sep 17 00:00:00 2001 From: Administrator Date: Tue, 15 Oct 2024 15:56:58 -0600 Subject: [PATCH] make cidr different for each env --- ops/terraform/locals.tf | 49 ++++++++++++++++----- ops/terraform/main.tf | 12 ++--- ops/terraform/modules/network/main.tf | 38 ++++++++-------- ops/terraform/modules/network/variables.tf | 3 +- ops/terraform/modules/security/variables.tf | 1 - 5 files changed, 63 insertions(+), 40 deletions(-) diff --git a/ops/terraform/locals.tf b/ops/terraform/locals.tf index 77e0cc0b..6fc1c396 100644 --- a/ops/terraform/locals.tf +++ b/ops/terraform/locals.tf @@ -4,21 +4,46 @@ locals { environment = local.environment location = "eastus2" } - network = { - config = { + dev = { + dev = { vnetcidr = "10.0.0.0/16" websubnetcidr = "10.0.1.0/24" - appsubnetcidr = "10.0.2.0/24" - dbsubnetcidr = "10.0.3.0/24" - lbsubnetcidr = "10.0.4.0/24" + lbsubnetcidr = "10.0.2.0/24" } } - app = { - web_host_name = "webserver" - web_username = "web_user" - web_os_password = "@Webuser1" - app_host_name = "appserver" - app_username = "app_user" - app_os_password = "@Appuser1" + dev2 = { + dev2 = { + vnetcidr = "10.2.0.0/16" + websubnetcidr = "10.2.1.0/24" + lbsubnetcidr = "10.2.2.0/24" + } + } + dev3 = { + dev3 = { + vnetcidr = "10.3.0.0/16" + websubnetcidr = "10.3.1.0/24" + lbsubnetcidr = "10.3.2.0/24" + } + } + dev4 = { + dev4 = { + vnetcidr = "10.4.0.0/16" + websubnetcidr = "10.4.1.0/24" + lbsubnetcidr = "10.4.2.0/24" + } + } + dev5 = { + dev5 = { + vnetcidr = "10.5.0.0/16" + websubnetcidr = "10.5.1.0/24" + lbsubnetcidr = "10.5.2.0/24" + } + } + dev6 = { + dev6 = { + vnetcidr = "10.6.0.0/16" + websubnetcidr = "10.6.1.0/24" + lbsubnetcidr = "10.6.2.0/24" + } } } \ No newline at end of file diff --git a/ops/terraform/main.tf b/ops/terraform/main.tf index c02f8730..489a48ae 100644 --- a/ops/terraform/main.tf +++ b/ops/terraform/main.tf @@ -1,4 +1,7 @@ locals { + workspaces = "${merge(local.dev, local.dev2, local.dev3, local.dev4, local.dev5, local.dev6)}" + workspace = "${local.workspaces[terraform.workspace]}" + management_tags = { environment = local.environment resource_group = data.azurerm_resource_group.rg.name @@ -13,11 +16,9 @@ module "networking" { name = var.name location = data.azurerm_resource_group.rg.location resource_group = data.azurerm_resource_group.rg.name - vnetcidr = local.network.config.vnetcidr - websubnetcidr = local.network.config.websubnetcidr - appsubnetcidr = local.network.config.appsubnetcidr - lbsubnetcidr = local.network.config.lbsubnetcidr - dbsubnetcidr = local.network.config.dbsubnetcidr + vnetcidr = local.workspace["vnetcidr"] + websubnetcidr = local.workspace["websubnetcidr"] + lbsubnetcidr = local.workspace["lbsubnetcidr"] env = local.environment } @@ -31,7 +32,6 @@ module "securitygroup" { location = data.azurerm_resource_group.rg.location resource_group = data.azurerm_resource_group.rg.name web_subnet_id = module.networking.websubnet_id - app_subnet_id = module.networking.appsubnet_id db_subnet_id = module.networking.dbsubnet_id lb_subnet_id = module.networking.lbsubnet_id env = local.environment diff --git a/ops/terraform/modules/network/main.tf b/ops/terraform/modules/network/main.tf index 9156a2b7..56cd44dc 100644 --- a/ops/terraform/modules/network/main.tf +++ b/ops/terraform/modules/network/main.tf @@ -14,21 +14,21 @@ resource "azurerm_subnet" "web-subnet" { depends_on = [azurerm_virtual_network.vnet] } -resource "azurerm_subnet" "app-subnet" { - name = "${var.name}-app-subnet-${var.env}" - virtual_network_name = azurerm_virtual_network.vnet.name - resource_group_name = var.resource_group - address_prefixes = [var.appsubnetcidr] +# resource "azurerm_subnet" "app-subnet" { +# name = "${var.name}-app-subnet-${var.env}" +# virtual_network_name = azurerm_virtual_network.vnet.name +# resource_group_name = var.resource_group +# address_prefixes = [var.appsubnetcidr] - delegation { - name = "delegation" +# delegation { +# name = "delegation" - service_delegation { - name = "Microsoft.ContainerInstance/containerGroups" - actions = ["Microsoft.Network/virtualNetworks/subnets/action"] - } - } -} +# service_delegation { +# name = "Microsoft.ContainerInstance/containerGroups" +# actions = ["Microsoft.Network/virtualNetworks/subnets/action"] +# } +# } +# } resource "azurerm_subnet" "lb-subnet" { name = "${var.name}-lb-subnet-${var.env}" @@ -38,9 +38,9 @@ resource "azurerm_subnet" "lb-subnet" { depends_on = [azurerm_virtual_network.vnet] } -resource "azurerm_subnet" "db-subnet" { - name = "${var.name}-db-subnet-${var.env}" - virtual_network_name = azurerm_virtual_network.vnet.name - resource_group_name = var.resource_group - address_prefixes = [var.dbsubnetcidr] -} \ No newline at end of file +# resource "azurerm_subnet" "db-subnet" { +# name = "${var.name}-db-subnet-${var.env}" +# virtual_network_name = azurerm_virtual_network.vnet.name +# resource_group_name = var.resource_group +# address_prefixes = [var.dbsubnetcidr] +# } \ No newline at end of file diff --git a/ops/terraform/modules/network/variables.tf b/ops/terraform/modules/network/variables.tf index a01c9363..301bbef4 100644 --- a/ops/terraform/modules/network/variables.tf +++ b/ops/terraform/modules/network/variables.tf @@ -3,7 +3,6 @@ variable "name" {} variable "location" {} variable "vnetcidr" {} variable "websubnetcidr" {} -variable "appsubnetcidr" {} variable "lbsubnetcidr" {} -variable "dbsubnetcidr" {} +# variable "dbsubnetcidr" {} variable "env" {} \ No newline at end of file diff --git a/ops/terraform/modules/security/variables.tf b/ops/terraform/modules/security/variables.tf index 6004ce0d..f008b4f0 100644 --- a/ops/terraform/modules/security/variables.tf +++ b/ops/terraform/modules/security/variables.tf @@ -3,6 +3,5 @@ variable "name" {} variable "env" {} variable "resource_group" {} variable "web_subnet_id" {} -variable "app_subnet_id" {} variable "db_subnet_id" {} variable "lb_subnet_id" {} \ No newline at end of file