Skip to content

Commit 08771ea

Browse files
Radon Rosboroughjandersen-plaid
authored andcommitted
add eip and ngw tags
1 parent 494f2fc commit 08771ea

File tree

3 files changed

+63
-31
lines changed

3 files changed

+63
-31
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,12 @@ No modules.
497497
| <a name="input_map_public_ip_on_launch"></a> [map\_public\_ip\_on\_launch](#input\_map\_public\_ip\_on\_launch) | Specify true to indicate that instances launched into the subnet should be assigned a public IP address. Default is `false` | `bool` | `false` | no |
498498
| <a name="input_name"></a> [name](#input\_name) | Name to be used on all the resources as identifier | `string` | `""` | no |
499499
| <a name="input_nat_eip_tags"></a> [nat\_eip\_tags](#input\_nat\_eip\_tags) | Additional tags for the NAT EIP | `map(string)` | `{}` | no |
500+
| <a name="input_nat_eip_tags_per_az"></a> [nat\_eip\_tags\_per\_az](#input\_nat\_eip\_tags\_per\_az) | Additional tags for the NAT EIPs where the primary key is the AZ | `map(map(string))` | `{}` | no |
501+
| <a name="input_nat_eip_tags_per_subnet"></a> [nat\_eip\_tags\_per\_subnet](#input\_nat\_eip\_tags\_per\_subnet) | Additional tags for the NAT EIPs, if specified then must have a length equal to the number of private subnets | `list(map(string))` | `[]` | no |
500502
| <a name="input_nat_gateway_destination_cidr_block"></a> [nat\_gateway\_destination\_cidr\_block](#input\_nat\_gateway\_destination\_cidr\_block) | Used to pass a custom destination route for private NAT Gateway. If not specified, the default 0.0.0.0/0 is used as a destination route | `string` | `"0.0.0.0/0"` | no |
501503
| <a name="input_nat_gateway_tags"></a> [nat\_gateway\_tags](#input\_nat\_gateway\_tags) | Additional tags for the NAT gateways | `map(string)` | `{}` | no |
504+
| <a name="input_nat_gateway_tags_per_az"></a> [nat\_gateway\_tags\_per\_az](#input\_nat\_gateway\_tags\_per\_az) | Additional tags for the NAT gateways where the primary key is the AZ | `map(map(string))` | `{}` | no |
505+
| <a name="input_nat_gateway_tags_per_subnet"></a> [nat\_gateway\_tags\_per\_subnet](#input\_nat\_gateway\_tags\_per\_subnet) | Additional tags for the NAT gateways, if specified then must have a length equal to the number of private subnets | `list(map(string))` | `[]` | no |
502506
| <a name="input_one_nat_gateway_per_az"></a> [one\_nat\_gateway\_per\_az](#input\_one\_nat\_gateway\_per\_az) | Should be true if you want only one NAT Gateway per availability zone. Requires `var.azs` to be set, and the number of `public_subnets` created to be greater than or equal to the number of availability zones specified in `var.azs` | `bool` | `false` | no |
503507
| <a name="input_outpost_acl_tags"></a> [outpost\_acl\_tags](#input\_outpost\_acl\_tags) | Additional tags for the outpost subnets network ACL | `map(string)` | `{}` | no |
504508
| <a name="input_outpost_arn"></a> [outpost\_arn](#input\_outpost\_arn) | ARN of Outpost you want to create a subnet in | `string` | `null` | no |

main.tf

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ resource "aws_subnet" "public" {
119119
},
120120
var.tags,
121121
var.public_subnet_tags,
122-
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {})
122+
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {}),
123+
length(var.public_subnet_tags_per_subnet) > 0 ? element(var.public_subnet_tags_per_subnet, count.index) : {},
123124
)
124125
}
125126

@@ -238,17 +239,15 @@ resource "aws_subnet" "private" {
238239

239240
tags = merge(
240241
{
241-
"Name" = try(
242-
var.private_route_table_names[count.index],
243-
var.single_nat_gateway ? "${var.name}-${var.private_subnet_suffix}" : format(
244-
"${var.name}-${var.private_subnet_suffix}-%s",
245-
element(var.azs, count.index),
246-
)
242+
Name = try(
243+
var.private_subnet_names[count.index],
244+
format("${var.name}-${var.private_subnet_suffix}-%s", element(var.azs, count.index))
247245
)
248246
},
249247
var.tags,
250-
var.private_route_table_tags,
251-
length(var.private_route_table_tags_per_subnet) > 0 ? element(var.private_route_table_tags_per_subnet, count.index) : {},
248+
var.private_subnet_tags,
249+
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {}),
250+
length(var.private_subnet_tags_per_subnet) > 0 ? element(var.private_subnet_tags_per_subnet, count.index) : {},
252251
)
253252
}
254253

@@ -261,16 +260,16 @@ resource "aws_route_table" "private" {
261260
tags = merge(
262261
{
263262
"Name" = try(
264-
var.database_route_table_names[count.index],
265-
var.single_nat_gateway || var.create_database_internet_gateway_route ? "${var.name}-${var.database_subnet_suffix}" : format(
266-
"${var.name}-${var.database_subnet_suffix}-%s",
263+
var.private_route_table_names[count.index],
264+
var.single_nat_gateway ? "${var.name}-${var.private_subnet_suffix}" : format(
265+
"${var.name}-${var.private_subnet_suffix}-%s",
267266
element(var.azs, count.index),
268267
)
269268
)
270269
},
271270
var.tags,
272-
var.database_route_table_tags,
273-
length(var.database_route_table_tags_per_subnet) > 0 ? element(var.database_route_table_tags_per_subnet, count.index) : {},
271+
var.private_route_table_tags,
272+
length(var.private_route_table_tags_per_subnet) > 0 ? element(var.private_route_table_tags_per_subnet, count.index) : {},
274273
)
275274
}
276275

@@ -371,9 +370,8 @@ resource "aws_subnet" "database" {
371370
)
372371
},
373372
var.tags,
374-
var.public_subnet_tags,
375-
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {}),
376-
length(var.public_subnet_tags_per_subnet) > 0 ? element(var.public_subnet_tags_per_subnet, count.index) : {},
373+
var.database_subnet_tags,
374+
length(var.database_subnet_tags_per_subnet) > 0 ? element(var.database_subnet_tags_per_subnet, count.index) : {},
377375
)
378376
}
379377

@@ -389,9 +387,7 @@ resource "aws_db_subnet_group" "database" {
389387
"Name" = lower(coalesce(var.database_subnet_group_name, var.name))
390388
},
391389
var.tags,
392-
var.private_subnet_tags,
393-
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {}),
394-
length(var.private_subnet_tags_per_subnet) > 0 ? element(var.private_subnet_tags_per_subnet, count.index) : {},
390+
var.database_subnet_group_tags,
395391
)
396392
}
397393

@@ -402,14 +398,17 @@ resource "aws_route_table" "database" {
402398

403399
tags = merge(
404400
{
405-
"Name" = var.single_nat_gateway || var.create_database_internet_gateway_route ? "${var.name}-${var.database_subnet_suffix}" : format(
406-
"${var.name}-${var.database_subnet_suffix}-%s",
407-
element(var.azs, count.index),
401+
"Name" = try(
402+
var.database_route_table_names[count.index],
403+
var.single_nat_gateway || var.create_database_internet_gateway_route ? "${var.name}-${var.database_subnet_suffix}" : format(
404+
"${var.name}-${var.database_subnet_suffix}-%s",
405+
element(var.azs, count.index),
406+
)
408407
)
409408
},
410409
var.tags,
411-
var.outpost_subnet_tags,
412-
length(var.outpost_subnet_tags_per_subnet) > 0 ? element(var.outpost_subnet_tags_per_subnet, count.index) : {},
410+
var.database_route_table_tags,
411+
length(var.database_route_table_tags_per_subnet) > 0 ? element(var.database_route_table_tags_per_subnet, count.index) : {},
413412
)
414413
}
415414

@@ -488,8 +487,7 @@ resource "aws_network_acl" "database" {
488487
tags = merge(
489488
{ "Name" = "${var.name}-${var.database_subnet_suffix}" },
490489
var.tags,
491-
var.database_subnet_tags,
492-
length(var.database_subnet_tags_per_subnet) > 0 ? element(var.database_subnet_tags_per_subnet, count.index) : {},
490+
var.database_acl_tags,
493491
)
494492
}
495493

@@ -586,8 +584,7 @@ resource "aws_route_table" "redshift" {
586584
tags = merge(
587585
{ "Name" = "${var.name}-${var.redshift_subnet_suffix}" },
588586
var.tags,
589-
var.elasticache_subnet_tags,
590-
length(var.elasticache_subnet_tags_per_subnet) > 0 ? element(var.elasticache_subnet_tags_per_subnet, count.index) : {},
587+
var.redshift_route_table_tags,
591588
)
592589
}
593590

@@ -628,8 +625,7 @@ resource "aws_network_acl" "redshift" {
628625
tags = merge(
629626
{ "Name" = "${var.name}-${var.redshift_subnet_suffix}" },
630627
var.tags,
631-
var.intra_subnet_tags,
632-
length(var.intra_subnet_tags_per_subnet) > 0 ? element(var.intra_subnet_tags_per_subnet, count.index) : {},
628+
var.redshift_acl_tags,
633629
)
634630
}
635631

@@ -700,6 +696,7 @@ resource "aws_subnet" "elasticache" {
700696
},
701697
var.tags,
702698
var.elasticache_subnet_tags,
699+
length(var.elasticache_subnet_tags_per_subnet) > 0 ? element(var.elasticache_subnet_tags_per_subnet, count.index) : {},
703700
)
704701
}
705702

@@ -829,6 +826,7 @@ resource "aws_subnet" "intra" {
829826
},
830827
var.tags,
831828
var.intra_subnet_tags,
829+
length(var.intra_subnet_tags_per_subnet) > 0 ? element(var.intra_subnet_tags_per_subnet, count.index) : {},
832830
)
833831
}
834832

