Я новичок в terraform. Моё требование - запускать несколько экземпляров в общем модуле ec2 с разными user_data.
мой файл maif.tf:
provider "aws" {
region = "${var.region}"
profile = "${var.aws_profile}" #.aws/credentials
}
variable "count" {
default = 3
}
variable "hostnames" {
default = {
"0" = "testcase_1.sh"
"1" = "testcase_2.sh"
"2" = "testcase_3.sh"
}
}
data "template_file" "user_data" {
// here we expand multiple template_files - the same number as we have instances
count = "${var.count}"
template = "wrf_testcase.sh"
vars {
// that gives us access to use count.index to do the lookup
hostname = "${lookup(var.hostnames, count.index)}"
}
}
module "ec2" {
source = "/././modules/ec2"
count = 3
user_data = "${element(data.template_file.user-data.rendered, count.index)}"
}
Мой модуль ec2:
resource "aws_instance" "application" {
count = "${var.count}"
ami = "${var.ami}"
availability_zone = "${var.availability_zone}"
ebs_optimized = "${var.ebs_optimized}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
monitoring = "${var.monitoring}"
vpc_security_group_ids = ["${var.security_group_ids}"]
subnet_id = "${var.subnet_id}"
associate_public_ip_address = "${var.associate_public_ip_address}"
iam_instance_profile = "${var.iam_instance_profile}"
user_data = "${var.user_data}"
tags = "${merge(var.tags, map("Name",
format("%s", var.instance_name)))}"
}
Ошибка: модуль "ec2": переменные числа действительны только в пределах ресурсов