Skip to content

Commit

Permalink
Merge pull request #80 from aws-ia/b-subnet-tags-for-tgw
Browse files Browse the repository at this point in the history
Bug: subnet tags for tgw
  • Loading branch information
drewmullen authored Aug 17, 2022
2 parents ab264f8 + 15729e1 commit e37c01f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/public_private_flow_logs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ No requirements.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_vpc"></a> [vpc](#module\_vpc) | aws-ia/vpc/aws | >= 2.0.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | ../.. | n/a |

## Resources

Expand Down
11 changes: 8 additions & 3 deletions examples/transit_gateway/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
data "aws_availability_zones" "current" {}

module "vpc" {
# source = "aws-ia/vpc/aws"
# version = ">= 2.0.0"
source = "../.."
source = "aws-ia/vpc/aws"
version = ">= 2.0.0"

name = "tgw"
cidr_block = "10.0.0.0/16"
Expand Down Expand Up @@ -32,6 +33,10 @@ module "vpc" {
transit_gateway_default_route_table_propagation = true
transit_gateway_appliance_mode_support = "enable"
transit_gateway_dns_support = "disable"

tags = {
subnet_type = "tgw"
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions examples/transit_gateway/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "tgw_subnets_tags_length" {
description = "Count of tgw subnet tags for a single az."
value = length(module.vpc.tgw_subnet_attributes_by_az[data.aws_availability_zones.current.names[0]].tags)
}

output "private_subnets_tags_length" {
description = "Count of private subnet tags for a single az."
value = length(module.vpc.private_subnet_attributes_by_az["truly_private/${data.aws_availability_zones.current.names[0]}"].tags)
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ resource "awscc_ec2_route_table" "tgw" {
tags = concat(
[{ "key" = "Name", "value" = "${local.subnet_names["transit_gateway"]}-${each.key}" }],
module.tags.tags,
try(module.subnet_tags[split("/", each.key)[0]].tags, {})
try(module.subnet_tags["transit_gateway"].tags, [])
)
}

Expand Down
7 changes: 7 additions & 0 deletions test/examples_transit_gatway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/likexian/gokit/assert"
)

func TestExamplesTransitGateway(t *testing.T) {
Expand All @@ -29,4 +30,10 @@ func TestExamplesTransitGateway(t *testing.T) {
defer terraform.Destroy(t, terraformOptions)
terraform.InitAndApply(t, terraformOptions)
terraform.ApplyAndIdempotent(t, terraformOptions)

tgwTagsLength := terraform.Output(t, terraformOptions, "tgw_subnets_tags_length")
assert.Equal(t, "2", tgwTagsLength)

privateTagsLength := terraform.Output(t, terraformOptions, "private_subnets_tags_length")
assert.Equal(t, "1", privateTagsLength)
}

0 comments on commit e37c01f

Please sign in to comment.