diff --git a/README.md b/README.md index 3af1a0130..41627717a 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,7 @@ Terraform version 0.10.3 or newer is required for this module to work. | cidr | The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overriden | string | `0.0.0.0/0` | no | | create_database_subnet_group | Controls if database subnet group should be created | string | `true` | no | | create_vpc | Controls if VPC should be created (it affects almost all resources) | string | `true` | no | +| database_subnet_group_tags | Additional tags for the database subnet group | string | `` | no | | database_subnet_tags | Additional tags for the database subnets | string | `` | no | | database_subnets | A list of database subnets | list | `` | no | | default_route_table_tags | Additional tags for the default route table | string | `` | no | @@ -191,6 +192,7 @@ Terraform version 0.10.3 or newer is required for this module to work. | enable_s3_endpoint | Should be true if you want to provision an S3 endpoint to the VPC | string | `false` | no | | enable_vpn_gateway | Should be true if you want to create a new VPN Gateway resource and attach it to the VPC | string | `false` | no | | external_nat_ip_ids | List of EIP IDs to be assigned to the NAT Gateways (used in combination with reuse_nat_ips) | list | `` | no | +| igw_tags | Additional tags for the internet gateway | string | `` | no | | instance_tenancy | A tenancy option for instances launched into the VPC | string | `default` | no | | intra_route_table_tags | Additional tags for the intra route tables | string | `` | no | | intra_subnet_tags | Additional tags for the intra subnets | string | `` | no | @@ -198,7 +200,8 @@ Terraform version 0.10.3 or newer is required for this module to work. | manage_default_vpc | Should be true to adopt and manage Default VPC | string | `false` | no | | map_public_ip_on_launch | Should be false if you do not want to auto-assign public IP on launch | string | `true` | no | | name | Name to be used on all the resources as identifier | string | `` | no | -| nat_gateway_tags | Additional tags for the nat gateways | string | `` | no | +| nat_eip_tags | Additional tags for the NAT EIP | string | `` | no | +| nat_gateway_tags | Additional tags for the NAT gateways | string | `` | no | | 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`. | string | `false` | no | | private_route_table_tags | Additional tags for the private route tables | string | `` | no | | private_subnet_tags | Additional tags for the private subnets | string | `` | no | @@ -208,6 +211,7 @@ Terraform version 0.10.3 or newer is required for this module to work. | public_route_table_tags | Additional tags for the public route tables | string | `` | no | | public_subnet_tags | Additional tags for the public subnets | string | `` | no | | public_subnets | A list of public subnets inside the VPC | string | `` | no | +| redshift_subnet_group_tags | Additional tags for the redshift subnet group | string | `` | no | | redshift_subnet_tags | Additional tags for the redshift subnets | string | `` | no | | redshift_subnets | A list of redshift subnets | list | `` | no | | 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 | string | `false` | no | @@ -215,6 +219,7 @@ Terraform version 0.10.3 or newer is required for this module to work. | tags | A map of tags to add to all resources | string | `` | no | | vpc_tags | Additional tags for the VPC | string | `` | no | | vpn_gateway_id | ID of VPN Gateway to attach to the VPC | string | `` | no | +| vpn_gateway_tags | Additional tags for the VPN gateway | string | `` | no | ## Outputs diff --git a/examples/simple-vpc/main.tf b/examples/simple-vpc/main.tf index 6cf916fc4..ac8ca9016 100644 --- a/examples/simple-vpc/main.tf +++ b/examples/simple-vpc/main.tf @@ -16,8 +16,16 @@ module "vpc" { enable_nat_gateway = true single_nat_gateway = true + public_subnet_tags = { + Name = "overriden-name-public" + } + tags = { Owner = "user" Environment = "dev" } + + vpc_tags = { + Name = "vpc-name" + } } diff --git a/main.tf b/main.tf index 1bd9b17ff..b40b988a0 100644 --- a/main.tf +++ b/main.tf @@ -18,7 +18,7 @@ resource "aws_vpc" "this" { enable_dns_hostnames = "${var.enable_dns_hostnames}" enable_dns_support = "${var.enable_dns_support}" - tags = "${merge(var.tags, var.vpc_tags, map("Name", format("%s", var.name)))}" + tags = "${merge(map("Name", format("%s", var.name)), var.vpc_tags, var.tags)}" } ################### @@ -33,7 +33,7 @@ resource "aws_vpc_dhcp_options" "this" { netbios_name_servers = ["${var.dhcp_options_netbios_name_servers}"] netbios_node_type = "${var.dhcp_options_netbios_node_type}" - tags = "${merge(var.tags, var.dhcp_options_tags, map("Name", format("%s", var.name)))}" + tags = "${merge(map("Name", format("%s", var.name)), var.dhcp_options_tags, var.tags)}" } ############################### @@ -54,7 +54,7 @@ resource "aws_internet_gateway" "this" { vpc_id = "${aws_vpc.this.id}" - tags = "${merge(var.tags, map("Name", format("%s", var.name)))}" + tags = "${merge(map("Name", format("%s", var.name)), var.igw_tags, var.tags)}" } ################ @@ -65,7 +65,7 @@ resource "aws_route_table" "public" { vpc_id = "${aws_vpc.this.id}" - tags = "${merge(var.tags, var.public_route_table_tags, map("Name", format("%s-public", var.name)))}" + tags = "${merge(map("Name", format("%s-public", var.name)), var.public_route_table_tags, var.tags)}" } resource "aws_route" "public_internet_gateway" { @@ -89,7 +89,7 @@ resource "aws_route_table" "private" { vpc_id = "${aws_vpc.this.id}" - tags = "${merge(var.tags, var.private_route_table_tags, map("Name", (var.single_nat_gateway ? "${var.name}-private" : format("%s-private-%s", var.name, element(var.azs, count.index)))))}" + tags = "${merge(map("Name", (var.single_nat_gateway ? "${var.name}-private" : format("%s-private-%s", var.name, element(var.azs, count.index)))), var.private_route_table_tags, var.tags)}" lifecycle { # When attaching VPN gateways it is common to define aws_vpn_gateway_route_propagation @@ -106,7 +106,7 @@ resource "aws_route_table" "intra" { vpc_id = "${aws_vpc.this.id}" - tags = "${merge(var.tags, var.intra_route_table_tags, map("Name", "${var.name}-intra"))}" + tags = "${merge(map("Name", "${var.name}-intra"), var.intra_route_table_tags, var.tags)}" } ################ @@ -120,7 +120,7 @@ resource "aws_subnet" "public" { availability_zone = "${element(var.azs, count.index)}" map_public_ip_on_launch = "${var.map_public_ip_on_launch}" - tags = "${merge(var.tags, var.public_subnet_tags, map("Name", format("%s-public-%s", var.name, element(var.azs, count.index))))}" + tags = "${merge(map("Name", format("%s-public-%s", var.name, element(var.azs, count.index))), var.public_subnet_tags, var.tags)}" } ################# @@ -133,7 +133,7 @@ resource "aws_subnet" "private" { cidr_block = "${var.private_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" - tags = "${merge(var.tags, var.private_subnet_tags, map("Name", format("%s-private-%s", var.name, element(var.azs, count.index))))}" + tags = "${merge(map("Name", format("%s-private-%s", var.name, element(var.azs, count.index))), var.private_subnet_tags, var.tags)}" } ################## @@ -146,7 +146,7 @@ resource "aws_subnet" "database" { cidr_block = "${var.database_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" - tags = "${merge(var.tags, var.database_subnet_tags, map("Name", format("%s-db-%s", var.name, element(var.azs, count.index))))}" + tags = "${merge(map("Name", format("%s-db-%s", var.name, element(var.azs, count.index))), var.database_subnet_tags, var.tags)}" } resource "aws_db_subnet_group" "database" { @@ -156,7 +156,7 @@ resource "aws_db_subnet_group" "database" { description = "Database subnet group for ${var.name}" subnet_ids = ["${aws_subnet.database.*.id}"] - tags = "${merge(var.tags, map("Name", format("%s", var.name)))}" + tags = "${merge(map("Name", format("%s", var.name)), var.database_subnet_group_tags, var.tags)}" } ################## @@ -169,7 +169,7 @@ resource "aws_subnet" "redshift" { cidr_block = "${var.redshift_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" - tags = "${merge(var.tags, var.redshift_subnet_tags, map("Name", format("%s-redshift-%s", var.name, element(var.azs, count.index))))}" + tags = "${merge(map("Name", format("%s-redshift-%s", var.name, element(var.azs, count.index))), var.redshift_subnet_tags, var.tags)}" } resource "aws_redshift_subnet_group" "redshift" { @@ -179,7 +179,7 @@ resource "aws_redshift_subnet_group" "redshift" { description = "Redshift subnet group for ${var.name}" subnet_ids = ["${aws_subnet.redshift.*.id}"] - tags = "${merge(var.tags, map("Name", format("%s", var.name)))}" + tags = "${merge(map("Name", format("%s", var.name)), var.redshift_subnet_group_tags, var.tags)}" } ##################### @@ -192,7 +192,7 @@ resource "aws_subnet" "elasticache" { cidr_block = "${var.elasticache_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" - tags = "${merge(var.tags, var.elasticache_subnet_tags, map("Name", format("%s-elasticache-%s", var.name, element(var.azs, count.index))))}" + tags = "${merge(map("Name", format("%s-elasticache-%s", var.name, element(var.azs, count.index))), var.elasticache_subnet_tags, var.tags)}" } resource "aws_elasticache_subnet_group" "elasticache" { @@ -204,7 +204,7 @@ resource "aws_elasticache_subnet_group" "elasticache" { } ##################################################### -# intra subnets - private subnet with no NAT gateway +# intra subnets - private subnet without NAT gateway ##################################################### resource "aws_subnet" "intra" { count = "${var.create_vpc && length(var.intra_subnets) > 0 ? length(var.intra_subnets) : 0}" @@ -213,7 +213,7 @@ resource "aws_subnet" "intra" { cidr_block = "${var.intra_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" - tags = "${merge(var.tags, var.intra_subnet_tags, map("Name", format("%s-intra-%s", var.name, element(var.azs, count.index))))}" + tags = "${merge(map("Name", format("%s-intra-%s", var.name, element(var.azs, count.index))), var.intra_subnet_tags, var.tags)}" } ############## @@ -236,7 +236,7 @@ resource "aws_eip" "nat" { vpc = true - tags = "${merge(var.tags, map("Name", format("%s-%s", var.name, element(var.azs, (var.single_nat_gateway ? 0 : count.index)))))}" + tags = "${merge(map("Name", format("%s-%s", var.name, element(var.azs, (var.single_nat_gateway ? 0 : count.index)))), var.nat_eip_tags, var.tags)}" } resource "aws_nat_gateway" "this" { @@ -245,7 +245,7 @@ resource "aws_nat_gateway" "this" { allocation_id = "${element(local.nat_gateway_ips, (var.single_nat_gateway ? 0 : count.index))}" subnet_id = "${element(aws_subnet.public.*.id, (var.single_nat_gateway ? 0 : count.index))}" - tags = "${merge(var.tags, var.nat_gateway_tags, map("Name", format("%s-%s", var.name, element(var.azs, (var.single_nat_gateway ? 0 : count.index)))))}" + tags = "${merge(map("Name", format("%s-%s", var.name, element(var.azs, (var.single_nat_gateway ? 0 : count.index)))), var.nat_gateway_tags, var.tags)}" depends_on = ["aws_internet_gateway.this"] } @@ -389,7 +389,7 @@ resource "aws_vpn_gateway" "this" { vpc_id = "${aws_vpc.this.id}" - tags = "${merge(var.tags, map("Name", format("%s", var.name)))}" + tags = "${merge(map("Name", format("%s", var.name)), var.vpn_gateway_tags, var.tags)}" } resource "aws_vpn_gateway_attachment" "this" { @@ -423,5 +423,5 @@ resource "aws_default_vpc" "this" { enable_dns_hostnames = "${var.default_vpc_enable_dns_hostnames}" enable_classiclink = "${var.default_vpc_enable_classiclink}" - tags = "${merge(var.tags, var.default_vpc_tags, map("Name", format("%s", var.default_vpc_name)))}" + tags = "${merge(map("Name", format("%s", var.default_vpc_name)), var.default_vpc_tags, var.tags)}" } diff --git a/variables.tf b/variables.tf index 5462800b9..398ed1300 100644 --- a/variables.tf +++ b/variables.tf @@ -143,6 +143,11 @@ variable "vpc_tags" { default = {} } +variable "igw_tags" { + description = "Additional tags for the internet gateway" + default = {} +} + variable "public_subnet_tags" { description = "Additional tags for the public subnets" default = {} @@ -178,11 +183,21 @@ variable "database_subnet_tags" { default = {} } +variable "database_subnet_group_tags" { + description = "Additional tags for the database subnet group" + default = {} +} + variable "redshift_subnet_tags" { description = "Additional tags for the redshift subnets" default = {} } +variable "redshift_subnet_group_tags" { + description = "Additional tags for the redshift subnet group" + default = {} +} + variable "elasticache_subnet_tags" { description = "Additional tags for the elasticache subnets" default = {} @@ -199,7 +214,17 @@ variable "dhcp_options_tags" { } variable "nat_gateway_tags" { - description = "Additional tags for the nat gateways" + description = "Additional tags for the NAT gateways" + default = {} +} + +variable "nat_eip_tags" { + description = "Additional tags for the NAT EIP" + default = {} +} + +variable "vpn_gateway_tags" { + description = "Additional tags for the VPN gateway" default = {} }