Skip to content

Commit e5305a6

Browse files
updated custom tags for subnets
1 parent eaecac7 commit e5305a6

File tree

7 files changed

+50
-6
lines changed

7 files changed

+50
-6
lines changed

.terraform.lock.hcl

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ locals {
162162

163163
| Name | Version |
164164
|------|---------|
165-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0, < 7.0 |
165+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.100.0 |
166166

167167
## Modules
168168

@@ -225,7 +225,9 @@ locals {
225225
| <a name="input_kms_config"></a> [kms\_config](#input\_kms\_config) | n/a | <pre>object({<br/> deletion_window_in_days = number<br/> enable_key_rotation = bool<br/> })</pre> | <pre>{<br/> "deletion_window_in_days": 30,<br/> "enable_key_rotation": true<br/>}</pre> | no |
226226
| <a name="input_name"></a> [name](#input\_name) | VPC name | `string` | n/a | yes |
227227
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Namespace name | `string` | n/a | yes |
228-
| <a name="input_subnet_map"></a> [subnet\_map](#input\_subnet\_map) | A map defining the configuration of subnets, their attributes, and associated resources.<br/>Each subnet configuration can include the following details:<br/><br/>- **name**: Name of the subnet.<br/>- **cidr\_block**: CIDR block for the subnet.<br/>- **availability\_zone**: The availability zone where the subnet is located.<br/>- **enable\_resource\_name\_dns\_a\_record\_on\_launch**: Enable or disable DNS A records for EC2 instances launched in this subnet (default: false).<br/>- **enable\_resource\_name\_dns\_aaaa\_record\_on\_launch**: Enable or disable DNS AAAA records for EC2 instances launched in this subnet (default: false).<br/>- **map\_public\_ip\_on\_launch**: Specify whether to auto-assign a public IP for instances in this subnet (default: false).<br/>- **ipv6\_native**: Enable or disable native IPv6 support for the subnet (default: false).<br/>- **assign\_ipv6\_address\_on\_creation**: Whether to automatically assign an IPv6 address to instances launched in the subnet (default: false).<br/>- **ipv6\_cidr\_block**: The IPv6 CIDR block associated with the subnet (optional).<br/>- **enable\_dns64**: Enable or disable DNS64 in the subnet (default: false).<br/>- **nat\_gateway\_name**: Name of the NAT Gateway attached to the subnet (optional).<br/>- **create\_nat\_gateway**: Specify whether to create a NAT Gateway for the subnet (default: true).<br/>- **attach\_nat\_gateway**: Specify whether to attach an existing NAT Gateway to the subnet (default: false).<br/>- **attach\_internet\_gateway**: Specify whether to attach an Internet Gateway to the subnet (default: false).<br/>- **additional\_routes**: List of additional routes to be added to the subnet route table, typically to route traffic to other services like Transit Gateway. Each route includes:<br/> - **type**: Type of resource (default: "transit-gateway").<br/> - **id**: The ID of the route target (e.g., a Transit Gateway ID).<br/> - **cidr\_block**: The destination CIDR block for the route.<br/> - **destination\_ipv6\_cidr\_block**: The destination IPV6 CIDR block for the route. | <pre>map(object({<br/> name = string<br/> cidr_block = string<br/> availability_zone = string<br/> enable_resource_name_dns_a_record_on_launch = optional(bool, false)<br/> enable_resource_name_dns_aaaa_record_on_launch = optional(bool, false)<br/> map_public_ip_on_launch = optional(bool, false)<br/> ipv6_native = optional(bool, false)<br/> assign_ipv6_address_on_creation = optional(bool, false)<br/> ipv6_cidr_block = optional(string, null)<br/> enable_dns64 = optional(bool, false)<br/> nat_gateway_name = optional(string, null)<br/> create_nat_gateway = optional(bool, true)<br/> attach_nat_gateway = optional(bool, false)<br/> attach_internet_gateway = optional(bool, false)<br/> additional_routes = optional(list(object({<br/> type = optional(string, "transit-gateway") // possible values : network-interface ,transit-gateway, vpc-endpoint, vpc-peering-connection<br/> id = string<br/> destination_cidr_block = optional(string, null)<br/> destination_ipv6_cidr_block = optional(string, null)<br/> }<br/> )), [])<br/> }))</pre> | `null` | no |
228+
| <a name="input_private_subnet_tags"></a> [private\_subnet\_tags](#input\_private\_subnet\_tags) | (optional) Additional tags for auto-generated private subnets | `map(string)` | `{}` | no |
229+
| <a name="input_public_subnet_tags"></a> [public\_subnet\_tags](#input\_public\_subnet\_tags) | (optional) Additional tags for auto-generated public subnets | `map(string)` | `{}` | no |
230+
| <a name="input_subnet_map"></a> [subnet\_map](#input\_subnet\_map) | A map defining the configuration of subnets, their attributes, and associated resources.<br/>Each subnet configuration can include the following details:<br/><br/>- **name**: Name of the subnet.<br/>- **cidr\_block**: CIDR block for the subnet.<br/>- **availability\_zone**: The availability zone where the subnet is located.<br/>- **enable\_resource\_name\_dns\_a\_record\_on\_launch**: Enable or disable DNS A records for EC2 instances launched in this subnet (default: false).<br/>- **enable\_resource\_name\_dns\_aaaa\_record\_on\_launch**: Enable or disable DNS AAAA records for EC2 instances launched in this subnet (default: false).<br/>- **map\_public\_ip\_on\_launch**: Specify whether to auto-assign a public IP for instances in this subnet (default: false).<br/>- **ipv6\_native**: Enable or disable native IPv6 support for the subnet (default: false).<br/>- **assign\_ipv6\_address\_on\_creation**: Whether to automatically assign an IPv6 address to instances launched in the subnet (default: false).<br/>- **ipv6\_cidr\_block**: The IPv6 CIDR block associated with the subnet (optional).<br/>- **enable\_dns64**: Enable or disable DNS64 in the subnet (default: false).<br/>- **nat\_gateway\_name**: Name of the NAT Gateway attached to the subnet (optional).<br/>- **create\_nat\_gateway**: Specify whether to create a NAT Gateway for the subnet (default: true).<br/>- **attach\_nat\_gateway**: Specify whether to attach an existing NAT Gateway to the subnet (default: false).<br/>- **attach\_internet\_gateway**: Specify whether to attach an Internet Gateway to the subnet (default: false).<br/>- **additional\_routes**: List of additional routes to be added to the subnet route table, typically to route traffic to other services like Transit Gateway. Each route includes:<br/> - **type**: Type of resource (default: "transit-gateway").<br/> - **id**: The ID of the route target (e.g., a Transit Gateway ID).<br/> - **cidr\_block**: The destination CIDR block for the route.<br/> - **destination\_ipv6\_cidr\_block**: The destination IPV6 CIDR block for the route.<br/>- **tags**: Additional tags to apply to the subnet (default: {}). | <pre>map(object({<br/> name = string<br/> cidr_block = string<br/> availability_zone = string<br/> enable_resource_name_dns_a_record_on_launch = optional(bool, false)<br/> enable_resource_name_dns_aaaa_record_on_launch = optional(bool, false)<br/> map_public_ip_on_launch = optional(bool, false)<br/> ipv6_native = optional(bool, false)<br/> assign_ipv6_address_on_creation = optional(bool, false)<br/> ipv6_cidr_block = optional(string, null)<br/> enable_dns64 = optional(bool, false)<br/> nat_gateway_name = optional(string, null)<br/> create_nat_gateway = optional(bool, true)<br/> attach_nat_gateway = optional(bool, false)<br/> attach_internet_gateway = optional(bool, false)<br/> additional_routes = optional(list(object({<br/> type = optional(string, "transit-gateway") // possible values : network-interface ,transit-gateway, vpc-endpoint, vpc-peering-connection<br/> id = string<br/> destination_cidr_block = optional(string, null)<br/> destination_ipv6_cidr_block = optional(string, null)<br/> }<br/> )), [])<br/> tags = optional(map(string), {})<br/> }))</pre> | `null` | no |
229231
| <a name="input_tags"></a> [tags](#input\_tags) | (optional) Tags for VPC resources | `map(string)` | `{}` | no |
230232
| <a name="input_vpc_endpoint_data"></a> [vpc\_endpoint\_data](#input\_vpc\_endpoint\_data) | (optional) List of VPC endpoints to be created | <pre>list(object({<br/> service = string<br/> route_table_filter = optional(string, "private") // possible values 'private' and 'public'<br/> policy_doc = optional(string, null)<br/> private_dns_enabled = optional(bool, false)<br/> security_group_ids = optional(list(string), [])<br/> }))</pre> | `[]` | no |
231233
| <a name="input_vpc_flow_log_config"></a> [vpc\_flow\_log\_config](#input\_vpc\_flow\_log\_config) | If `s3_bucket_arn` is null, only CloudWatch logging is enabled by default. If `s3_bucket_arn` is provided, S3 logging is enabled. | <pre>object({<br/> enable = bool<br/> retention_in_days = number<br/> s3_bucket_arn = string<br/> })</pre> | <pre>{<br/> "enable": true,<br/> "retention_in_days": 7,<br/> "s3_bucket_arn": null<br/>}</pre> | no |
@@ -286,4 +288,4 @@ By specifying this , it will bump the version and if you dont specify this in yo
286288

287289
## Authors
288290
This project is authored by:
289-
- SourceFuse
291+
- SourceFuse

examples/custom-subnets/local.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
locals {
22

3-
prefix = "${var.namespace}-${var.environment}"
3+
prefix = "${var.namespace}-${var.environment}-custom"
44

55
subnet_map = {
66
"${local.prefix}-public-az1" = {

examples/custom-subnets/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module "network" {
3737
namespace = var.namespace
3838
environment = var.environment
3939

40-
name = "${var.namespace}-${var.environment}"
40+
name = "${var.namespace}-${var.environment}-custom"
4141
create_internet_gateway = true
4242
subnet_map = local.subnet_map
4343
cidr_block = "10.0.0.0/16"

locals-auto.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ locals {
2424
ipv6_cidr_block = null
2525
enable_dns64 = false
2626
additional_routes = []
27+
tags = var.public_subnet_tags
2728
}
2829
}
2930
private_subnet_data = { for idx, az in var.availability_zones : "${var.name}-private-${az}" => {
@@ -43,6 +44,7 @@ locals {
4344
ipv6_cidr_block = null
4445
enable_dns64 = false
4546
additional_routes = []
47+
tags = var.private_subnet_tags
4648
}
4749
}
4850

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ resource "aws_subnet" "this" {
5555
{
5656
Name = each.value.name
5757
},
58-
var.tags
58+
var.tags,
59+
each.value.tags
5960
)
6061
}
6162

variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ variable "subnet_map" {
121121
destination_ipv6_cidr_block = optional(string, null)
122122
}
123123
)), [])
124+
tags = optional(map(string), {})
124125
}))
125126
default = null
126127
description = <<-EOT
@@ -146,6 +147,7 @@ variable "subnet_map" {
146147
- **id**: The ID of the route target (e.g., a Transit Gateway ID).
147148
- **cidr_block**: The destination CIDR block for the route.
148149
- **destination_ipv6_cidr_block**: The destination IPV6 CIDR block for the route.
150+
- **tags**: Additional tags to apply to the subnet (default: {}).
149151
EOT
150152
}
151153

@@ -167,6 +169,18 @@ variable "availability_zones" {
167169
default = []
168170
}
169171

172+
variable "public_subnet_tags" {
173+
type = map(string)
174+
description = "(optional) Additional tags for auto-generated public subnets"
175+
default = {}
176+
}
177+
178+
variable "private_subnet_tags" {
179+
type = map(string)
180+
description = "(optional) Additional tags for auto-generated private subnets"
181+
default = {}
182+
}
183+
170184
variable "tags" {
171185
type = map(string)
172186
description = "(optional) Tags for VPC resources"

0 commit comments

Comments
 (0)