@@ -940,6 +938,7 @@ resource "aws_subnet" "outpost" {
940938
},
941939
var.tags,
942940
var.outpost_subnet_tags,
941+
length(var.outpost_subnet_tags_per_subnet) > 0 ? element(var.outpost_subnet_tags_per_subnet, count.index) : {},
943942
)
944943
}
945944

@@ -1067,6 +1066,8 @@ resource "aws_eip" "nat" {
10671066
},
10681067
var.tags,
10691068
var.nat_eip_tags,
1069+
lookup(var.nat_eip_tags_per_az, element(var.azs, count.index), {}),
1070+
length(var.nat_eip_tags_per_subnet) > 0 ? element(var.nat_eip_tags_per_subnet, count.index) : {},
10701071
)
10711072

10721073
depends_on = [aws_internet_gateway.this]
@@ -1093,6 +1094,8 @@ resource "aws_nat_gateway" "this" {
10931094
},
10941095
var.tags,
10951096
var.nat_gateway_tags,
1097+
lookup(var.nat_gateway_tags_per_az, element(var.azs, count.index), {}),
1098+
length(var.nat_gateway_tags_per_subnet) > 0 ? element(var.nat_gateway_tags_per_subnet, count.index) : {},
10961099
)
10971100

10981101
depends_on = [aws_internet_gateway.this]

