Skip to content

Commit 71b422f

Browse files
oycycgberenice
andauthored
feat(internet-gateways): add better tagging for naming visibility (#157)
* feat(internet-gateways): add better tagging for naming visibility * fix tests * fix tests and tofu fmt * fix tests and tofu fmt * goddamn why is there multiple things not maintained in test * goddamn why is there multiple things not maintained in test * goddamn why is there multiple things not maintained in test * these tests are sooooo PITA * fix: add a dependency chain for security group associations * fix: use native provider retry logic * feat: add time_sleep to resolve race condition * fix: serialize all operations * feat: replace with aws_vpc_endpoint_security_group_association security_group_ids * chore: try out default provider configuragion * fix: support previously implemented logic with the default SG --------- Co-authored-by: Veronika Gnilitska <veronika.gnilitska@gmail.com>
1 parent 5f5f71b commit 71b422f

File tree

13 files changed

+58
-68
lines changed

13 files changed

+58
-68
lines changed

examples/complete/outputs.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
output "public_subnet_cidrs" {
2-
value = module.subnets.public_subnet_cidrs
2+
value = module.subnets.public_subnet_cidrs
3+
description = "The CIDR blocks for the public subnets"
34
}
45

56
output "private_subnet_cidrs" {
6-
value = module.subnets.private_subnet_cidrs
7+
value = module.subnets.private_subnet_cidrs
8+
description = "The CIDR blocks for the private subnets"
79
}
810

911
output "vpc_cidr" {
10-
value = module.vpc.vpc_cidr_block
12+
value = module.vpc.vpc_cidr_block
13+
description = "The CIDR block for the VPC"
1114
}
1215

1316
output "additional_cidr_blocks" {

examples/complete/variables.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
variable "region" {
2-
type = string
2+
type = string
3+
description = "The region to use for the VPC"
34
}
45

56
variable "availability_zones" {
6-
type = list(string)
7+
type = list(string)
8+
description = "The availability zones to use for the VPC"
79
}
810

911
variable "default_security_group_deny_all" {
10-
type = bool
12+
type = bool
13+
description = "Whether to deny all ingress and egress traffic on the default security group"
1114
}
1215

1316
variable "default_route_table_no_routes" {
14-
type = bool
17+
type = bool
18+
description = "Whether to remove all routes from the default route table"
1519
}
1620

1721
variable "default_network_acl_deny_all" {
18-
type = bool
22+
type = bool
23+
description = "Whether to deny all ingress and egress traffic on the default network ACL"
1924
}
2025

2126
variable "network_address_usage_metrics_enabled" {
22-
type = bool
27+
type = bool
28+
description = "Whether to enable network address usage metrics"
2329
}

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.9.0"
7+
version = ">= 4.9.0, < 6.0"
88
}
99
}
1010
}

examples/deprecated/outputs.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
output "public_subnet_cidrs" {
2-
value = module.subnets.public_subnet_cidrs
2+
description = "The CIDR blocks for the public subnets"
3+
value = module.subnets.public_subnet_cidrs
34
}
45

56
output "private_subnet_cidrs" {
6-
value = module.subnets.private_subnet_cidrs
7+
description = "The CIDR blocks for the private subnets"
8+
value = module.subnets.private_subnet_cidrs
79
}
810

911
output "vpc_cidr" {
10-
value = module.vpc.vpc_cidr_block
12+
description = "The CIDR block for the VPC"
13+
value = module.vpc.vpc_cidr_block
1114
}

examples/deprecated/variables.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
variable "region" {
2-
type = string
2+
type = string
3+
description = "The region to use for the VPC"
34
}
45

56
variable "availability_zones" {
6-
type = list(string)
7+
type = list(string)
8+
description = "The availability zones to use for the VPC"
79
}

examples/deprecated/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.0"
7+
version = ">= 3.0, < 6.0"
88
}
99
}
1010
}

