Skip to content

Commit

Permalink
make cidr different for each env
Browse files Browse the repository at this point in the history
  • Loading branch information
Administrator committed Oct 15, 2024
1 parent 953c5ca commit 6970e7b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 40 deletions.
49 changes: 37 additions & 12 deletions ops/terraform/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
12 changes: 6 additions & 6 deletions ops/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}

Expand All @@ -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
Expand Down
38 changes: 19 additions & 19 deletions ops/terraform/modules/network/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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]
}
# 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]
# }
3 changes: 1 addition & 2 deletions ops/terraform/modules/network/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ variable "name" {}
variable "location" {}
variable "vnetcidr" {}
variable "websubnetcidr" {}
variable "appsubnetcidr" {}
variable "lbsubnetcidr" {}
variable "dbsubnetcidr" {}
# variable "dbsubnetcidr" {}
variable "env" {}
1 change: 0 additions & 1 deletion ops/terraform/modules/security/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {}

0 comments on commit 6970e7b

Please sign in to comment.