5

I've written a fair bit of Terraform and have deployed a single user-data script during boot of aws instances. I simply used the file function calling the location of the powershell script. This approach works well for single user-data scripts.

resource "aws_instance" "windows" {
     ...
     ...
     user_data  = file("./user-data/ConfigureWinRM.ps1")

Now, I want to have two scripts executed as the instances are stood up. I took a similar approach and tried the following but it appears the two scripts are not executed.

user_data = join("\n", [file("./user-data/ConfigureWinRM.ps1"), file("./user-data/admin-pass.ps1")])

I tried the template_file data source but this this also does not work.

data "template_file" "script1" {
  template = file("./user-data/ConfigureWinRM.ps1")
}

data "template_file" "script2" {
  template = file("./user-data/admin-pass.ps1")
}
user_data = join("\n", [data.template_file.script1.rendered, data.template_file.script2.rendered]) 

I also tried the template_cloud_init data source but it did not work.

data "template_cloudinit_config" "user-data" { 
  part { 
    filename = "ConfigureWinRM.ps1" 
    content  = file("./user-data/ConfigureWinRM.ps1") 
  } 
  part { 
    filename = "admin-pass.ps1" 
    content  = file("./user-data/admin-pass.ps1") 
  } 
} 
user_data = data.template_cloudinit_config.user-data.rendered 

Any suggestions would be most helpful. Thanks!

0

1 Answer 1

1

I think you're missing the content_type in the part section on template_cloudinit_config

sample

data "template_cloudinit_config" "user-data" { 
  part { 
    content_type = "text/x-shellscript"
    content  = file("./user-data/ConfigureWinRM.ps1") 
  } 
  part { 
    content_type = "text/x-shellscript" 
    content  = file("./user-data/admin-pass.ps1") 
  } 
} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.