examples/vpc-endpoints/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.9.0"
7+
version = ">= 4.9.0, < 6.0"
88
}
99
null = {
1010
source = "hashicorp/null"

main.tf

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ module "label" {
2727
context = module.this.context
2828
}
2929

30+
module "igw_label" {
31+
source = "cloudposse/label/null"
32+
version = "0.25.0"
33+
34+
enabled = local.internet_gateway_enabled
35+
attributes = ["igw"]
36+
context = module.this.context
37+
}
38+
39+
module "eigw_label" {
40+
source = "cloudposse/label/null"
41+
version = "0.25.0"
42+
43+
enabled = local.ipv6_egress_only_internet_gateway_enabled
44+
attributes = ["eigw"]
45+
context = module.this.context
46+
}
47+
3048
resource "aws_vpc" "default" {
3149
count = local.enabled ? 1 : 0
3250

@@ -77,14 +95,14 @@ resource "aws_internet_gateway" "default" {
7795
count = local.internet_gateway_enabled ? 1 : 0
7896

7997
vpc_id = aws_vpc.default[0].id
80-
tags = module.label.tags
98+
tags = module.igw_label.tags
8199
}
82100

83101
resource "aws_egress_only_internet_gateway" "default" {
84102
count = local.ipv6_egress_only_internet_gateway_enabled ? 1 : 0
85103

86104
vpc_id = aws_vpc.default[0].id
87-
tags = module.label.tags
105+
tags = module.eigw_label.tags
88106
}
89107

90108
resource "aws_vpc_ipv4_cidr_block_association" "default" {

modules/vpc-endpoints/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ Submodule for provisioning Gateway and/or Interface VPC Endpoints to the VPC cre
3232
| [aws_vpc_endpoint.gateway_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |
3333
| [aws_vpc_endpoint.interface_endpoint](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |
3434
| [aws_vpc_endpoint_route_table_association.gateway](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint_route_table_association) | resource |
35-
| [aws_vpc_endpoint_security_group_association.interface](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint_security_group_association) | resource |
3635
| [aws_vpc_endpoint_subnet_association.interface](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint_subnet_association) | resource |
3736
| [time_sleep.creation](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
38-
| [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/security_group) | data source |
3937
| [aws_vpc_endpoint.gateway](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_endpoint) | data source |
4038
| [aws_vpc_endpoint.interface](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_endpoint) | data source |
4139
| [aws_vpc_endpoint_service.gateway_endpoint_service](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc_endpoint_service) | data source |

modules/vpc-endpoints/main.tf

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,6 @@ locals {
2323

2424
subnet_associations_map = { for v in local.subnet_associations_list : v.key => v }
2525

26-
# Because security group ID may not be known at plan time, we cannot use it as a key
27-
security_group_associations_list = flatten([for k, v in var.interface_vpc_endpoints : [
28-
for i, s in v.security_group_ids : {
29-
key = "${k}[${i}]"
30-
index = i
31-
interface = k
32-
security_group_id = s
33-
}
34-
]])
35-
36-
security_group_associations_map = { for v in local.security_group_associations_list : v.key => v }
37-
}
38-
39-
# Unfortunately, the AWS provider makes us jump through hoops to deal with the
40-
# association of an endpoint interface with the default VPC security group.
41-
# See https://github.com/hashicorp/terraform-provider-aws/issues/27100
42-
data "aws_security_group" "default" {
43-
count = local.enabled ? 1 : 0
44-
45-
filter {
46-
name = "group-name"
47-
values = ["default"]
48-
}
49-
50-
filter {
51-
name = "vpc-id"
52-
values = [var.vpc_id]
53-
}
5426
}
5527

5628
data "aws_vpc_endpoint_service" "gateway_endpoint_service" {
@@ -110,6 +82,8 @@ resource "aws_vpc_endpoint" "interface_endpoint" {
11082
vpc_id = var.vpc_id
11183
private_dns_enabled = var.interface_vpc_endpoints[each.key].private_dns_enabled
11284

85+
security_group_ids = length(var.interface_vpc_endpoints[each.key].security_group_ids) > 0 ? var.interface_vpc_endpoints[each.key].security_group_ids : null
86+
11387
tags = module.interface_endpoint_label[each.key].tags
11488
}
11589

@@ -119,16 +93,3 @@ resource "aws_vpc_endpoint_subnet_association" "interface" {
11993
subnet_id = each.value.subnet_id
12094
vpc_endpoint_id = aws_vpc_endpoint.interface_endpoint[each.value.interface].id
12195
}
122-
123-
resource "aws_vpc_endpoint_security_group_association" "interface" {
124-
for_each = local.enabled ? local.security_group_associations_map : {}
125-
126-
# It is an error to replace the default association with the default security group
127-
# See https://github.com/hashicorp/terraform-provider-aws/issues/27100
128-
replace_default_association = each.value.index == 0 && each.value.security_group_id != data.aws_security_group.default[0].id
129-
130-
security_group_id = each.value.security_group_id
131-
vpc_endpoint_id = aws_vpc_endpoint.interface_endpoint[each.value.interface].id
132-
133-
depends_on = [aws_vpc_endpoint_subnet_association.interface]
134-
}

0 commit comments

Comments
 (0)