I am trying to create multiple ec2
instances based on a configuration using terraform.
resource "aws_instance" "collatz_instance" {
for_each = { for config in var.instance_configuration : config.name => config }
ami = each.value.ami
key_name = local.prefix
instance_type = "m6g.xlarge"
vpc_security_group_ids = [aws_security_group.security_group.id]
subnet_id = aws_subnet.public_subnet.id
user_data = file("${each.value.script_path}")
tags = merge(
{ "Name" = format("%s", "${each.value.name}-net-ec2-public") },
local.tags,
)
}
Here the user_data provision does not seem to be working
instance_configuration = [
{
ami: "ami-XXXXXX",
name: "parithiban"
script_path: "scripts/parithiban.sh"
},
{
ami: "ami-XXXXXXX",
name: "parithiban-another"
script_path: "scripts/parithiban_one.sh"
}
]
Name
and ami
is working perfectly only user_data
is not working. Once the instance is launched i checked in Instance settings/Edit user data. I can see the same script there. I couldn’t find any errors too. I can see the same txt file in /var/lib/cloud/instance/
.
My terrraform version is v1.0.10