From 70d266b4a358b615392ec82d1874ca5546a652ca Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Fri, 7 Oct 2016 01:15:47 +0200 Subject: [PATCH 1/9] added extra cloud config vars --- ecs-cluster/main.tf | 27 ++++++++++++++++++++++- main.tf | 52 ++++++++++++++++++++++++++++----------------- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index ca6267d0..edde619c 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -114,6 +114,16 @@ variable "docker_auth_data" { default = "" } +variable "extra_cloud_config_type" { + description = "Extra cloud config type" + default = "text/x-shellscript" +} + +variable "extra_cloud_config_content" { + description = "Extra cloud config content" + default = "" +} + resource "aws_security_group" "cluster" { name = "${var.name}-ecs-cluster" vpc_id = "${var.vpc_id}" @@ -151,7 +161,7 @@ resource "aws_ecs_cluster" "main" { } } -resource "template_file" "cloud_config" { +data "template_file" "ecs_cloud_config" { template = "${file("${path.module}/files/cloud-config.yml.tpl")}" vars { @@ -167,6 +177,21 @@ resource "template_file" "cloud_config" { } } +data "template_cloudinit_config" "cloud_config" { + gzip = true + base64_encode = true + + part { + content_type = "text/part-handler" + content = "${data.template_file.ecs_cloud_config.rendered}" + } + + part { + content_type = "${var.extra_cloud_config_type}" + content = "${var.extra_cloud_config_content}" + } +} + resource "aws_launch_configuration" "main" { name_prefix = "${format("%s-", var.name)}" diff --git a/main.tf b/main.tf index 321ed91b..4548b29d 100644 --- a/main.tf +++ b/main.tf @@ -129,6 +129,16 @@ variable "ecs_ami" { default = "" } +variable "extra_cloud_config_type" { + description = "Extra cloud config type" + default = "text/x-shellscript" +} + +variable "extra_cloud_config_content" { + description = "Extra cloud config content" + default = "" +} + module "defaults" { source = "./defaults" region = "${var.region}" @@ -184,26 +194,28 @@ module "iam_role" { } module "ecs_cluster" { - source = "./ecs-cluster" - name = "${coalesce(var.ecs_cluster_name, var.name)}" - environment = "${var.environment}" - vpc_id = "${module.vpc.id}" - image_id = "${coalesce(var.ecs_ami, module.defaults.ecs_ami)}" - subnet_ids = "${module.vpc.internal_subnets}" - key_name = "${var.key_name}" - instance_type = "${var.ecs_instance_type}" - instance_ebs_optimized = "${var.ecs_instance_ebs_optimized}" - iam_instance_profile = "${module.iam_role.profile}" - min_size = "${var.ecs_min_size}" - max_size = "${var.ecs_max_size}" - desired_capacity = "${var.ecs_desired_capacity}" - region = "${var.region}" - availability_zones = "${module.vpc.availability_zones}" - root_volume_size = "${var.ecs_root_volume_size}" - docker_volume_size = "${var.ecs_docker_volume_size}" - docker_auth_type = "${var.ecs_docker_auth_type}" - docker_auth_data = "${var.ecs_docker_auth_data}" - security_groups = "${coalesce(var.ecs_security_groups, format("%s,%s,%s", module.security_groups.internal_ssh, module.security_groups.internal_elb, module.security_groups.external_elb))}" + source = "./ecs-cluster" + name = "${coalesce(var.ecs_cluster_name, var.name)}" + environment = "${var.environment}" + vpc_id = "${module.vpc.id}" + image_id = "${coalesce(var.ecs_ami, module.defaults.ecs_ami)}" + subnet_ids = "${module.vpc.internal_subnets}" + key_name = "${var.key_name}" + instance_type = "${var.ecs_instance_type}" + instance_ebs_optimized = "${var.ecs_instance_ebs_optimized}" + iam_instance_profile = "${module.iam_role.profile}" + min_size = "${var.ecs_min_size}" + max_size = "${var.ecs_max_size}" + desired_capacity = "${var.ecs_desired_capacity}" + region = "${var.region}" + availability_zones = "${module.vpc.availability_zones}" + root_volume_size = "${var.ecs_root_volume_size}" + docker_volume_size = "${var.ecs_docker_volume_size}" + docker_auth_type = "${var.ecs_docker_auth_type}" + docker_auth_data = "${var.ecs_docker_auth_data}" + security_groups = "${coalesce(var.ecs_security_groups, format("%s,%s,%s", module.security_groups.internal_ssh, module.security_groups.internal_elb, module.security_groups.external_elb))}" + extra_cloud_config_type = "${var.extra_cloud_config_type}" + extra_cloud_config_content = "${var.extra_cloud_config_content}" } module "s3_logs" { From fd4913ee010e49291014f7aaf18c28a4ee9cc96f Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Fri, 7 Oct 2016 01:20:16 +0200 Subject: [PATCH 2/9] mistyping patch --- ecs-cluster/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index edde619c..be32cb01 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -201,7 +201,7 @@ resource "aws_launch_configuration" "main" { iam_instance_profile = "${var.iam_instance_profile}" key_name = "${var.key_name}" security_groups = ["${aws_security_group.cluster.id}"] - user_data = "${template_file.cloud_config.rendered}" + user_data = "${template_cloudinit_config.cloud_config.rendered}" associate_public_ip_address = "${var.associate_public_ip_address}" # root From 243aac66df65cea6388b4646f6c9fe50cb1a9070 Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Fri, 7 Oct 2016 01:22:20 +0200 Subject: [PATCH 3/9] patch mistyping 2 --- ecs-cluster/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index be32cb01..f5fc26d3 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -201,7 +201,7 @@ resource "aws_launch_configuration" "main" { iam_instance_profile = "${var.iam_instance_profile}" key_name = "${var.key_name}" security_groups = ["${aws_security_group.cluster.id}"] - user_data = "${template_cloudinit_config.cloud_config.rendered}" + user_data = "${data.template_cloudinit_config.cloud_config.rendered}" associate_public_ip_address = "${var.associate_public_ip_address}" # root From 1cb72bb781d6d489cef8688bc9c83b2fffde32a0 Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Fri, 7 Oct 2016 11:07:59 +0200 Subject: [PATCH 4/9] corrected typo --- ecs-cluster/main.tf | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index f5fc26d3..2103f27b 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -161,7 +161,7 @@ resource "aws_ecs_cluster" "main" { } } -data "template_file" "ecs_cloud_config" { +resource "template_file" "ecs_cloud_config" { template = "${file("${path.module}/files/cloud-config.yml.tpl")}" vars { @@ -177,19 +177,23 @@ data "template_file" "ecs_cloud_config" { } } -data "template_cloudinit_config" "cloud_config" { +resource "template_cloudinit_config" "cloud_config" { gzip = true base64_encode = true part { content_type = "text/part-handler" - content = "${data.template_file.ecs_cloud_config.rendered}" + content = "${template_file.ecs_cloud_config.rendered}" } part { content_type = "${var.extra_cloud_config_type}" content = "${var.extra_cloud_config_content}" } + + lifecycle { + create_before_destroy = true + } } resource "aws_launch_configuration" "main" { @@ -201,7 +205,7 @@ resource "aws_launch_configuration" "main" { iam_instance_profile = "${var.iam_instance_profile}" key_name = "${var.key_name}" security_groups = ["${aws_security_group.cluster.id}"] - user_data = "${data.template_cloudinit_config.cloud_config.rendered}" + user_data = "${template_cloudinit_config.cloud_config.rendered}" associate_public_ip_address = "${var.associate_public_ip_address}" # root From a620f89f715bd24332fdccf2961e9137a0b6e52e Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Fri, 7 Oct 2016 11:12:03 +0200 Subject: [PATCH 5/9] changed resource to data --- ecs-cluster/main.tf | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index 2103f27b..514e573c 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -161,7 +161,7 @@ resource "aws_ecs_cluster" "main" { } } -resource "template_file" "ecs_cloud_config" { +data "template_file" "ecs_cloud_config" { template = "${file("${path.module}/files/cloud-config.yml.tpl")}" vars { @@ -171,29 +171,21 @@ resource "template_file" "ecs_cloud_config" { docker_auth_type = "${var.docker_auth_type}" docker_auth_data = "${var.docker_auth_data}" } - - lifecycle { - create_before_destroy = true - } } -resource "template_cloudinit_config" "cloud_config" { +data "template_cloudinit_config" "cloud_config" { gzip = true base64_encode = true part { content_type = "text/part-handler" - content = "${template_file.ecs_cloud_config.rendered}" + content = "${data.template_file.ecs_cloud_config.rendered}" } part { content_type = "${var.extra_cloud_config_type}" content = "${var.extra_cloud_config_content}" } - - lifecycle { - create_before_destroy = true - } } resource "aws_launch_configuration" "main" { @@ -205,7 +197,7 @@ resource "aws_launch_configuration" "main" { iam_instance_profile = "${var.iam_instance_profile}" key_name = "${var.key_name}" security_groups = ["${aws_security_group.cluster.id}"] - user_data = "${template_cloudinit_config.cloud_config.rendered}" + user_data = "${data.template_cloudinit_config.cloud_config.rendered}" associate_public_ip_address = "${var.associate_public_ip_address}" # root From b13bce2a745e5be1019d2804a94cc870236ccbaa Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Fri, 7 Oct 2016 11:35:06 +0200 Subject: [PATCH 6/9] removed gzip and base64 encode --- ecs-cluster/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index 514e573c..9f0178b6 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -174,8 +174,8 @@ data "template_file" "ecs_cloud_config" { } data "template_cloudinit_config" "cloud_config" { - gzip = true - base64_encode = true + gzip = false + base64_encode = false part { content_type = "text/part-handler" From f3162b87e708a771ed93279c1116fcc6159b904d Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Sun, 9 Oct 2016 18:59:34 +0200 Subject: [PATCH 7/9] changed types --- ecs-cluster/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index 9f0178b6..a0876cfc 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -116,7 +116,7 @@ variable "docker_auth_data" { variable "extra_cloud_config_type" { description = "Extra cloud config type" - default = "text/x-shellscript" + default = "text/cloud-config" } variable "extra_cloud_config_content" { @@ -178,7 +178,7 @@ data "template_cloudinit_config" "cloud_config" { base64_encode = false part { - content_type = "text/part-handler" + content_type = "text/cloud-config" content = "${data.template_file.ecs_cloud_config.rendered}" } From 294f393428d58e9882ee6cba5d65d7b09b8d7747 Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Sun, 9 Oct 2016 19:37:40 +0200 Subject: [PATCH 8/9] changed default extra cloud config type --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 4548b29d..2216441b 100644 --- a/main.tf +++ b/main.tf @@ -131,7 +131,7 @@ variable "ecs_ami" { variable "extra_cloud_config_type" { description = "Extra cloud config type" - default = "text/x-shellscript" + default = "text/cloud-config" } variable "extra_cloud_config_content" { From 79e92d7cd420269af25b0ef6938b849e18f1a397 Mon Sep 17 00:00:00 2001 From: Vincent Caggiari Date: Sun, 9 Oct 2016 22:47:04 +0200 Subject: [PATCH 9/9] removed terraform fmt --- main.tf | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/main.tf b/main.tf index 10eb639c..9d9951e4 100644 --- a/main.tf +++ b/main.tf @@ -194,26 +194,26 @@ module "iam_role" { } module "ecs_cluster" { - source = "./ecs-cluster" - name = "${coalesce(var.ecs_cluster_name, var.name)}" - environment = "${var.environment}" - vpc_id = "${module.vpc.id}" - image_id = "${coalesce(var.ecs_ami, module.defaults.ecs_ami)}" - subnet_ids = "${module.vpc.internal_subnets}" - key_name = "${var.key_name}" - instance_type = "${var.ecs_instance_type}" - instance_ebs_optimized = "${var.ecs_instance_ebs_optimized}" - iam_instance_profile = "${module.iam_role.profile}" - min_size = "${var.ecs_min_size}" - max_size = "${var.ecs_max_size}" - desired_capacity = "${var.ecs_desired_capacity}" - region = "${var.region}" - availability_zones = "${module.vpc.availability_zones}" - root_volume_size = "${var.ecs_root_volume_size}" - docker_volume_size = "${var.ecs_docker_volume_size}" - docker_auth_type = "${var.ecs_docker_auth_type}" - docker_auth_data = "${var.ecs_docker_auth_data}" - security_groups = "${coalesce(var.ecs_security_groups, format("%s,%s,%s", module.security_groups.internal_ssh, module.security_groups.internal_elb, module.security_groups.external_elb))}" + source = "./ecs-cluster" + name = "${coalesce(var.ecs_cluster_name, var.name)}" + environment = "${var.environment}" + vpc_id = "${module.vpc.id}" + image_id = "${coalesce(var.ecs_ami, module.defaults.ecs_ami)}" + subnet_ids = "${module.vpc.internal_subnets}" + key_name = "${var.key_name}" + instance_type = "${var.ecs_instance_type}" + instance_ebs_optimized = "${var.ecs_instance_ebs_optimized}" + iam_instance_profile = "${module.iam_role.profile}" + min_size = "${var.ecs_min_size}" + max_size = "${var.ecs_max_size}" + desired_capacity = "${var.ecs_desired_capacity}" + region = "${var.region}" + availability_zones = "${module.vpc.availability_zones}" + root_volume_size = "${var.ecs_root_volume_size}" + docker_volume_size = "${var.ecs_docker_volume_size}" + docker_auth_type = "${var.ecs_docker_auth_type}" + docker_auth_data = "${var.ecs_docker_auth_data}" + security_groups = "${coalesce(var.ecs_security_groups, format("%s,%s,%s", module.security_groups.internal_ssh, module.security_groups.internal_elb, module.security_groups.external_elb))}" extra_cloud_config_type = "${var.extra_cloud_config_type}" extra_cloud_config_content = "${var.extra_cloud_config_content}" }