Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

dependencies:
override:
- sudo curl -L# https://releases.hashicorp.com/terraform/0.6.16/terraform_0.6.16_linux_amd64.zip -o /usr/local/bin/tf.zip
- sudo curl -L# https://releases.hashicorp.com/terraform/0.7.0/terraform_0.7.0_linux_amd64.zip -o /usr/local/bin/tf.zip
- cd /usr/local/bin && sudo unzip tf.zip

test:
Expand Down
14 changes: 8 additions & 6 deletions ecs-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* name = "cdn"
* vpc_id = "vpc-id"
* image_id = "ami-id"
* subnet_ids = "1,2"
* subnet_ids = ["1" ,"2"]
* key_name = "ssh-key"
* security_groups = "1,2"
* iam_instance_profile = "id"
* region = "us-west-2"
* availability_zones = "a,b"
* availability_zones = ["a", "b"]
* instance_type = "t2.small"
* }
*
Expand All @@ -42,7 +42,8 @@ variable "image_id" {
}

variable "subnet_ids" {
description = "Comma separated list of subnet IDs"
description = "List of subnet IDs"
type = "list"
}

variable "key_name" {
Expand All @@ -62,7 +63,8 @@ variable "region" {
}

variable "availability_zones" {
description = "Comma separated list of AZs"
description = "List of AZs"
type = "list"
}

variable "instance_type" {
Expand Down Expand Up @@ -200,8 +202,8 @@ resource "aws_launch_configuration" "main" {
resource "aws_autoscaling_group" "main" {
name = "${var.name}"

availability_zones = ["${split(",", var.availability_zones)}"]
vpc_zone_identifier = ["${split(",", var.subnet_ids)}"]
availability_zones = ["${var.availability_zones}"]
vpc_zone_identifier = ["${var.subnet_ids}"]
launch_configuration = "${aws_launch_configuration.main.id}"
min_size = "${var.min_size}"
max_size = "${var.max_size}"
Expand Down
12 changes: 6 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ variable "cidr" {
}

variable "internal_subnets" {
description = "a comma-separated list of CIDRs for internal subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones"
default = "10.30.0.0/19,10.30.64.0/19,10.30.128.0/19"
description = "a list of CIDRs for internal subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones"
default = ["10.30.0.0/19" ,"10.30.64.0/19", "10.30.128.0/19"]
}

variable "external_subnets" {
description = "a comma-separated list of CIDRs for external subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones"
default = "10.30.32.0/20,10.30.96.0/20,10.30.160.0/20"
description = "a list of CIDRs for external subnets in your VPC, must be set if the cidr variable is defined, needs to have as many elements as there are availability zones"
default = ["10.30.32.0/20", "10.30.96.0/20", "10.30.160.0/20"]
}

variable "availability_zones" {
description = "a comma-separated list of availability zones, defaults to all AZ of the region, if set to something other than the defaults, both internal_subnets and external_subnets have to be defined as well"
default = "us-west-2a,us-west-2b,us-west-2c"
default = ["us-west-2a", "us-west-2b", "us-west-2c"]
}

variable "bastion_instance_type" {
Expand Down Expand Up @@ -159,7 +159,7 @@ module "bastion" {
instance_type = "${var.bastion_instance_type}"
security_groups = "${module.security_groups.external_ssh},${module.security_groups.internal_ssh}"
vpc_id = "${module.vpc.id}"
subnet_id = "${element(split(",",module.vpc.external_subnets), 0)}"
subnet_id = "${element(module.vpc.external_subnets, 0)}"
key_name = "${var.key_name}"
environment = "${var.environment}"
}
Expand Down
39 changes: 21 additions & 18 deletions vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ variable "cidr" {
}

variable "external_subnets" {
description = "Comma separated list of subnets"
description = "List of external subnets"
type = "list"
}

variable "internal_subnets" {
description = "Comma separated list of subnets"
description = "List of internal subnets"
type = "list"
}

variable "environment" {
description = "Environment tag, e.g prod"
}

variable "availability_zones" {
description = "Comma separated list of availability zones"
description = "List of availability zones"
type = "list"
}

variable "name" {
Expand Down Expand Up @@ -52,14 +55,14 @@ resource "aws_internet_gateway" "main" {
}

resource "aws_nat_gateway" "main" {
count = "${length(compact(split(",", var.internal_subnets)))}"
count = "${length(var.internal_subnets)}"
allocation_id = "${element(aws_eip.nat.*.id, count.index)}"
subnet_id = "${element(aws_subnet.external.*.id, count.index)}"
depends_on = ["aws_internet_gateway.main"]
}

resource "aws_eip" "nat" {
count = "${length(compact(split(",", var.internal_subnets)))}"
count = "${length(var.internal_subnets)}"
vpc = true
}

Expand All @@ -69,9 +72,9 @@ resource "aws_eip" "nat" {

resource "aws_subnet" "internal" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "${element(split(",", var.internal_subnets), count.index)}"
availability_zone = "${element(split(",", var.availability_zones), count.index)}"
count = "${length(compact(split(",", var.internal_subnets)))}"
cidr_block = "${element(var.internal_subnets, count.index)}"
availability_zone = "${element(var.availability_zones, count.index)}"
count = "${length(var.internal_subnets)}"

tags {
Name = "${var.name}-${format("internal-%03d", count.index+1)}"
Expand All @@ -80,9 +83,9 @@ resource "aws_subnet" "internal" {

resource "aws_subnet" "external" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "${element(split(",", var.external_subnets), count.index)}"
availability_zone = "${element(split(",", var.availability_zones), count.index)}"
count = "${length(compact(split(",", var.external_subnets)))}"
cidr_block = "${element(var.external_subnets, count.index)}"
availability_zone = "${element(var.availability_zones, count.index)}"
count = "${length(var.external_subnets)}"
map_public_ip_on_launch = true

tags {
Expand All @@ -108,7 +111,7 @@ resource "aws_route_table" "external" {
}

resource "aws_route_table" "internal" {
count = "${length(compact(split(",", var.internal_subnets)))}"
count = "${length(var.internal_subnets)}"
vpc_id = "${aws_vpc.main.id}"

route {
Expand All @@ -126,13 +129,13 @@ resource "aws_route_table" "internal" {
*/

resource "aws_route_table_association" "internal" {
count = "${length(compact(split(",", var.internal_subnets)))}"
count = "${length(var.internal_subnets)}"
subnet_id = "${element(aws_subnet.internal.*.id, count.index)}"
route_table_id = "${element(aws_route_table.internal.*.id, count.index)}"
}

resource "aws_route_table_association" "external" {
count = "${length(compact(split(",", var.external_subnets)))}"
count = "${length(var.external_subnets)}"
subnet_id = "${element(aws_subnet.external.*.id, count.index)}"
route_table_id = "${aws_route_table.external.id}"
}
Expand All @@ -148,12 +151,12 @@ output "id" {

// A comma-separated list of subnet IDs.
output "external_subnets" {
value = "${join(",", aws_subnet.external.*.id)}"
value = ["${aws_subnet.external.*.id}"]
}

// A comma-separated list of subnet IDs.
// A list of subnet IDs.
output "internal_subnets" {
value = "${join(",", aws_subnet.internal.*.id)}"
value = ["${aws_subnet.internal.*.id}"]
}

// The default VPC security group ID.
Expand All @@ -163,5 +166,5 @@ output "security_group" {

// The list of availability zones of the VPC.
output "availability_zones" {
value = "${join(",", aws_subnet.external.*.availability_zone)}"
value = ["${aws_subnet.external.*.availability_zone}"]
}