Skip to content

Commit

Permalink
First
Browse files Browse the repository at this point in the history
  • Loading branch information
pgale61git committed Jul 6, 2020
1 parent 9d9dee1 commit 3858b87
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# terraform-aws-scalr_dynamic_vpc_dns
# scalr_dynamic_vpc_dns module

Manages a VPC and dynamically created subnets in AWS.

1. VPC has DNS enabled
2. Subnets created dynamically based on max_subnets setting with VPC CIDR broken up evenly into CIDRs for the subnet.
3. Optional to make the subnets public
38 changes: 38 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# scalr-vpc-dns
#
# Manages a DNS enabled VPC with subnets in every AZ of the region

resource "aws_vpc" "scalr_vpc_dns" {
cidr_block = var.cidr
enable_dns_support = true
enable_dns_hostnames = true

tags = {
Name = "${var.prefix}-scalr-vpc"
}
}

data "aws_availability_zones" "azs" {
state = "available"
}

locals {
subnets = var.max_subnets > 0 && var.max_subnets <= length(data.aws_availability_zones.azs.zone_ids) ? var.max_subnets : length(data.aws_availability_zones.azs.zone_ids)
}

resource "aws_subnet" "scalr_subnet" {
count = local.subnets
vpc_id = aws_vpc.scalr_vpc_dns.id
availability_zone_id = element(data.aws_availability_zones.azs.zone_ids,count.index)
cidr_block = cidrsubnet(
aws_vpc.scalr_vpc_dns.cidr_block,
ceil(log(local.subnets * 2, 2)),
count.index
)
map_public_ip_on_launch = var.public

tags = {
Name = "${var.prefix}-scalr-subnet-${count.index}"
}

}
11 changes: 11 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
output subnet_ids {
value = aws_subnet.scalr_subnet.*.id
}

output subnet_cidrs {
value = aws_subnet.scalr_subnet.*.cidr_block
}

output vpc_id {
value = aws_vpc.scalr_vpc_dns.id
}
17 changes: 17 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable cidr {
description = "CIDR blockfor the VPC in format n.n.n.n/n. Subnet CIDR's will be generated to splut this range evenly across the subnets"
}

variable prefix {
description = "Prefic for resource names"
}

variable public {
description = "Indicates if public IP's should be allocated to instances on launched in the VPC"
type = bool
}

variable max_subnets {
description = "Maximum number of subnets to create. Must be <= number of AZs (-1 = all AZs)"
default = -1
}

0 comments on commit 3858b87

Please sign in to comment.