Skip to content

Commit c5f50fa

Browse files
committed
feat(vpc): support region parameter for aws v6
1 parent 9043536 commit c5f50fa

File tree

10 files changed

+121
-67
lines changed

10 files changed

+121
-67
lines changed

modules/vpc/README.md

Lines changed: 28 additions & 28 deletions
Large diffs are not rendered by default.

modules/vpc/defaults.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# INFO: Not supported attributes
66
# - `subnet_ids`
77
resource "aws_default_network_acl" "this" {
8+
region = var.region
9+
810
default_network_acl_id = aws_vpc.this.default_network_acl_id
911

1012
dynamic "ingress" {
@@ -128,6 +130,8 @@ resource "aws_default_network_acl" "this" {
128130
###################################################
129131

130132
# resource "aws_default_route_table" "this" {
133+
# region = var.region
134+
#
131135
# default_route_table_id = aws_vpc.this.default_route_table_id
132136
#
133137
# tags = merge(
@@ -145,6 +149,8 @@ resource "aws_default_network_acl" "this" {
145149
###################################################
146150

147151
resource "aws_default_security_group" "this" {
152+
region = var.region
153+
148154
vpc_id = aws_vpc.this.id
149155

150156
dynamic "ingress" {

modules/vpc/dhcp-options.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
data "aws_region" "this" {}
1+
data "aws_region" "this" {
2+
region = var.region
3+
}
24

35
locals {
4-
region = data.aws_region.this.name
6+
region = data.aws_region.this.region
57

68
default_dhcp_options_domain_name = (local.region != "us-east-1"
79
? "${local.region}.compute.internal"
@@ -17,6 +19,8 @@ locals {
1719
resource "aws_vpc_dhcp_options" "this" {
1820
count = var.dhcp_options.enabled ? 1 : 0
1921

22+
region = var.region
23+
2024
domain_name = (length(compact([var.dhcp_options.domain_name])) > 0
2125
? var.dhcp_options.domain_name
2226
: local.default_dhcp_options_domain_name
@@ -43,6 +47,8 @@ resource "aws_vpc_dhcp_options" "this" {
4347
resource "aws_vpc_dhcp_options_association" "this" {
4448
count = var.dhcp_options.enabled ? 1 : 0
4549

50+
region = aws_vpc.this.region
51+
4652
vpc_id = aws_vpc.this.id
4753
dhcp_options_id = aws_vpc_dhcp_options.this[0].id
4854
}

modules/vpc/gateways.tf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
# Internet Gateway
33
###################################################
44

5-
# INFO: Not supported attributes
5+
# INFO: Use a separate resource
66
# - `vpc_id`
77
resource "aws_internet_gateway" "this" {
88
count = var.internet_gateway.enabled ? 1 : 0
99

10+
region = var.region
11+
1012
tags = merge(
1113
{
1214
"Name" = coalesce(var.internet_gateway.name, local.metadata.name)
@@ -19,6 +21,8 @@ resource "aws_internet_gateway" "this" {
1921
resource "aws_internet_gateway_attachment" "this" {
2022
count = var.internet_gateway.enabled ? 1 : 0
2123

24+
region = aws_vpc.this.region
25+
2226
vpc_id = aws_vpc.this.id
2327
internet_gateway_id = aws_internet_gateway.this[0].id
2428
}
@@ -31,6 +35,8 @@ resource "aws_internet_gateway_attachment" "this" {
3135
resource "aws_egress_only_internet_gateway" "this" {
3236
count = var.egress_only_internet_gateway.enabled ? 1 : 0
3337

38+
region = var.region
39+
3440
vpc_id = aws_vpc.this.id
3541

3642
tags = merge(
@@ -54,12 +60,15 @@ resource "aws_egress_only_internet_gateway" "this" {
5460
# Virtual Private Gateway
5561
###################################################
5662

57-
# INFO: Not supported attributes
63+
# INFO: Use a separate resource
5864
# - `vpc_id`
65+
# INFO: Not supported attributes
5966
# - `availability_zone`
6067
resource "aws_vpn_gateway" "this" {
6168
count = var.vpn_gateway.enabled ? 1 : 0
6269

70+
region = var.region
71+
6372
amazon_side_asn = var.vpn_gateway.asn
6473

6574
tags = merge(
@@ -74,6 +83,8 @@ resource "aws_vpn_gateway" "this" {
7483
resource "aws_vpn_gateway_attachment" "this" {
7584
count = var.vpn_gateway.enabled ? 1 : 0
7685

86+
region = aws_vpc.this.region
87+
7788
vpc_id = aws_vpc.this.id
7889
vpn_gateway_id = aws_vpn_gateway.this[0].id
7990
}

modules/vpc/main.tf

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ locals {
2929
###################################################
3030

3131
resource "aws_vpc" "this" {
32+
region = var.region
33+
3234
## IPv4 CIDR Blocks
3335
cidr_block = (var.ipv4_cidrs[0].type == "MANUAL"
3436
? var.ipv4_cidrs[0].cidr
@@ -45,7 +47,6 @@ resource "aws_vpc" "this" {
4547

4648

4749
## IPv6 CIDR Blocks
48-
# TODO: Want to manage IPv6 CIDRs with `aws_vpc_ipv6_cidr_block_association` resource. But, there are unsupported featrues yet.
4950
assign_generated_ipv6_cidr_block = (local.ipv6_enabled
5051
? (var.ipv6_cidrs[0].type == "AMAZON"
5152
? true
@@ -108,6 +109,8 @@ resource "aws_vpc" "this" {
108109
resource "aws_vpc_ipv4_cidr_block_association" "this" {
109110
count = length(var.ipv4_cidrs) > 0 ? length(var.ipv4_cidrs) - 1 : 0
110111

112+
region = aws_vpc.this.region
113+
111114
vpc_id = aws_vpc.this.id
112115
cidr_block = (var.ipv4_cidrs[count.index + 1].type == "MANUAL"
113116
? var.ipv4_cidrs[count.index + 1].cidr
@@ -123,18 +126,26 @@ resource "aws_vpc_ipv4_cidr_block_association" "this" {
123126
)
124127
}
125128

129+
# INFO: Not supported attributes
130+
# - `ipv6_pool`
126131
resource "aws_vpc_ipv6_cidr_block_association" "this" {
127-
count = length(var.ipv6_cidrs) > 0 ? length(var.ipv6_cidrs) - 1 : 0
132+
count = local.ipv6_enabled ? length(var.ipv6_cidrs) - 1 : 0
133+
134+
region = aws_vpc.this.region
128135

129136
vpc_id = aws_vpc.this.id
130-
ipv6_cidr_block = (var.ipv6_cidrs[count.index + 1].type == "IPAM_POOL"
131-
? var.ipv6_cidrs[count.index + 1].ipam_pool.cidr
137+
assign_generated_ipv6_cidr_block = (var.ipv6_cidrs[count.index + 1].type == "AMAZON"
138+
? true
132139
: null
133140
)
134141
ipv6_ipam_pool_id = (var.ipv6_cidrs[count.index + 1].type == "IPAM_POOL"
135142
? var.ipv6_cidrs[count.index + 1].ipam_pool.id
136143
: null
137144
)
145+
ipv6_cidr_block = (var.ipv6_cidrs[count.index + 1].type == "IPAM_POOL"
146+
? var.ipv6_cidrs[count.index + 1].ipam_pool.cidr
147+
: null
148+
)
138149
ipv6_netmask_length = (var.ipv6_cidrs[count.index + 1].type == "IPAM_POOL"
139150
? var.ipv6_cidrs[count.index + 1].ipam_pool.netmask_length
140151
: null

modules/vpc/outputs.tf

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
output "region" {
2+
description = "The AWS region this module resources resides in."
3+
value = aws_vpc.this.region
4+
}
5+
16
output "name" {
27
description = "The name of the VPC."
38
value = var.name
49
}
510

6-
output "owner" {
11+
output "owner_id" {
712
description = "The ID of the AWS account that owns the VPC."
813
value = aws_vpc.this.owner_id
914
}
@@ -139,14 +144,14 @@ output "dns_resolution_enabled" {
139144
value = aws_vpc.this.enable_dns_support
140145
}
141146

142-
output "dns_dnssec_validation_enabled" {
143-
description = "Whether or not the VPC has Route53 DNSSEC validation support."
144-
value = var.dns_dnssec_validation_enabled
145-
}
146-
147-
output "dns_dnssec_validation_id" {
148-
description = "The ID of a configuration for DNSSEC validation."
149-
value = one(aws_route53_resolver_dnssec_config.this[*].id)
147+
output "dnssec_validation" {
148+
description = "The configuration for Route53 DNSSEC validation for the VPC."
149+
value = {
150+
enabled = var.dnssec_validation.enabled
151+
id = one(aws_route53_resolver_dnssec_config.this[*].id)
152+
arn = one(aws_route53_resolver_dnssec_config.this[*].arn)
153+
status = one(aws_route53_resolver_dnssec_config.this[*].status)
154+
}
150155
}
151156

152157
output "private_hosted_zones" {
@@ -162,9 +167,9 @@ output "default_network_acl" {
162167
`owner` - The ID of the AWS account that owns the default Network ACL.
163168
EOF
164169
value = {
165-
id = aws_vpc.this.default_network_acl_id
166-
arn = aws_default_network_acl.this.arn
167-
owner = aws_default_network_acl.this.owner_id
170+
id = aws_vpc.this.default_network_acl_id
171+
arn = aws_default_network_acl.this.arn
172+
owner_id = aws_default_network_acl.this.owner_id
168173
}
169174
}
170175

@@ -190,7 +195,7 @@ output "default_security_group" {
190195
value = {
191196
id = aws_vpc.this.default_security_group_id
192197
arn = aws_default_security_group.this.arn
193-
owner = aws_default_security_group.this.owner_id
198+
owner_id = aws_default_security_group.this.owner_id
194199
name = aws_default_security_group.this.name
195200
description = aws_default_security_group.this.description
196201
}
@@ -222,9 +227,9 @@ output "dhcp_options" {
222227
EOF
223228
value = (var.dhcp_options.enabled
224229
? {
225-
id = one(aws_vpc_dhcp_options.this[*].id)
226-
arn = one(aws_vpc_dhcp_options.this[*].arn)
227-
owner = one(aws_vpc_dhcp_options.this[*].owner_id)
230+
id = one(aws_vpc_dhcp_options.this[*].id)
231+
arn = one(aws_vpc_dhcp_options.this[*].arn)
232+
owner_id = one(aws_vpc_dhcp_options.this[*].owner_id)
228233

229234
domain_name = one(aws_vpc_dhcp_options.this[*].domain_name)
230235
domain_name_servers = one(aws_vpc_dhcp_options.this[*].domain_name_servers)
@@ -246,9 +251,9 @@ output "internet_gateway" {
246251
EOF
247252
value = (var.internet_gateway.enabled
248253
? {
249-
id = one(aws_internet_gateway.this[*].id)
250-
arn = one(aws_internet_gateway.this[*].arn)
251-
owner = one(aws_internet_gateway.this[*].owner_id)
254+
id = one(aws_internet_gateway.this[*].id)
255+
arn = one(aws_internet_gateway.this[*].arn)
256+
owner_id = one(aws_internet_gateway.this[*].owner_id)
252257
}
253258
: null
254259
)

modules/vpc/resource-group.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module "resource_group" {
1616

1717
count = (var.resource_group.enabled && var.module_tags_enabled) ? 1 : 0
1818

19+
region = var.region
20+
1921
name = local.resource_group_name
2022
description = var.resource_group.description
2123

modules/vpc/route53.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
resource "aws_route53_zone_association" "this" {
66
for_each = toset(var.private_hosted_zones)
77

8-
vpc_id = aws_vpc.this.id
8+
vpc_region = aws_vpc.this.region
9+
vpc_id = aws_vpc.this.id
10+
911
zone_id = each.value
1012
}
1113

@@ -15,7 +17,9 @@ resource "aws_route53_zone_association" "this" {
1517
###################################################
1618

1719
resource "aws_route53_resolver_dnssec_config" "this" {
18-
count = var.dns_dnssec_validation_enabled ? 1 : 0
20+
count = var.dnssec_validation.enabled ? 1 : 0
21+
22+
region = var.region
1923

2024
resource_id = aws_vpc.this.id
2125
}

modules/vpc/variables.tf

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
variable "region" {
2+
description = "(Optional) The region in which to create the module resources. If not provided, the module resources will be created in the provider's configured region."
3+
type = string
4+
default = null
5+
nullable = true
6+
}
7+
18
variable "name" {
29
description = "(Required) Desired name for the VPC resources."
310
type = string
@@ -108,11 +115,16 @@ variable "dns_resolution_enabled" {
108115
nullable = false
109116
}
110117

111-
variable "dns_dnssec_validation_enabled" {
112-
description = "(Optional) Should be true to enable Route53 DNSSEC validation in the VPC."
113-
type = bool
114-
default = false
115-
nullable = false
118+
variable "dnssec_validation" {
119+
description = <<EOF
120+
(Optional) A configuration for Route53 DNSSEC validation in the VPC. `dnssec_validation` as defined below.
121+
(Optional) `enabled` - Whether to enable Route53 DNSSEC validation in the VPC. Defaults to `false`.
122+
EOF
123+
type = object({
124+
enabled = optional(bool, false)
125+
})
126+
default = {}
127+
nullable = false
116128
}
117129

118130
variable "private_hosted_zones" {
@@ -348,9 +360,6 @@ variable "module_tags_enabled" {
348360
# Resource Group
349361
###################################################
350362

351-
352-
353-
354363
variable "resource_group" {
355364
description = <<EOF
356365
(Optional) A configurations of Resource Group for this module. `resource_group` as defined below.

modules/vpc/versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 1.6"
2+
required_version = ">= 1.12"
33

44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.46"
7+
version = ">= 6.12"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)