title: How to run sudo in terraform "local-exec" block
body: <p>I have an issue where adding sudo in local exec keep running. </p>
  
  <p>So in short without the local-exec block. I'm able to create and access my EC2 instance. using ssh -vi path/to/key.pem ec2-user@ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com.</p>
  
  <p>But now as soon as I add below block; and run <code>apply</code> it keeps showing "still creating" after the password prompt. </p>
  
  <pre><code> provisioner "local-exec" {
      command = &lt;&lt;EOH
        sudo yum -y update
        sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
      EOH
    }
  </code></pre>
  
  <p>So, my question is which user is sudo user here? is it ec2-user or the user which I created initially to setup my AWS (that includes only access key id and secret access key)? </p>
  
  <p>How can I set it up, is there any documentation to refer? </p>
  
  <p>below is my main.tf</p>
  
  <pre><code>
  provider "aws" {
    region = "us-east-2"
    version = "~&gt; 1.2.0"
  }
  
  resource "aws_instance" "hello-world" {
    ami = "ami-ef92b08a"
    instance_type = "t2.micro"
  
    provisioner "local-exec" {
      command = &lt;&lt;EOH
        sudo yum -y update
        sudo yum install -y python36u python36u-libs python36u-devel python36u-pip
      EOH
    }
  
    tags {
      Name = "my-aws-terraform-hello-world"
    }
  }
  
  resource "aws_security_group" "allow-tcp" {
    name = "my-aws-terraform-hello-world"
    ingress {
      from_port = 8080
      to_port = 8080
      protocol = "tcp"
      cidr_blocks = ["0.0.0.0/0"]
    }
  }
  </code></pre>