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

fix: Remove references to the create_vpc variable from unrelated reso… #994

Closed
Closed
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ No modules.
| <a name="input_create_igw"></a> [create\_igw](#input\_create\_igw) | Controls if an Internet Gateway is created for public subnets and the related routes that connect them | `bool` | `true` | no |
| <a name="input_create_redshift_subnet_group"></a> [create\_redshift\_subnet\_group](#input\_create\_redshift\_subnet\_group) | Controls if redshift subnet group should be created | `bool` | `true` | no |
| <a name="input_create_redshift_subnet_route_table"></a> [create\_redshift\_subnet\_route\_table](#input\_create\_redshift\_subnet\_route\_table) | Controls if separate route table for redshift should be created | `bool` | `false` | no |
| <a name="input_create_vpc"></a> [create\_vpc](#input\_create\_vpc) | Controls if VPC should be created (it affects almost all resources) | `bool` | `true` | no |
| <a name="input_create_vpc"></a> [create\_vpc](#input\_create\_vpc) | Controls if VPC should be created | `bool` | `true` | no |
| <a name="input_customer_gateway_tags"></a> [customer\_gateway\_tags](#input\_customer\_gateway\_tags) | Additional tags for the Customer Gateway | `map(string)` | `{}` | no |
| <a name="input_customer_gateways"></a> [customer\_gateways](#input\_customer\_gateways) | Maps of Customer Gateway's attributes (BGP ASN and Gateway's Internet-routable external IP address) | `map(map(any))` | `{}` | no |
| <a name="input_customer_owned_ipv4_pool"></a> [customer\_owned\_ipv4\_pool](#input\_customer\_owned\_ipv4\_pool) | The customer owned IPv4 address pool. Typically used with the `map_customer_owned_ip_on_launch` argument. The `outpost_arn` argument must be specified when configured | `string` | `null` | no |
Expand Down Expand Up @@ -572,6 +572,7 @@ No modules.
| <a name="input_use_ipam_pool"></a> [use\_ipam\_pool](#input\_use\_ipam\_pool) | Determines whether IPAM pool is used for CIDR allocation | `bool` | `false` | no |
| <a name="input_vpc_flow_log_permissions_boundary"></a> [vpc\_flow\_log\_permissions\_boundary](#input\_vpc\_flow\_log\_permissions\_boundary) | The ARN of the Permissions Boundary for the VPC Flow Log IAM Role | `string` | `null` | no |
| <a name="input_vpc_flow_log_tags"></a> [vpc\_flow\_log\_tags](#input\_vpc\_flow\_log\_tags) | Additional tags for the VPC Flow Logs | `map(string)` | `{}` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | If create\_vpc variable value is false, then you must have to provide ID of the VPC. | `string` | `null` | no |
| <a name="input_vpc_tags"></a> [vpc\_tags](#input\_vpc\_tags) | Additional tags for the VPC | `map(string)` | `{}` | no |
| <a name="input_vpn_gateway_az"></a> [vpn\_gateway\_az](#input\_vpn\_gateway\_az) | The Availability Zone for the VPN Gateway | `string` | `null` | no |
| <a name="input_vpn_gateway_id"></a> [vpn\_gateway\_id](#input\_vpn\_gateway\_id) | ID of VPN Gateway to attach to the VPC | `string` | `""` | no |
Expand Down
51 changes: 27 additions & 24 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ locals {
max_subnet_length = max(
local.len_private_subnets,
local.len_public_subnets,
local.len_intra_subnets,
local.len_elasticache_subnets,
local.len_database_subnets,
local.len_redshift_subnets,
)

# Use `local.vpc_id` to give a hint to Terraform that subnets should be deleted before secondary CIDR blocks can be free!
vpc_id = try(aws_vpc_ipv4_cidr_block_association.this[0].vpc_id, aws_vpc.this[0].id, "")
vpc_id = try(aws_vpc_ipv4_cidr_block_association.this[0].vpc_id, aws_vpc.this[0].id, var.vpc_id)

create_vpc = var.create_vpc && var.putin_khuylo
}


################################################################################
# VPC
################################################################################
Expand Down Expand Up @@ -51,12 +53,13 @@ resource "aws_vpc" "this" {
}

resource "aws_vpc_ipv4_cidr_block_association" "this" {
count = local.create_vpc && length(var.secondary_cidr_blocks) > 0 ? length(var.secondary_cidr_blocks) : 0
count = var.create_vpc && length(var.secondary_cidr_blocks) > 0 ? length(var.secondary_cidr_blocks) : 0

# Do not turn this into `local.vpc_id`
vpc_id = aws_vpc.this[0].id

cidr_block = element(var.secondary_cidr_blocks, count.index)

}

################################################################################
Expand Down Expand Up @@ -89,9 +92,9 @@ resource "aws_vpc_dhcp_options_association" "this" {
################################################################################
# Publiс Subnets
################################################################################

#
locals {
create_public_subnets = local.create_vpc && local.len_public_subnets > 0
create_public_subnets = local.len_public_subnets > 0
}

resource "aws_subnet" "public" {
Expand Down Expand Up @@ -218,7 +221,7 @@ resource "aws_network_acl_rule" "public_outbound" {
################################################################################

locals {
create_private_subnets = local.create_vpc && local.len_private_subnets > 0
create_private_subnets = local.len_private_subnets > 0
}

resource "aws_subnet" "private" {
Expand Down Expand Up @@ -337,7 +340,7 @@ resource "aws_network_acl_rule" "private_outbound" {
################################################################################

locals {
create_database_subnets = local.create_vpc && local.len_database_subnets > 0
create_database_subnets = local.len_database_subnets > 0
create_database_route_table = local.create_database_subnets && var.create_database_subnet_route_table
}

Expand Down Expand Up @@ -519,7 +522,7 @@ resource "aws_network_acl_rule" "database_outbound" {
################################################################################

locals {
create_redshift_subnets = local.create_vpc && local.len_redshift_subnets > 0
create_redshift_subnets = local.len_redshift_subnets > 0
create_redshift_route_table = local.create_redshift_subnets && var.create_redshift_subnet_route_table
}

Expand Down Expand Up @@ -656,7 +659,7 @@ resource "aws_network_acl_rule" "redshift_outbound" {
################################################################################

locals {
create_elasticache_subnets = local.create_vpc && local.len_elasticache_subnets > 0
create_elasticache_subnets = local.len_elasticache_subnets > 0
create_elasticache_route_table = local.create_elasticache_subnets && var.create_elasticache_subnet_route_table
}

Expand Down Expand Up @@ -786,7 +789,7 @@ resource "aws_network_acl_rule" "elasticache_outbound" {
################################################################################

locals {
create_intra_subnets = local.create_vpc && local.len_intra_subnets > 0
create_intra_subnets = local.len_intra_subnets > 0
}

resource "aws_subnet" "intra" {
Expand Down Expand Up @@ -895,7 +898,7 @@ resource "aws_network_acl_rule" "intra_outbound" {
################################################################################

locals {
create_outpost_subnets = local.create_vpc && local.len_outpost_subnets > 0
create_outpost_subnets = local.len_outpost_subnets > 0
}

resource "aws_subnet" "outpost" {
Expand Down Expand Up @@ -1009,7 +1012,7 @@ resource "aws_internet_gateway" "this" {
}

resource "aws_egress_only_internet_gateway" "this" {
count = local.create_vpc && var.create_egress_only_igw && var.enable_ipv6 && local.max_subnet_length > 0 ? 1 : 0
count = var.create_egress_only_igw && var.enable_ipv6 && local.max_subnet_length > 0 ? 1 : 0

vpc_id = local.vpc_id

Expand All @@ -1021,7 +1024,7 @@ resource "aws_egress_only_internet_gateway" "this" {
}

resource "aws_route" "private_ipv6_egress" {
count = local.create_vpc && var.create_egress_only_igw && var.enable_ipv6 ? local.len_private_subnets : 0
count = var.create_egress_only_igw && var.enable_ipv6 ? local.len_private_subnets : 0

route_table_id = element(aws_route_table.private[*].id, count.index)
destination_ipv6_cidr_block = "::/0"
Expand All @@ -1038,7 +1041,7 @@ locals {
}

resource "aws_eip" "nat" {
count = local.create_vpc && var.enable_nat_gateway && !var.reuse_nat_ips ? local.nat_gateway_count : 0
count = var.enable_nat_gateway && !var.reuse_nat_ips ? local.nat_gateway_count : 0

domain = "vpc"

Expand All @@ -1057,7 +1060,7 @@ resource "aws_eip" "nat" {
}

resource "aws_nat_gateway" "this" {
count = local.create_vpc && var.enable_nat_gateway ? local.nat_gateway_count : 0
count = var.enable_nat_gateway ? local.nat_gateway_count : 0

allocation_id = element(
local.nat_gateway_ips,
Expand All @@ -1083,7 +1086,7 @@ resource "aws_nat_gateway" "this" {
}

resource "aws_route" "private_nat_gateway" {
count = local.create_vpc && var.enable_nat_gateway ? local.nat_gateway_count : 0
count = var.enable_nat_gateway ? local.nat_gateway_count : 0

route_table_id = element(aws_route_table.private[*].id, count.index)
destination_cidr_block = var.nat_gateway_destination_cidr_block
Expand All @@ -1095,7 +1098,7 @@ resource "aws_route" "private_nat_gateway" {
}

resource "aws_route" "private_dns64_nat_gateway" {
count = local.create_vpc && var.enable_nat_gateway && var.enable_ipv6 && var.private_subnet_enable_dns64 ? local.nat_gateway_count : 0
count = var.enable_nat_gateway && var.enable_ipv6 && var.private_subnet_enable_dns64 ? local.nat_gateway_count : 0

route_table_id = element(aws_route_table.private[*].id, count.index)
destination_ipv6_cidr_block = "64:ff9b::/96"
Expand Down Expand Up @@ -1130,7 +1133,7 @@ resource "aws_customer_gateway" "this" {
################################################################################

resource "aws_vpn_gateway" "this" {
count = local.create_vpc && var.enable_vpn_gateway ? 1 : 0
count = var.enable_vpn_gateway ? 1 : 0

vpc_id = local.vpc_id
amazon_side_asn = var.amazon_side_asn
Expand All @@ -1151,7 +1154,7 @@ resource "aws_vpn_gateway_attachment" "this" {
}

resource "aws_vpn_gateway_route_propagation" "public" {
count = local.create_vpc && var.propagate_public_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? 1 : 0
count = var.propagate_public_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? 1 : 0

route_table_id = element(aws_route_table.public[*].id, count.index)
vpn_gateway_id = element(
Expand All @@ -1164,7 +1167,7 @@ resource "aws_vpn_gateway_route_propagation" "public" {
}

resource "aws_vpn_gateway_route_propagation" "private" {
count = local.create_vpc && var.propagate_private_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? local.len_private_subnets : 0
count = var.propagate_private_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? local.len_private_subnets : 0

route_table_id = element(aws_route_table.private[*].id, count.index)
vpn_gateway_id = element(
Expand All @@ -1177,7 +1180,7 @@ resource "aws_vpn_gateway_route_propagation" "private" {
}

resource "aws_vpn_gateway_route_propagation" "intra" {
count = local.create_vpc && var.propagate_intra_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? local.len_intra_subnets : 0
count = var.propagate_intra_route_tables_vgw && (var.enable_vpn_gateway || var.vpn_gateway_id != "") ? local.len_intra_subnets : 0

route_table_id = element(aws_route_table.intra[*].id, count.index)
vpn_gateway_id = element(
Expand Down Expand Up @@ -1207,9 +1210,9 @@ resource "aws_default_vpc" "this" {
}

resource "aws_default_security_group" "this" {
count = local.create_vpc && var.manage_default_security_group ? 1 : 0
count = var.manage_default_security_group ? 1 : 0

vpc_id = aws_vpc.this[0].id
vpc_id = local.vpc_id

dynamic "ingress" {
for_each = var.default_security_group_ingress
Expand Down Expand Up @@ -1253,7 +1256,7 @@ resource "aws_default_security_group" "this" {
################################################################################

resource "aws_default_network_acl" "this" {
count = local.create_vpc && var.manage_default_network_acl ? 1 : 0
count = var.create_vpc && var.manage_default_network_acl ? 1 : 0

default_network_acl_id = aws_vpc.this[0].default_network_acl_id

Expand Down Expand Up @@ -1306,7 +1309,7 @@ resource "aws_default_network_acl" "this" {
################################################################################

resource "aws_default_route_table" "default" {
count = local.create_vpc && var.manage_default_route_table ? 1 : 0
count = var.create_vpc && var.manage_default_route_table ? 1 : 0

default_route_table_id = aws_vpc.this[0].default_route_table_id
propagating_vgws = var.default_route_table_propagating_vgws
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
################################################################################

variable "create_vpc" {
description = "Controls if VPC should be created (it affects almost all resources)"
description = "Controls if VPC should be created"
type = bool
default = true
}

variable "vpc_id" {
description = "If create_vpc variable value is false, then you must have to provide ID of the VPC."
type = string
default = null
}

variable "name" {
description = "Name to be used on all the resources as identifier"
type = string
Expand Down