Skip to content

Commit 8514cfb

Browse files
committed
feat: Add public and private and database tags per cidr
1 parent 08e5451 commit 8514cfb

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ No modules.
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 |
386386
| <a name="input_database_subnet_tags_per_az"></a> [database\_subnet\_tags\_per\_az](#input\_database\_subnet\_tags\_per\_az) | Additional tags for the database subnets where the primary key is the AZ | `map(map(string))` | `{}` | no |
387+
| <a name="input_database_subnet_tags_per_cidr"></a> [database\_subnet\_tags\_per\_cidr](#input\_database\_subnet\_tags\_per\_cidr) | Additional tags for the database subnets where the primary key is the CIDR | `map(map(string))` | `{}` | no |
387388
| <a name="input_database_subnets"></a> [database\_subnets](#input\_database\_subnets) | A list of database subnets | `list(string)` | `[]` | no |
388389
| <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 |
389390
| <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 |
@@ -497,6 +498,7 @@ No modules.
497498
| <a name="input_private_subnet_suffix"></a> [private\_subnet\_suffix](#input\_private\_subnet\_suffix) | Suffix to append to private subnets name | `string` | `"private"` | no |
498499
| <a name="input_private_subnet_tags"></a> [private\_subnet\_tags](#input\_private\_subnet\_tags) | Additional tags for the private subnets | `map(string)` | `{}` | no |
499500
| <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 |
501+
| <a name="input_private_subnet_tags_per_cidr"></a> [private\_subnet\_tags\_per\_cidr](#input\_private\_subnet\_tags\_per\_cidr) | Additional tags for the private subnets where the primary key is the CIDR | `map(map(string))` | `{}` | no |
500502
| <a name="input_private_subnets"></a> [private\_subnets](#input\_private\_subnets) | A list of private subnets inside the VPC | `list(string)` | `[]` | no |
501503
| <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 |
502504
| <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 |
@@ -512,6 +514,7 @@ No modules.
512514
| <a name="input_public_subnet_suffix"></a> [public\_subnet\_suffix](#input\_public\_subnet\_suffix) | Suffix to append to public subnets name | `string` | `"public"` | no |
513515
| <a name="input_public_subnet_tags"></a> [public\_subnet\_tags](#input\_public\_subnet\_tags) | Additional tags for the public subnets | `map(string)` | `{}` | no |
514516
| <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 |
517+
| <a name="input_public_subnet_tags_per_cidr"></a> [public\_subnet\_tags\_per\_cidr](#input\_public\_subnet\_tags\_per\_cidr) | Additional tags for the public subnets where the primary key is the CIDR | `map(map(string))` | `{}` | no |
515518
| <a name="input_public_subnets"></a> [public\_subnets](#input\_public\_subnets) | A list of public subnets inside the VPC | `list(string)` | `[]` | no |
516519
| <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 |
517520
| <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 |

examples/simple-vpc/main.tf

+22-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ module "vpc" {
2323
name = local.name
2424
cidr = "10.0.0.0/16"
2525

26-
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
27-
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
28-
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
26+
azs = ["${local.region}a", "${local.region}b", "${local.region}c"]
27+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
28+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
29+
database_subnets = ["10.0.104.0/24", "10.0.105.0/24", "10.0.106.0/24"]
2930

3031
enable_ipv6 = true
3132

@@ -42,6 +43,24 @@ module "vpc" {
4243
}
4344
}
4445

46+
public_subnet_tags_per_cidr = {
47+
"10.0.101.0/24" = {
48+
type = "public-awesome-app"
49+
}
50+
}
51+
52+
private_subnet_tags_per_cidr = {
53+
"10.0.1.0/24" = {
54+
type = "private-awesome-app"
55+
}
56+
}
57+
58+
database_subnet_tags_per_cidr = {
59+
"10.0.104.0/24" = {
60+
type = "awesome-app-db"
61+
}
62+
}
63+
4564
tags = local.tags
4665

4766
vpc_tags = {

main.tf

+6-3
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+
lookup(var.public_subnet_tags_per_cidr, element(concat(var.public_subnets, [""]), 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+
lookup(var.private_subnet_tags_per_cidr, var.private_subnets[count.index], {})
409411
)
410412
}
411413

@@ -461,7 +463,8 @@ resource "aws_subnet" "database" {
461463
},
462464
var.tags,
463465
var.database_subnet_tags,
464-
lookup(var.database_subnet_tags_per_az, element(var.azs, count.index), {})
466+
lookup(var.database_subnet_tags_per_az, element(var.azs, count.index), {}),
467+
lookup(var.database_subnet_tags_per_cidr, var.database_subnets[count.index])
465468
)
466469
}
467470

variables.tf

+18
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_cidr" {
496+
description = "Additional tags for the public subnets where the primary key is the CIDR"
497+
type = map(map(string))
498+
default = {}
499+
}
500+
495501
variable "private_subnet_tags" {
496502
description = "Additional tags for the private subnets"
497503
type = map(string)
@@ -504,6 +510,12 @@ variable "private_subnet_tags_per_az" {
504510
default = {}
505511
}
506512

513+
variable "private_subnet_tags_per_cidr" {
514+
description = "Additional tags for the private subnets where the primary key is the CIDR"
515+
type = map(map(string))
516+
default = {}
517+
}
518+
507519
variable "outpost_subnet_tags" {
508520
description = "Additional tags for the outpost subnets"
509521
type = map(string)
@@ -564,6 +576,12 @@ variable "database_subnet_tags_per_az" {
564576
default = {}
565577
}
566578

579+
variable "database_subnet_tags_per_cidr" {
580+
description = "Additional tags for the database subnets where the primary key is the CIDR"
581+
type = map(map(string))
582+
default = {}
583+
}
584+
567585
variable "database_subnet_group_tags" {
568586
description = "Additional tags for the database subnet group"
569587
type = map(string)

0 commit comments

Comments
 (0)