Skip to content

Commit

Permalink
Add toggles for private & public subnet creation
Browse files Browse the repository at this point in the history
This lets users create only private (or only public) subnets. The CIDR
range is still divided as per usual, so you can change your mind later
with minimal disruption.
  • Loading branch information
alexjurkiewicz committed Mar 14, 2021
1 parent 56a4d6d commit f7ee59e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion private.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ locals {
}

resource "aws_subnet" "private" {
count = local.enabled ? local.availability_zones_count : 0
count = local.enabled && var.create_private_subnets ? local.availability_zones_count : 0
vpc_id = join("", data.aws_vpc.default.*.id)
availability_zone = element(var.availability_zones, count.index)

Expand Down
2 changes: 1 addition & 1 deletion public.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ locals {
}

resource "aws_subnet" "public" {
count = local.enabled ? local.availability_zones_count : 0
count = local.enabled && var.create_public_subnets ? local.availability_zones_count : 0
vpc_id = join("", data.aws_vpc.default.*.id)
availability_zone = element(var.availability_zones, count.index)

Expand Down
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,15 @@ variable "root_block_device_encrypted" {
default = true
description = "Whether to encrypt the root block device"
}

variable "create_public_subnets" {
type = bool
default = true
description = "Set to false to prevent the module from creating public subnets. Some of your CIDR block will still be reserved, so you can change this later without disruption."
}

variable "create_private_subnets" {
type = bool
default = true
description = "Set to false to prevent the module from creating private subnets. Some of your CIDR block will still be reserved, so you can change this later without disruption."
}

0 comments on commit f7ee59e

Please sign in to comment.