diff --git a/circle.yml b/circle.yml index 04eab8e2..b412f501 100644 --- a/circle.yml +++ b/circle.yml @@ -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: diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index ca6267d0..23176c3e 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -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" * } * @@ -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" { @@ -62,7 +63,8 @@ variable "region" { } variable "availability_zones" { - description = "Comma separated list of AZs" + description = "List of AZs" + type = "list" } variable "instance_type" { @@ -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}" diff --git a/main.tf b/main.tf index 38588911..afd576c3 100644 --- a/main.tf +++ b/main.tf @@ -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" { @@ -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}" } diff --git a/vpc/main.tf b/vpc/main.tf index 12557126..e058ae9c 100644 --- a/vpc/main.tf +++ b/vpc/main.tf @@ -3,11 +3,13 @@ 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" { @@ -15,7 +17,8 @@ variable "environment" { } variable "availability_zones" { - description = "Comma separated list of availability zones" + description = "List of availability zones" + type = "list" } variable "name" { @@ -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 } @@ -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)}" @@ -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 { @@ -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 { @@ -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}" } @@ -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. @@ -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}"] }