Terraform template_cloudinit_config multiple part execution order is wrong

829 Views Asked by At

I am using the terraform to build my ec2-instances as part of instance bootstrap, added cloud-init config to run multiple userdata scripts. but the content_type = "text/x-shellscript" always executed first. I verified the cat /var/log/cloud-init-output.log file. it shows the shell script is invoked first. How do I config the shell script to run at last?

data "template_cloudinit_config" "myapp_cloudinit_config" {
  gzip = false
  base64_encode = false

  # Main cloud-config configuration file.
  part {
    content_type = "text/cloud-config" 
    content = "${data.template_file.base_bootstrap_file.rendered}" 
    merge_type = "list(append)+dict(recurse_array)+str()"
  }
  part {
    content_type = "text/cloud-config"
    content = "${module.template_file_appsec_init.appsec_user_data_rendered}"
    merge_type = "list(append)+dict(recurse_array)+str()"
  }

  part {
    content_type = "text/x-shellscript"
    content = "${module.template_file_beat_init.beat_user_data_rendered}"
  }
}

Shell script looks like below

module " template_file_beat_init" {
  source = "url" #the source url contains the zip file which includes the below shell script
}
#!/bin/sh

deploy_the_app() {
//invoke ansible playbook execution
}
deploy_the_app

Cloud provider: AWS OS : RHEL 8.3 cloud-init --version: /usr/bin/cloud-init 19.4 Terraform v0.11.8

0

There are 0 best solutions below