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

use the submodule as per changes in AVM upstream #4

Merged
merged 2 commits into from
May 25, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ avm.tflint_example.merged.hcl
*.md.tmp
# MacOS
.DS_Store
avm.tflint_module.hcl
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ Version: 0.2.0

### <a name="module_subnets"></a> [subnets](#module\_subnets)

Source: git::https://github.com/kewalaka/terraform-azurerm-avm-res-network-virtualnetwork
Source: git::https://github.com/kewalaka/terraform-azurerm-avm-res-network-virtualnetwork//modules/subnet

Version: dev
Version: feat/use-azapi-for-subnets

<!-- markdownlint-disable-next-line MD041 -->
## Data Collection
Expand Down
69 changes: 27 additions & 42 deletions examples/default/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,6 @@ resource "azurerm_route" "this" {
}

locals {
subnets = {
snet0 = {
name = "${module.naming.subnet.name_unique}0"
address_prefixes = ["10.0.0.0/24"]
network_security_group_key = "nsg0"
route_table = {
id = azurerm_route_table.this.id
}
},
snet1 = {
name = "${module.naming.subnet.name_unique}1"
address_prefixes = ["10.0.1.0/24"]
network_security_group_key = "nsg0"
route_table_key = "rt0"
},
snet2 = {
name = "${module.naming.subnet.name_unique}2"
address_prefixes = ["10.0.2.0/24"]
delegation = [{
name = "Microsoft.Web.serverFarms"
service_delegation = {
name = "Microsoft.Web/serverFarms"
}
}]
}
}

network_security_groups = {
nsg0 = {
name = module.naming.network_security_group.name_unique
Expand All @@ -116,7 +89,6 @@ locals {
}
}
}

route_tables = {
rt0 = {
name = "${module.naming.route_table.name_unique}-created"
Expand All @@ -127,12 +99,35 @@ locals {
}
}
}
subnets = {
snet0 = {
name = "${module.naming.subnet.name_unique}0"
address_prefixes = ["10.0.0.0/24"]
network_security_group_key = "nsg0"
route_table = {
id = azurerm_route_table.this.id
}
},
snet1 = {
name = "${module.naming.subnet.name_unique}1"
address_prefixes = ["10.0.1.0/24"]
network_security_group_key = "nsg0"
route_table_key = "rt0"
},
snet2 = {
name = "${module.naming.subnet.name_unique}2"
address_prefixes = ["10.0.2.0/24"]
delegation = [{
name = "Microsoft.Web.serverFarms"
service_delegation = {
name = "Microsoft.Web/serverFarms"
}
}]
}
}
}

