Skip to content

Commit

Permalink
Merge pull request #87 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 8.6.0 - Configurable VPC CIDR blocks
  • Loading branch information
forevermatt authored Aug 15, 2023
2 parents 76f7f54 + ad24830 commit 6d0151d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
5 changes: 4 additions & 1 deletion aws/vpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ be useful.

- `enable_dns_hostnames` - default `false`
- `create_nat_gateway` - default `true`
- `private_subnet_cidr_blocks`
- `public_subnet_cidr_blocks`
- `vpc_cidr_block`

## Outputs

- `vpc_default_sg_id` - The VPC default security group ID
- `public_subnet_ids` - A list of the public subnet IDs
- `public_subnet_cidr_blocks` - A list of public subnet CIDR blocks, ex: `["10.0.10.0/24","10.0.12.0/24"]`
- `public_subnet_cidr_blocks` - A list of public subnet CIDR blocks, ex: `["10.0.10.0/24","10.0.20.0/24"]`
- `private_subnet_ids` - A list of the private subnet IDs
- `private_subnet_cidr_blocks` - A list of private subnet CIDR blocks, ex: `["10.0.11.0/24","10.0.22.0/24"]`
- `db_subnet_group_name` - The name of the DB subnet group
Expand Down
6 changes: 3 additions & 3 deletions aws/vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Create VPC using app name and env to name it
*/
resource "aws_vpc" "vpc" {
cidr_block = "10.0.0.0/16"
cidr_block = var.vpc_cidr_block
enable_dns_hostnames = var.enable_dns_hostnames

tags = {
Expand All @@ -27,7 +27,7 @@ resource "aws_subnet" "public_subnet" {
count = length(var.aws_zones)
vpc_id = aws_vpc.vpc.id
availability_zone = element(var.aws_zones, count.index)
cidr_block = "10.0.${(count.index + 1) * 10}.0/24"
cidr_block = element(var.public_subnet_cidr_blocks, count.index)

tags = {
Name = "public-${element(var.aws_zones, count.index)}"
Expand All @@ -40,7 +40,7 @@ resource "aws_subnet" "private_subnet" {
count = length(var.aws_zones)
vpc_id = aws_vpc.vpc.id
availability_zone = element(var.aws_zones, count.index)
cidr_block = "10.0.${(count.index + 1) * 11}.0/24"
cidr_block = element(var.private_subnet_cidr_blocks, count.index)

tags = {
Name = "private-${element(var.aws_zones, count.index)}"
Expand Down
18 changes: 18 additions & 0 deletions aws/vpc/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ variable "create_nat_gateway" {
type = bool
default = true
}

variable "private_subnet_cidr_blocks" {
description = "The CIDR blocks for the private subnets (one per AZ, in order). There must be at least as many private CIDRs as AZs, and they must not overlap the public CIDRs."
type = list(string)
default = ["10.0.11.0/24", "10.0.22.0/24", "10.0.33.0/24", "10.0.44.0/24"]
}

variable "public_subnet_cidr_blocks" {
description = "The CIDR blocks for the public subnets (one per AZ, in order). There must be at least as many public CIDRs as AZs, and they must not overlap the private CIDRs."
type = list(string)
default = ["10.0.10.0/24", "10.0.20.0/24", "10.0.30.0/24", "10.0.40.0/24"]
}

variable "vpc_cidr_block" {
description = "The block of IP addresses (as a CIDR) the VPC should use"
type = string
default = "10.0.0.0/16"
}

0 comments on commit 6d0151d

Please sign in to comment.