Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support defining tags per subnet name #1139

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ No modules.
| <a name="input_private_subnet_suffix"></a> [private\_subnet\_suffix](#input\_private\_subnet\_suffix) | Suffix to append to private subnets name | `string` | `"private"` | no |
| <a name="input_private_subnet_tags"></a> [private\_subnet\_tags](#input\_private\_subnet\_tags) | Additional tags for the private subnets | `map(string)` | `{}` | no |
| <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 |
| <a name="input_private_subnet_tags_per_name"></a> [private\_subnet\_tags\_per\_name](#input\_private\_subnet\_tags\_per\_name) | Additional tags for the private subnets where the primary key is the subnet name | `map(map(string))` | `{}` | no |
| <a name="input_private_subnets"></a> [private\_subnets](#input\_private\_subnets) | A list of private subnets inside the VPC | `list(string)` | `[]` | no |
| <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 |
| <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 |
Expand All @@ -556,6 +557,7 @@ No modules.
| <a name="input_public_subnet_suffix"></a> [public\_subnet\_suffix](#input\_public\_subnet\_suffix) | Suffix to append to public subnets name | `string` | `"public"` | no |
| <a name="input_public_subnet_tags"></a> [public\_subnet\_tags](#input\_public\_subnet\_tags) | Additional tags for the public subnets | `map(string)` | `{}` | no |
| <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 |
| <a name="input_public_subnet_tags_per_name"></a> [public\_subnet\_tags\_per\_name](#input\_public\_subnet\_tags\_per\_name) | Additional tags for the public subnets where the primary key is the subnet name | `map(map(string))` | `{}` | no |
| <a name="input_public_subnets"></a> [public\_subnets](#input\_public\_subnets) | A list of public subnets inside the VPC | `list(string)` | `[]` | no |
| <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 |
| <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 |
Expand Down
8 changes: 8 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ module "vpc" {
intra_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 20)]

private_subnet_names = ["Private Subnet One", "Private Subnet Two"]
private_subnet_tags_per_name = {
"Private Subnet One" = {
"subnet one" = "true"
},
"Private Subnet Two" = {
"subnet two" = "true"
}
}
# public_subnet_names omitted to show default name generation for all three subnets
database_subnet_names = ["DB Subnet One"]
elasticache_subnet_names = ["Elasticache Subnet One", "Elasticache Subnet Two"]
Expand Down
6 changes: 4 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ resource "aws_subnet" "public" {
},
var.tags,
var.public_subnet_tags,
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {})
lookup(var.public_subnet_tags_per_az, element(var.azs, count.index), {}),
lookup(var.public_subnet_tags_per_name, try(var.public_subnet_names[count.index], ""), {})
)
}

Expand Down Expand Up @@ -255,7 +256,8 @@ resource "aws_subnet" "private" {
},
var.tags,
var.private_subnet_tags,
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {})
lookup(var.private_subnet_tags_per_az, element(var.azs, count.index), {}),
lookup(var.private_subnet_tags_per_name, try(var.private_subnet_names[count.index], ""), {})
)
}

Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ variable "public_subnet_tags_per_az" {
default = {}
}

variable "public_subnet_tags_per_name" {
description = "Additional tags for the public subnets where the primary key is the subnet name"
type = map(map(string))
default = {}
}

variable "public_route_table_tags" {
description = "Additional tags for the public route tables"
type = map(string)
Expand Down Expand Up @@ -390,6 +396,12 @@ variable "private_subnet_tags_per_az" {
default = {}
}

variable "private_subnet_tags_per_name" {
description = "Additional tags for the private subnets where the primary key is the subnet name"
type = map(map(string))
default = {}
}

variable "private_route_table_tags" {
description = "Additional tags for the private route tables"
type = map(string)
Expand Down
Loading