diff --git a/ecs-cluster/main.tf b/ecs-cluster/main.tf index b29f1a51..4fae8565 100644 --- a/ecs-cluster/main.tf +++ b/ecs-cluster/main.tf @@ -116,6 +116,16 @@ variable "docker_auth_data" { default = "" } +variable "extra_cloud_config_type" { + description = "Extra cloud config type" + default = "text/cloud-config" +} + +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}" @@ -153,7 +163,7 @@ resource "aws_ecs_cluster" "main" { } } -data "template_file" "cloud_config" { +data "template_file" "ecs_cloud_config" { template = "${file("${path.module}/files/cloud-config.yml.tpl")}" vars { @@ -165,6 +175,21 @@ data "template_file" "cloud_config" { } } +data "template_cloudinit_config" "cloud_config" { + gzip = false + base64_encode = false + + part { + content_type = "text/cloud-config" + 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)}" @@ -174,7 +199,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_file.cloud_config.rendered}" + user_data = "${data.template_cloudinit_config.cloud_config.rendered}" associate_public_ip_address = "${var.associate_public_ip_address}" # root diff --git a/main.tf b/main.tf index 0ec714f8..9d9951e4 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/cloud-config" +} + +variable "extra_cloud_config_content" { + description = "Extra cloud config content" + default = "" +} + module "defaults" { source = "./defaults" region = "${var.region}" @@ -204,6 +214,8 @@ module "ecs_cluster" { 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" {