Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default variable removed & tag updated #7

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ usage: |-
virtual_network_name = join("", module.vnet.vnet_name)

#subnet
default_name_subnet = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
Expand All @@ -81,7 +79,6 @@ usage: |-
subnet_prefixes = ["10.0.1.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
Expand All @@ -103,13 +100,11 @@ usage: |-
virtual_network_name = join("", module.vnet.vnet_name)

#subnet
default_name_subnet = true
create_nat_gateway = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
Expand Down
13 changes: 5 additions & 8 deletions _example/default_subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provider "azurerm" {

module "resource_group" {
source = "clouddrove/resource-group/azure"
version = "1.0.0"
version = "1.0.1"

name = "app"
environment = "test"
Expand All @@ -14,34 +14,31 @@ module "resource_group" {

module "vnet" {
source = "clouddrove/vnet/azure"
version = "1.0.0"
version = "1.0.1"

name = "app"
environment = "test"
label_order = ["name", "environment"]
resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
address_space = "10.0.0.0/16"
enable_ddos_pp = false
}

module "subnet" {
source = "../.."

name = "app"
environment = "test"
label_order = ["name", "environment"]

resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
virtual_network_name = join("", module.vnet.vnet_name)

#subnet
default_name_subnet = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
Expand Down
6 changes: 2 additions & 4 deletions _example/name-specific_subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provider "azurerm" {

module "resource_group" {
source = "clouddrove/resource-group/azure"
version = "1.0.0"
version = "1.0.1"

name = "app"
environment = "test"
Expand All @@ -22,15 +22,14 @@ module "vnet" {
resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
address_space = "10.0.0.0/16"
enable_ddos_pp = false
}

module "name_specific_subnet" {
source = "../.."

name = "app"
environment = "test"
label_order = ["name", "environment"]

resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
virtual_network_name = join("", module.vnet.vnet_name)
Expand All @@ -41,7 +40,6 @@ module "name_specific_subnet" {
subnet_prefixes = ["10.0.1.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
Expand Down
13 changes: 5 additions & 8 deletions _example/nat-gateway_subnet/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ provider "azurerm" {

module "resource_group" {
source = "clouddrove/resource-group/azure"
version = "1.0.0"
version = "1.0.1"

name = "app"
environment = "test"
Expand All @@ -22,27 +22,24 @@ module "vnet" {
resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
address_space = "10.0.0.0/16"
enable_ddos_pp = false
}

module "subnet" {
source = "../.."

name = "app"
environment = "test"
label_order = ["name", "environment"]

resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
virtual_network_name = join("", module.vnet.vnet_name)

#subnet
default_name_subnet = true
create_nat_gateway = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]
create_nat_gateway = true
subnet_names = ["subnet1", "subnet2"]
subnet_prefixes = ["10.0.1.0/24", "10.0.2.0/24"]

# route_table
enable_route_table = false
routes = [
{
name = "rt-test"
Expand Down
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module "labels" {

#Subnet
resource "azurerm_subnet" "subnet" {
count = var.enable && var.default_name_subnet == true ? length(var.subnet_names) : 0
count = var.enable && var.specific_name_subnet == false ? length(var.subnet_names) : 0
name = "${var.name}-${var.subnet_names[count.index]}"
resource_group_name = var.resource_group_name
address_prefixes = [var.subnet_prefixes[count.index]]
Expand Down Expand Up @@ -97,9 +97,9 @@ resource "azurerm_nat_gateway_public_ip_association" "pip_assoc" {
}

resource "azurerm_subnet_nat_gateway_association" "subnet_assoc" {
count = var.create_nat_gateway ? (var.default_name_subnet == true ? length(azurerm_subnet.subnet.*.id) : length(azurerm_subnet.subnet2.*.id)) : 0
count = var.create_nat_gateway ? (var.specific_name_subnet == false ? length(azurerm_subnet.subnet.*.id) : length(azurerm_subnet.subnet2.*.id)) : 0
nat_gateway_id = join("", azurerm_nat_gateway.natgw.*.id)
subnet_id = var.default_name_subnet == true ? azurerm_subnet.subnet.*.id[count.index] : azurerm_subnet.subnet2.*.id[count.index]
subnet_id = var.specific_name_subnet == false ? azurerm_subnet.subnet.*.id[count.index] : azurerm_subnet.subnet2.*.id[count.index]
}

#Route Table
Expand All @@ -122,7 +122,7 @@ resource "azurerm_route_table" "rt" {
}

resource "azurerm_subnet_route_table_association" "main" {
count = var.enable && var.enable_route_table && var.default_name_subnet ? length(var.subnet_prefixes) : 0
count = var.enable && var.enable_route_table && var.specific_name_subnet == false ? length(var.subnet_prefixes) : 0
subnet_id = element(azurerm_subnet.subnet.*.id, count.index)
route_table_id = join("", azurerm_route_table.rt.*.id)
}
Expand Down
9 changes: 2 additions & 7 deletions variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ variable "environment" {

variable "label_order" {
type = list(any)
default = []
default = ["name", "environment"]
description = "Label order, e.g. `name`,`application`."
}

Expand Down Expand Up @@ -117,11 +117,6 @@ EOD
default = {}
}

variable "default_name_subnet" {
type = bool
default = false
}

variable "specific_name_subnet" {
type = bool
default = false
Expand Down Expand Up @@ -159,7 +154,7 @@ variable "create_nat_gateway" {

variable "enable_route_table" {
type = bool
default = false
default = true
description = "Flag to control route table creation."
}

Expand Down