Search code examples
terraformcloud-init

How can I get Terraform's 'cloudinit_config' data source to use an actual user-data script in my local directory?


Here's my cloudinit_config module in my Terraform code:

main.tf

data "cloudinit_config" "example" {
  gzip          = false
  base64_encode = true

  part {
    content_type = "text/x-shellscript"
    filename     = "/var/atlassian/application-data/jira/example.sh"
    content  = <<-EOF
      #!/bin/bash
      echo "Hello World"
    EOF
  }
}

I'm referencing the example they use in their documentation where you write the bash commands in-line in the content argument. However, I have a user-data script (userdata.sh) that's pretty long and I'd prefer to have the cloudinit_config data source just reference/run that script instead of me having to have it all in-line. How would I accomplish this?


Solution

  • You would use file for that:

    content = file("${path.module}/path/to/userdata.sh")