Run multiple userdata scripts on EC2 instance | AWS

I have multiple powershell scripts which i need to run in ec2 userdata.

data “template_file” “userdata” {
template = file(“userdata.ps1”)
}
data “template_file” “userdata1” {
template = file(“userdata1.ps1”)
}
data “template_cloudinit_config” “cloudinit-example” {
gzip = false
base64_encode = false
part {
filename = “userdata.ps1”
content_type = “text/cloud-config”
content = data.template_file.userdata.rendered
}
part {
filename = “userdata1.ps1”
content_type = “text/cloud-config”
content = data.template_file.userdata1.rendered
}
}
resource “aws_instance” “ec2” {
ami = “ami-0e484c84e6d59f3a3”
instance_type = “t2.medium”
key_name = “cp-dev-GA”
iam_instance_profile = “admin-access-test”
user_data = data.template_cloudinit_config.cloudinit-example.rendered
}

none of the powershell scripts gets executed. Anything i am missing here

did you find answer to this question?

you could try to use something like

provisioner "file" {
    source = "userdata.ps1"
    destination = "c:\\userdata.ps1"
  }
provisioner "remote-exec" {
    inline = [
      "powershell c:\\userdata.ps1",
      
    ]
    on_failure = "continue"
  }

provisioner “file” will copy the file to your windows instance and remote-exec will execute it on the instance. Hope that helps.

You can run multiple scripts using the join function.

user_data = join(“\n”, [data.template_file.userdata.rendered, data.template_file.userdata1.rendered])