# This is the module call
# Do not specify location here due to the randomization above.
# Leaving location as `null` will cause the module to use the resource group location
# with a data source.
module "test" {
source = "../../"
# source = "Azure/avm-ptn-subnets/azurerm"
Expand Down Expand Up @@ -184,17 +179,7 @@ No required inputs.

## Optional Inputs

The following input variables are optional (have default values):

### <a name="input_enable_telemetry"></a> [enable\_telemetry](#input\_enable\_telemetry)

Description: This variable controls whether or not telemetry is enabled for the module.
For more information see <https://aka.ms/avm/telemetryinfo>.
If it is set to false, then no telemetry will be collected.

Type: `bool`

Default: `true`
No optional inputs.

## Outputs

Expand Down
54 changes: 26 additions & 28 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,6 @@ resource "azurerm_route" "this" {
}

locals {
subnets = {
snet0 = {
name = "${module.naming.subnet.name_unique}0"
address_prefixes = ["10.0.0.0/24"]
network_security_group_key = "nsg0"
route_table = {
id = azurerm_route_table.this.id
}
},
snet1 = {
name = "${module.naming.subnet.name_unique}1"
address_prefixes = ["10.0.1.0/24"]
network_security_group_key = "nsg0"
route_table_key = "rt0"
},
snet2 = {
name = "${module.naming.subnet.name_unique}2"
address_prefixes = ["10.0.2.0/24"]
delegation = [{
name = "Microsoft.Web.serverFarms"
service_delegation = {
name = "Microsoft.Web/serverFarms"
}
}]
}
}

network_security_groups = {
nsg0 = {
name = module.naming.network_security_group.name_unique
Expand All @@ -110,7 +83,6 @@ locals {
}
}
}

route_tables = {
rt0 = {
name = "${module.naming.route_table.name_unique}-created"
Expand All @@ -121,6 +93,32 @@ locals {
}
}
}
subnets = {
snet0 = {
name = "${module.naming.subnet.name_unique}0"
address_prefixes = ["10.0.0.0/24"]
network_security_group_key = "nsg0"
route_table = {
id = azurerm_route_table.this.id
}
},
snet1 = {
name = "${module.naming.subnet.name_unique}1"
address_prefixes = ["10.0.1.0/24"]
network_security_group_key = "nsg0"
route_table_key = "rt0"
},
snet2 = {
name = "${module.naming.subnet.name_unique}2"
address_prefixes = ["10.0.2.0/24"]
delegation = [{
name = "Microsoft.Web.serverFarms"
service_delegation = {
name = "Microsoft.Web/serverFarms"
}
}]
}
}
}

# This is the module call
Expand Down
9 changes: 0 additions & 9 deletions examples/default/variables.tf

This file was deleted.

1 change: 0 additions & 1 deletion locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ locals {
}, sv.route_table, {})
}
)
if !(sv == "network_security_group_key" || sv == "route_table_key")
}
}
30 changes: 20 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
module "subnets" {
for_each = var.subnets
for_each = local.subnets

# TODO revert to Azure org pending fix: https://github.com/Azure/terraform-azurerm-avm-res-network-virtualnetwork/pull/74
source = "git::https://github.com/kewalaka/terraform-azurerm-avm-res-network-virtualnetwork?ref=dev"
# source = "Azure/avm-res-network-virtualnetwork/azurerm"
source = "git::https://github.com/kewalaka/terraform-azurerm-avm-res-network-virtualnetwork//modules/subnet?ref=feat/use-azapi-for-subnets"
# source = "Azure/avm-res-network-virtualnetwork/modules/subnet/azurerm"
# version = "0.2.0"

existing_vnet = {
virtual_network = {
resource_id = var.virtual_network_resource_id
}
location = var.location
resource_group_name = var.resource_group_name
subnets = local.subnets
name = each.value.name
address_prefixes = each.value.address_prefixes

default_outbound_access_enabled = try(each.value.default_outbound_access_enabled, false)
delegation = try(each.value.delegation, null)
nat_gateway = try(each.value.nat_gateway, null)
network_security_group = each.value.network_security_group
private_endpoint_network_policies = coalesce(each.value.private_endpoint_network_policies, "Enabled")
private_link_service_network_policies_enabled = coalesce(each.value.private_link_service_network_policies_enabled, true)
role_assignments = try(each.value.role_assignments, {})
route_table = each.value.route_table
service_endpoint_policies = try(each.value.service_endpoint_policies, null)
service_endpoints = try(each.value.service_endpoints, null)

depends_on = [module.network_security_groups]
}
Expand All @@ -32,18 +42,18 @@ module "network_security_groups" {
resource "azurerm_route_table" "this" {
for_each = var.route_tables

name = each.value.name
location = var.location
name = each.value.name
resource_group_name = var.resource_group_name
tags = each.value.tags

dynamic "route" {
for_each = try(each.value.routes, {})
content {
name = route.value.name
address_prefix = route.value.address_prefix
next_hop_type = route.value.next_hop_type
name = route.value.name
next_hop_in_ip_address = route.value.next_hop_in_ip_address
next_hop_type = route.value.next_hop_type
}
}
}
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
output "subnets" {
output "network_security_groups" {
description = "This is the full output for the resource."
value = module.subnets
value = module.network_security_groups
}

output "network_security_groups" {
output "subnets" {
description = "This is the full output for the resource."
value = module.network_security_groups
value = module.subnets
}
10 changes: 5 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ variable "resource_group_name" {
description = "The resource group where the resources will be deployed."
}

variable "virtual_network_resource_id" {
type = string
description = "The virtual network resource ID where the subnets, and optional NSGs and route tables, will be created."
}

# required AVM interfaces
# remove only if not supported by the resource
# tflint-ignore: terraform_unused_declarations
Expand Down Expand Up @@ -74,8 +79,3 @@ variable "tags" {
default = null
description = "(Optional) Tags of the resource."
}

variable "virtual_network_resource_id" {
description = "The virtual network resource ID where the subnets, and optional NSGs and route tables, will be created."
type = string
}
Loading