title: Is there a way to confirm user_data ran successfully with Terraform for EC2?
body: <p>I'm wondering if it's possible to know when the script in user data executes completely?</p>
  <pre><code>data &quot;template_file&quot; &quot;script&quot; {
    template = file(&quot;${path.module}/installing.sh&quot;)
  }
  
  data &quot;template_cloudinit_config&quot; &quot;config&quot; {
    gzip          = false
    base64_encode = false
  
    # Main cloud-config configuration file.
    part {
      filename     = &quot;install.sh&quot;
      content      = &quot;${data.template_file.script.rendered}&quot;
    }
  }
  
  resource &quot;aws_instance&quot; &quot;web&quot; {
    ami           = &quot;ami-04e7b4117bb0488e4&quot;
    instance_type = &quot;t2.micro&quot;
    key_name = &quot;KEY&quot;
    vpc_security_group_ids = [aws_default_security_group.default.id]
    subnet_id = aws_default_subnet.default_az1.id
    associate_public_ip_address = true
    iam_instance_profile = &quot;Role_S3&quot;
    user_data = data.template_cloudinit_config.config.rendered
    tags = {
      Name = &quot;Terraform-Ansible&quot;
    }
  }
  </code></pre>
  <p>And in the content of the script I have this.
  It tells me Terraform successfully apply the changes, but the script is still running, is there a way I can monitor that?</p>
  <pre><code>#!/usr/bin/env bash
  exec &gt; &gt;(tee /var/log/user-data.log|logger -t user-data -s 2&gt;/dev/console) 2&gt;&amp;1
  echo BEGIN
  sudo apt update
  sudo apt upgrade -y
  sudo apt install -y unzip
  echo END
  </code></pre>