variables.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ variable "private_subnet_ipv6_native" {
348348
default = false
349349
}
350350

351+
351352
variable "private_subnet_private_dns_hostname_type_on_launch" {
352353
description = "The type of hostnames to assign to instances in the subnet at launch. For IPv6-only subnets, an instance DNS name must be based on the instance ID. For dual-stack and IPv4-only subnets, you can specify whether DNS names use the instance IPv4 address or the instance ID. Valid values: `ip-name`, `resource-name`"
353354
type = string
@@ -1282,12 +1283,36 @@ variable "nat_gateway_tags" {
12821283
default = {}
12831284
}
12841285

1286+
variable "nat_gateway_tags_per_az" {
1287+
description = "Additional tags for the NAT gateways where the primary key is the AZ"
1288+
type = map(map(string))
1289+
default = {}
1290+
}
1291+
1292+
variable "nat_gateway_tags_per_subnet" {
1293+
description = "Additional tags for the NAT gateways, if specified then must have a length equal to the number of private subnets"
1294+
type = list(map(string))
1295+
default = []
1296+
}
1297+
12851298
variable "nat_eip_tags" {
12861299
description = "Additional tags for the NAT EIP"
12871300
type = map(string)
12881301
default = {}
12891302
}
12901303

1304+
variable "nat_eip_tags_per_az" {
1305+
description = "Additional tags for the NAT EIPs where the primary key is the AZ"
1306+
type = map(map(string))
1307+
default = {}
1308+
}
1309+
1310+
variable "nat_eip_tags_per_subnet" {
1311+
description = "Additional tags for the NAT EIPs, if specified then must have a length equal to the number of private subnets"
1312+
type = list(map(string))
1313+
default = []
1314+
}
1315+
12911316
################################################################################
12921317
# Customer Gateways
12931318
################################################################################

0 commit comments

Comments
 (0)