diff --git a/.gitignore b/.gitignore index f3bc35109..c536226f1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ terraform.tfstate terraform.tfvars Gemfile.lock +.idea diff --git a/main.tf b/main.tf index b40b988a0..384ad17e1 100644 --- a/main.tf +++ b/main.tf @@ -10,7 +10,7 @@ locals { ###### # VPC ###### -resource "aws_vpc" "this" { +resource "aws_vpc" "mod" { count = "${var.create_vpc ? 1 : 0}" cidr_block = "${var.cidr}" @@ -42,7 +42,7 @@ resource "aws_vpc_dhcp_options" "this" { resource "aws_vpc_dhcp_options_association" "this" { count = "${var.create_vpc && var.enable_dhcp_options ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" dhcp_options_id = "${aws_vpc_dhcp_options.this.id}" } @@ -52,7 +52,7 @@ resource "aws_vpc_dhcp_options_association" "this" { resource "aws_internet_gateway" "this" { count = "${var.create_vpc && length(var.public_subnets) > 0 ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" tags = "${merge(map("Name", format("%s", var.name)), var.igw_tags, var.tags)}" } @@ -63,7 +63,7 @@ resource "aws_internet_gateway" "this" { resource "aws_route_table" "public" { count = "${var.create_vpc && length(var.public_subnets) > 0 ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" tags = "${merge(map("Name", format("%s-public", var.name)), var.public_route_table_tags, var.tags)}" } @@ -87,7 +87,7 @@ resource "aws_route" "public_internet_gateway" { resource "aws_route_table" "private" { count = "${var.create_vpc && local.max_subnet_length > 0 ? local.nat_gateway_count : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" 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)}" @@ -104,7 +104,7 @@ resource "aws_route_table" "private" { resource "aws_route_table" "intra" { count = "${var.create_vpc && length(var.intra_subnets) > 0 ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" tags = "${merge(map("Name", "${var.name}-intra"), var.intra_route_table_tags, var.tags)}" } @@ -115,7 +115,7 @@ resource "aws_route_table" "intra" { resource "aws_subnet" "public" { count = "${var.create_vpc && length(var.public_subnets) > 0 && (!var.one_nat_gateway_per_az || length(var.public_subnets) >= length(var.azs)) ? length(var.public_subnets) : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" cidr_block = "${var.public_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" map_public_ip_on_launch = "${var.map_public_ip_on_launch}" @@ -129,7 +129,7 @@ resource "aws_subnet" "public" { resource "aws_subnet" "private" { count = "${var.create_vpc && length(var.private_subnets) > 0 ? length(var.private_subnets) : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" cidr_block = "${var.private_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" @@ -142,7 +142,7 @@ resource "aws_subnet" "private" { resource "aws_subnet" "database" { count = "${var.create_vpc && length(var.database_subnets) > 0 ? length(var.database_subnets) : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" cidr_block = "${var.database_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" @@ -165,7 +165,7 @@ resource "aws_db_subnet_group" "database" { resource "aws_subnet" "redshift" { count = "${var.create_vpc && length(var.redshift_subnets) > 0 ? length(var.redshift_subnets) : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" cidr_block = "${var.redshift_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" @@ -188,7 +188,7 @@ resource "aws_redshift_subnet_group" "redshift" { resource "aws_subnet" "elasticache" { count = "${var.create_vpc && length(var.elasticache_subnets) > 0 ? length(var.elasticache_subnets) : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" cidr_block = "${var.elasticache_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" @@ -209,7 +209,7 @@ resource "aws_elasticache_subnet_group" "elasticache" { resource "aws_subnet" "intra" { count = "${var.create_vpc && length(var.intra_subnets) > 0 ? length(var.intra_subnets) : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" cidr_block = "${var.intra_subnets[count.index]}" availability_zone = "${element(var.azs, count.index)}" @@ -274,7 +274,7 @@ data "aws_vpc_endpoint_service" "s3" { resource "aws_vpc_endpoint" "s3" { count = "${var.create_vpc && var.enable_s3_endpoint ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" service_name = "${data.aws_vpc_endpoint_service.s3.service_name}" } @@ -311,7 +311,7 @@ data "aws_vpc_endpoint_service" "dynamodb" { resource "aws_vpc_endpoint" "dynamodb" { count = "${var.create_vpc && var.enable_dynamodb_endpoint ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" service_name = "${data.aws_vpc_endpoint_service.dynamodb.service_name}" } @@ -387,7 +387,7 @@ resource "aws_route_table_association" "public" { resource "aws_vpn_gateway" "this" { count = "${var.create_vpc && var.enable_vpn_gateway ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" tags = "${merge(map("Name", format("%s", var.name)), var.vpn_gateway_tags, var.tags)}" } @@ -395,7 +395,7 @@ resource "aws_vpn_gateway" "this" { resource "aws_vpn_gateway_attachment" "this" { count = "${var.vpn_gateway_id != "" ? 1 : 0}" - vpc_id = "${aws_vpc.this.id}" + vpc_id = "${aws_vpc.mod.id}" vpn_gateway_id = "${var.vpn_gateway_id}" } diff --git a/outputs.tf b/outputs.tf index 33118e555..6f10283d5 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,62 +1,62 @@ # VPC output "vpc_id" { description = "The ID of the VPC" - value = "${element(concat(aws_vpc.this.*.id, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.id, list("")), 0)}" } output "vpc_cidr_block" { description = "The CIDR block of the VPC" - value = "${element(concat(aws_vpc.this.*.cidr_block, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.cidr_block, list("")), 0)}" } output "default_security_group_id" { description = "The ID of the security group created by default on VPC creation" - value = "${element(concat(aws_vpc.this.*.default_security_group_id, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.default_security_group_id, list("")), 0)}" } output "default_network_acl_id" { description = "The ID of the default network ACL" - value = "${element(concat(aws_vpc.this.*.default_network_acl_id, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.default_network_acl_id, list("")), 0)}" } output "default_route_table_id" { description = "The ID of the default route table" - value = "${element(concat(aws_vpc.this.*.default_route_table_id, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.default_route_table_id, list("")), 0)}" } output "vpc_instance_tenancy" { description = "Tenancy of instances spin up within VPC" - value = "${element(concat(aws_vpc.this.*.instance_tenancy, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.instance_tenancy, list("")), 0)}" } output "vpc_enable_dns_support" { description = "Whether or not the VPC has DNS support" - value = "${element(concat(aws_vpc.this.*.enable_dns_support, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.enable_dns_support, list("")), 0)}" } output "vpc_enable_dns_hostnames" { description = "Whether or not the VPC has DNS hostname support" - value = "${element(concat(aws_vpc.this.*.enable_dns_hostnames, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.enable_dns_hostnames, list("")), 0)}" } //output "vpc_enable_classiclink" { // description = "Whether or not the VPC has Classiclink enabled" -// value = "${element(concat(aws_vpc.this.*.enable_classiclink, list("")), 0)}" +// value = "${element(concat(aws_vpc.mod.*.enable_classiclink, list("")), 0)}" //} output "vpc_main_route_table_id" { description = "The ID of the main route table associated with this VPC" - value = "${element(concat(aws_vpc.this.*.main_route_table_id, list("")), 0)}" + value = "${element(concat(aws_vpc.mod.*.main_route_table_id, list("")), 0)}" } //output "vpc_ipv6_association_id" { // description = "The association ID for the IPv6 CIDR block" -// value = "${element(concat(aws_vpc.this.*.ipv6_association_id, list("")), 0)}" +// value = "${element(concat(aws_vpc.mod.*.ipv6_association_id, list("")), 0)}" //} // //output "vpc_ipv6_cidr_block" { // description = "The IPv6 CIDR block" -// value = "${element(concat(aws_vpc.this.*.ipv6_cidr_block, list("")), 0)}" +// value = "${element(concat(aws_vpc.mod.*.ipv6_cidr_block, list("")), 0)}" //} # Subnets