I am fairly new to terraform. I am trying to create number of ec2 instances and want to run bootstrap script once instance is ready, and in bootstrap script I need to pass private ips of instance created ( part of terraform script). After so much of googling I came to know that I have to use terraform_file but, not able to use it correctly. Terraform version: 0.11.13
/* Security group for the instances */ resource "aws_security_group" "test-reporting-sg" { name = "${var.environment}-test-reporting-sg" vpc_id = "${var.vpc_id}" } data "template_file" "init" { count = "${var.instance_count}" template = "${file("${path.module}/wrapperscript.sh")}" vars = { ip_addresses= "${aws_instance.dev-testreporting.*.private_ip}" } } resource "aws_instance" "dev-testreporting" { count = "${var.instance_count}" ami="${var.ami_id}" instance_type ="${var.instance_type}" key_name ="${var.key_name}" security_groups = [ "${aws_security_group.test-reporting-sg.id}" ] subnet_id = "${var.subnet_ids}" user_data = "${data.template_file.init.*.rendered.[count.index]}" }
Thanks
http://169.254.169.254/latest/dynamic/instance-identity/document
to get the private IP per instance with the shell scripts at runtime ? – error404consul_address
in your userdata template then? Can you post the templated script as well? Or create an minimal reproducible example with it in please? I'm assuming you want to create n instances and have the user data on those instances have the IP addresses of all n instances and not just their own? – ydaetskcoR