Skip to content

Commit d13247b

Browse files
author
Radon Rosborough
committed
feat: Allow tagging on per-subnet basis
1 parent 33b09ca commit d13247b

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ No modules.
383383
| <a name="input_database_subnet_names"></a> [database\_subnet\_names](#input\_database\_subnet\_names) | Explicit values to use in the Name tag on database subnets. If empty, Name tags are generated. | `list(string)` | `[]` | no |
384384
| <a name="input_database_subnet_suffix"></a> [database\_subnet\_suffix](#input\_database\_subnet\_suffix) | Suffix to append to database subnets name | `string` | `"db"` | no |
385385
| <a name="input_database_subnet_tags"></a> [database\_subnet\_tags](#input\_database\_subnet\_tags) | Additional tags for the database subnets | `map(string)` | `{}` | no |
386+
| <a name="input_database_subnet_tags_per_subnet"></a> [database\_subnet\_tags\_per\_subnet](#input\_database\_subnet\_tags\_per\_subnet) | Additional tags for the database subnets, if specified then must have a length equal to the number of database subnets | `list(map(string))` | `[]` | no |
386387
| <a name="input_database_subnets"></a> [database\_subnets](#input\_database\_subnets) | A list of database subnets | `list(string)` | `[]` | no |
387388
| <a name="input_default_network_acl_egress"></a> [default\_network\_acl\_egress](#input\_default\_network\_acl\_egress) | List of maps of egress rules to set on the Default Network ACL | `list(map(string))` | <pre>[<br> {<br> "action": "allow",<br> "cidr_block": "0.0.0.0/0",<br> "from_port": 0,<br> "protocol": "-1",<br> "rule_no": 100,<br> "to_port": 0<br> },<br> {<br> "action": "allow",<br> "from_port": 0,<br> "ipv6_cidr_block": "::/0",<br> "protocol": "-1",<br> "rule_no": 101,<br> "to_port": 0<br> }<br>]</pre> | no |
388389
| <a name="input_default_network_acl_ingress"></a> [default\_network\_acl\_ingress](#input\_default\_network\_acl\_ingress) | List of maps of ingress rules to set on the Default Network ACL | `list(map(string))` | <pre>[<br> {<br> "action": "allow",<br> "cidr_block": "0.0.0.0/0",<br> "from_port": 0,<br> "protocol": "-1",<br> "rule_no": 100,<br> "to_port": 0<br> },<br> {<br> "action": "allow",<br> "from_port": 0,<br> "ipv6_cidr_block": "::/0",<br> "protocol": "-1",<br> "rule_no": 101,<br> "to_port": 0<br> }<br>]</pre> | no |
@@ -419,6 +420,7 @@ No modules.
419420
| <a name="input_elasticache_subnet_names"></a> [elasticache\_subnet\_names](#input\_elasticache\_subnet\_names) | Explicit values to use in the Name tag on elasticache subnets. If empty, Name tags are generated. | `list(string)` | `[]` | no |
420421
| <a name="input_elasticache_subnet_suffix"></a> [elasticache\_subnet\_suffix](#input\_elasticache\_subnet\_suffix) | Suffix to append to elasticache subnets name | `string` | `"elasticache"` | no |
421422
| <a name="input_elasticache_subnet_tags"></a> [elasticache\_subnet\_tags](#input\_elasticache\_subnet\_tags) | Additional tags for the elasticache subnets | `map(string)` | `{}` | no |
423+
| <a name="input_elasticache_subnet_tags_per_subnet"></a> [elasticache\_subnet\_tags\_per\_subnet](#input\_elasticache\_subnet\_tags\_per\_subnet) | Additional tags for the elasticache subnets, if specified then must have a length equal to the number of elasticache subnets | `list(map(string))` | `[]` | no |
422424
| <a name="input_elasticache_subnets"></a> [elasticache\_subnets](#input\_elasticache\_subnets) | A list of elasticache subnets | `list(string)` | `[]` | no |
423425
| <a name="input_enable_classiclink"></a> [enable\_classiclink](#input\_enable\_classiclink) | [DEPRECATED](https://github.com/hashicorp/terraform/issues/31730) Should be true to enable ClassicLink for the VPC. Only valid in regions and accounts that support EC2 Classic. | `bool` | `null` | no |
424426
| <a name="input_enable_classiclink_dns_support"></a> [enable\_classiclink\_dns\_support](#input\_enable\_classiclink\_dns\_support) | [DEPRECATED](https://github.com/hashicorp/terraform/issues/31730) Should be true to enable ClassicLink DNS Support for the VPC. Only valid in regions and accounts that support EC2 Classic. | `bool` | `null` | no |
@@ -457,6 +459,7 @@ No modules.
457459
| <a name="input_intra_subnet_names"></a> [intra\_subnet\_names](#input\_intra\_subnet\_names) | Explicit values to use in the Name tag on intra subnets. If empty, Name tags are generated. | `list(string)` | `[]` | no |
458460
| <a name="input_intra_subnet_suffix"></a> [intra\_subnet\_suffix](#input\_intra\_subnet\_suffix) | Suffix to append to intra subnets name | `string` | `"intra"` | no |
459461
| <a name="input_intra_subnet_tags"></a> [intra\_subnet\_tags](#input\_intra\_subnet\_tags) | Additional tags for the intra subnets | `map(string)` | `{}` | no |
462+
| <a name="input_intra_subnet_tags_per_subnet"></a> [intra\_subnet\_tags\_per\_subnet](#input\_intra\_subnet\_tags\_per\_subnet) | Additional tags for the intra subnets, if specified then must have a length equal to the number of intra subnets | `list(map(string))` | `[]` | no |
460463
| <a name="input_intra_subnets"></a> [intra\_subnets](#input\_intra\_subnets) | A list of intra subnets | `list(string)` | `[]` | no |
461464
| <a name="input_ipv4_ipam_pool_id"></a> [ipv4\_ipam\_pool\_id](#input\_ipv4\_ipam\_pool\_id) | (Optional) The ID of an IPv4 IPAM pool you want to use for allocating this VPC's CIDR. | `string` | `null` | no |
462465
| <a name="input_ipv4_netmask_length"></a> [ipv4\_netmask\_length](#input\_ipv4\_netmask\_length) | (Optional) The netmask length of the IPv4 CIDR you want to allocate to this VPC. Requires specifying a ipv4\_ipam\_pool\_id. | `number` | `null` | no |
@@ -484,6 +487,7 @@ No modules.
484487
| <a name="input_outpost_subnet_names"></a> [outpost\_subnet\_names](#input\_outpost\_subnet\_names) | Explicit values to use in the Name tag on outpost subnets. If empty, Name tags are generated. | `list(string)` | `[]` | no |
485488
| <a name="input_outpost_subnet_suffix"></a> [outpost\_subnet\_suffix](#input\_outpost\_subnet\_suffix) | Suffix to append to outpost subnets name | `string` | `"outpost"` | no |
486489
| <a name="input_outpost_subnet_tags"></a> [outpost\_subnet\_tags](#input\_outpost\_subnet\_tags) | Additional tags for the outpost subnets | `map(string)` | `{}` | no |
490+
| <a name="input_outpost_subnet_tags_per_subnet"></a> [outpost\_subnet\_tags\_per\_subnet](#input\_outpost\_subnet\_tags\_per\_subnet) | Additional tags for the outpost subnets, if specified then must have a length equal to the number of outpost subnets | `list(map(string))` | `[]` | no |
487491
| <a name="input_outpost_subnets"></a> [outpost\_subnets](#input\_outpost\_subnets) | A list of outpost subnets inside the VPC | `list(string)` | `[]` | no |
488492
| <a name="input_private_acl_tags"></a> [private\_acl\_tags](#input\_private\_acl\_tags) | Additional tags for the private subnets network ACL | `map(string)` | `{}` | no |
489493
| <a name="input_private_dedicated_network_acl"></a> [private\_dedicated\_network\_acl](#input\_private\_dedicated\_network\_acl) | Whether to use dedicated network ACL (not default) and custom rules for private subnets | `bool` | `false` | no |
@@ -496,6 +500,7 @@ No modules.
496500
| <a name="input_private_subnet_suffix"></a> [private\_subnet\_suffix](#input\_private\_subnet\_suffix) | Suffix to append to private subnets name | `string` | `"private"` | no |
497501
| <a name="input_private_subnet_tags"></a> [private\_subnet\_tags](#input\_private\_subnet\_tags) | Additional tags for the private subnets | `map(string)` | `{}` | no |
498502
| <a name="input_private_subnet_tags_per_az"></a> [private\_subnet\_tags\_per\_az](#input\_private\_subnet\_tags\_per\_az) | Additional tags for the private subnets where the primary key is the AZ | `map(map(string))` | `{}` | no |
503+
| <a name="input_private_subnet_tags_per_subnet"></a> [private\_subnet\_tags\_per\_subnet](#input\_private\_subnet\_tags\_per\_subnet) | Additional tags for the private subnets, if specified then must have a length equal to the number of private subnets | `list(map(string))` | `[]` | no |
499504
| <a name="input_private_subnets"></a> [private\_subnets](#input\_private\_subnets) | A list of private subnets inside the VPC | `list(string)` | `[]` | no |
500505
| <a name="input_propagate_intra_route_tables_vgw"></a> [propagate\_intra\_route\_tables\_vgw](#input\_propagate\_intra\_route\_tables\_vgw) | Should be true if you want route table propagation | `bool` | `false` | no |
501506
| <a name="input_propagate_private_route_tables_vgw"></a> [propagate\_private\_route\_tables\_vgw](#input\_propagate\_private\_route\_tables\_vgw) | Should be true if you want route table propagation | `bool` | `false` | no |
@@ -511,6 +516,7 @@ No modules.
511516
| <a name="input_public_subnet_suffix"></a> [public\_subnet\_suffix](#input\_public\_subnet\_suffix) | Suffix to append to public subnets name | `string` | `"public"` | no |
512517
| <a name="input_public_subnet_tags"></a> [public\_subnet\_tags](#input\_public\_subnet\_tags) | Additional tags for the public subnets | `map(string)` | `{}` | no |
513518
| <a name="input_public_subnet_tags_per_az"></a> [public\_subnet\_tags\_per\_az](#input\_public\_subnet\_tags\_per\_az) | Additional tags for the public subnets where the primary key is the AZ | `map(map(string))` | `{}` | no |
519+
| <a name="input_public_subnet_tags_per_subnet"></a> [public\_subnet\_tags\_per\_subnet](#input\_public\_subnet\_tags\_per\_subnet) | Additional tags for the public subnets, if specified then must have a length equal to the number of public subnets | `list(map(string))` | `[]` | no |
514520
| <a name="input_public_subnets"></a> [public\_subnets](#input\_public\_subnets) | A list of public subnets inside the VPC | `list(string)` | `[]` | no |
515521
| <a name="input_putin_khuylo"></a> [putin\_khuylo](#input\_putin\_khuylo) | Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo! | `bool` | `true` | no |
516522
| <a name="input_redshift_acl_tags"></a> [redshift\_acl\_tags](#input\_redshift\_acl\_tags) | Additional tags for the redshift subnets network ACL | `map(string)` | `{}` | no |
@@ -525,6 +531,7 @@ No modules.
525531
| <a name="input_redshift_subnet_names"></a> [redshift\_subnet\_names](#input\_redshift\_subnet\_names) | Explicit values to use in the Name tag on redshift subnets. If empty, Name tags are generated. | `list(string)` | `[]` | no |
526532
| <a name="input_redshift_subnet_suffix"></a> [redshift\_subnet\_suffix](#input\_redshift\_subnet\_suffix) | Suffix to append to redshift subnets name | `string` | `"redshift"` | no |
527533
| <a name="input_redshift_subnet_tags"></a> [redshift\_subnet\_tags](#input\_redshift\_subnet\_tags) | Additional tags for the redshift subnets | `map(string)` | `{}` | no |
534+
| <a name="input_redshift_subnet_tags_per_subnet"></a> [redshift\_subnet\_tags\_per\_subnet](#input\_redshift\_subnet\_tags\_per\_subnet) | Additional tags for the redshift subnets, if specified then must have a length equal to the number of redshift subnets | `list(map(string))` | `[]` | no |
528535
| <a name="input_redshift_subnets"></a> [redshift\_subnets](#input\_redshift\_subnets) | A list of redshift subnets | `list(string)` | `[]` | no |
529536
| <a name="input_reuse_nat_ips"></a> [reuse\_nat\_ips](#input\_reuse\_nat\_ips) | Should be true if you don't want EIPs to be created for your NAT Gateways and will instead pass them in via the 'external\_nat\_ip\_ids' variable | `bool` | `false` | no |
530537
| <a name="input_secondary_cidr_blocks"></a> [secondary\_cidr\_blocks](#input\_secondary\_cidr\_blocks) | List of secondary CIDR blocks to associate with the VPC to extend the IP Address pool | `list(string)` | `[]` | no |

main.tf

+9-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ resource "aws_subnet" "public" {
377377
},
378378
var.tags,
379379
var.public_subnet_tags,
380-
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {})
380+
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {}),
381+
length(var.public_subnet_tags_per_subnet) > 0 ? element(var.public_subnet_tags_per_subnet, count.index) : {},
381382
)
382383
}
383384

@@ -405,7 +406,8 @@ resource "aws_subnet" "private" {
405406
},
406407
var.tags,
407408
var.private_subnet_tags,
408-
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {})
409+
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {}),
410+
length(var.private_subnet_tags_per_subnet) > 0 ? element(var.private_subnet_tags_per_subnet, count.index) : {},
409411
)
410412
}
411413

@@ -434,6 +436,7 @@ resource "aws_subnet" "outpost" {
434436
},
435437
var.tags,
436438
var.outpost_subnet_tags,
439+
length(var.outpost_subnet_tags_per_subnet) > 0 ? element(var.outpost_subnet_tags_per_subnet, count.index) : {},
437440
)
438441
}
439442

@@ -461,6 +464,7 @@ resource "aws_subnet" "database" {
461464
},
462465
var.tags,
463466
var.database_subnet_tags,
467+
length(var.database_subnet_tags_per_subnet) > 0 ? element(var.database_subnet_tags_per_subnet, count.index) : {},
464468
)
465469
}
466470

@@ -504,6 +508,7 @@ resource "aws_subnet" "redshift" {
504508
},
505509
var.tags,
506510
var.redshift_subnet_tags,
511+
length(var.redshift_subnet_tags_per_subnet) > 0 ? element(var.redshift_subnet_tags_per_subnet, count.index) : {},
507512
)
508513
}
509514

@@ -545,6 +550,7 @@ resource "aws_subnet" "elasticache" {
545550
},
546551
var.tags,
547552
var.elasticache_subnet_tags,
553+
length(var.elasticache_subnet_tags_per_subnet) > 0 ? element(var.elasticache_subnet_tags_per_subnet, count.index) : {},
548554
)
549555
}
550556

@@ -586,6 +592,7 @@ resource "aws_subnet" "intra" {
586592
},
587593
var.tags,
588594
var.intra_subnet_tags,
595+
length(var.intra_subnet_tags_per_subnet) > 0 ? element(var.intra_subnet_tags_per_subnet, count.index) : {},
589596
)
590597
}
591598

variables.tf

+42
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,12 @@ variable "public_subnet_tags_per_az" {
492492
default = {}
493493
}
494494

495+
variable "public_subnet_tags_per_subnet" {
496+
description = "Additional tags for the public subnets, if specified then must have a length equal to the number of public subnets"
497+
type = list(map(string))
498+
default = []
499+
}
500+
495501
variable "private_subnet_tags" {
496502
description = "Additional tags for the private subnets"
497503
type = map(string)
@@ -504,12 +510,24 @@ variable "private_subnet_tags_per_az" {
504510
default = {}
505511
}
506512

513+
variable "private_subnet_tags_per_subnet" {
514+
description = "Additional tags for the private subnets, if specified then must have a length equal to the number of private subnets"
515+
type = list(map(string))
516+
default = []
517+
}
518+
507519
variable "outpost_subnet_tags" {
508520
description = "Additional tags for the outpost subnets"
509521
type = map(string)
510522
default = {}
511523
}
512524

525+
variable "outpost_subnet_tags_per_subnet" {
526+
description = "Additional tags for the outpost subnets, if specified then must have a length equal to the number of outpost subnets"
527+
type = list(map(string))
528+
default = []
529+
}
530+
513531
variable "public_route_table_tags" {
514532
description = "Additional tags for the public route tables"
515533
type = map(string)
@@ -558,6 +576,12 @@ variable "database_subnet_tags" {
558576
default = {}
559577
}
560578

579+
variable "database_subnet_tags_per_subnet" {
580+
description = "Additional tags for the database subnets, if specified then must have a length equal to the number of database subnets"
581+
type = list(map(string))
582+
default = []
583+
}
584+
561585
variable "database_subnet_group_tags" {
562586
description = "Additional tags for the database subnet group"
563587
type = map(string)
@@ -570,6 +594,12 @@ variable "redshift_subnet_tags" {
570594
default = {}
571595
}
572596

597+
variable "redshift_subnet_tags_per_subnet" {
598+
description = "Additional tags for the redshift subnets, if specified then must have a length equal to the number of redshift subnets"
599+
type = list(map(string))
600+
default = []
601+
}
602+
573603
variable "redshift_subnet_group_name" {
574604
description = "Name of redshift subnet group"
575605
type = string
@@ -600,12 +630,24 @@ variable "elasticache_subnet_tags" {
600630
default = {}
601631
}
602632

633+
variable "elasticache_subnet_tags_per_subnet" {
634+
description = "Additional tags for the elasticache subnets, if specified then must have a length equal to the number of elasticache subnets"
635+
type = list(map(string))
636+
default = []
637+
}
638+
603639
variable "intra_subnet_tags" {
604640
description = "Additional tags for the intra subnets"
605641
type = map(string)
606642
default = {}
607643
}
608644

645+
variable "intra_subnet_tags_per_subnet" {
646+
description = "Additional tags for the intra subnets, if specified then must have a length equal to the number of intra subnets"
647+
type = list(map(string))
648+
default = []
649+
}
650+
609651
variable "public_acl_tags" {
610652
description = "Additional tags for the public subnets network ACL"
611653
type = map(string)

0 commit comments

Comments
 (0)