forked from scalr-eap/terraform-aws-scalr_dynamic_vpc_dns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d9dee1
commit 3858b87
Showing
4 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |