title: How can I initialize an instance with cloud-init on Terraform
body: <p>I am trying to initialize AWS instances using cloud-init, I test with
  terraform code:</p>
  <pre><code>variable &quot;hostname&quot;    {}
  variable &quot;domain_name&quot; {}
  
  
  variable &quot;filename&quot; {
    default = &quot;cloud-config.cfg&quot;
  }
  
  data &quot;template_file&quot; &quot;test&quot; {
    template = &lt;&lt;EOF
  #cloud-config
  hostname: $${hostname}
  fqdn: $${fqdn}
  mounts:
    - [ ephemeral, null ]
  output:
    all: '| tee -a /var/log/cloud-init-output.log'
  EOF
  
    vars {
      hostname = &quot;${var.hostname}&quot;
      fqdn     = &quot;${format(&quot;%s.%s&quot;, var.hostname, var.domain_name)}&quot;
    }
  }
  
  data &quot;template_cloudinit_config&quot; &quot;test&quot; {
    gzip          = false
    base64_encode = false
  
    part {
      filename     = &quot;${var.filename}&quot;
      content_type = &quot;text/cloud-config&quot;
      content      = &quot;${data.template_file.test.rendered}&quot;
    }
  }
  
  
  resource &quot;aws_instance&quot; &quot;bootstrap2&quot; {
      ami = &quot;${var.aws_centos_ami}&quot;
      availability_zone = &quot;eu-west-1b&quot;
      instance_type = &quot;t2.micro&quot;
      key_name = &quot;${var.aws_key_name}&quot;
      security_groups = [&quot;${aws_security_group.bastion.id}&quot;]
      associate_public_ip_address = true
      private_ip = &quot;10.0.0.12&quot;
      source_dest_check = false
      subnet_id = &quot;${aws_subnet.eu-west-1b-public.id}&quot;
      triggers {
        template = &quot;${data.template_file.test.rendered}&quot;
      }
  
      tags {
              Name = &quot;bootstrap2&quot;
          }
  }
  </code></pre>
  <p>But it is failing the triggers inside the &quot;bootstrap&quot; resource. So how can I aprovisione this instance with the cloud-config I defined up?</p>