title: How to run an apache server in custom vpc(non default)aws through terraform?
body: <p>I created a custom vpc in aws through terraform with 1 public subnet and 2 private subnet.Now i need to launch an instance running apache in private subnet through Terraform.My code to launch an instance in private subnet is this</p>
  
  <pre><code>resource "aws_instance" "my_apache" {
      ami = "ami-8437a5e4"
      key_name = "clust"
      subnet_id = "${aws_subnet.my_private1.id}"
      vpc_security_group_ids = ["sg-40542d3b"]
      availability_zone = "us-west-2a"
      instance_type = "t2.micro"
      tags {
        Name = "apache"
        }
        provisioner "remote-exec" {
          inline = [
            "sudo apt-get update",
            "sudo apt-get install apache2",
            "sudo service apache2 start"
          ]
        }
  }
  </code></pre>
  
  <p>The instance is launching but apache server is not running in the instance.I am getting the error like dis.</p>
  
  <pre><code>aws_instance.my_apache (remote-exec): Connecting to remote host via SSH...
  aws_instance.my_apache (remote-exec):   Host: 172.16.2.163
  aws_instance.my_apache (remote-exec):   User: root
  aws_instance.my_apache (remote-exec):   Password: false
  aws_instance.my_apache (remote-exec):   Private key: false
  aws_instance.my_apache (remote-exec):   SSH Agent: true
  aws_instance.my_apache: Still creating... (3m0s elapsed)
  ^CInterrupt received. Gracefully shutting down...
  aws_instance.my_apache: Still creating... (3m10s elapsed)
  aws_instance.my_apache (remote-exec): Connecting to remote host via SSH...
  aws_instance.my_apache (remote-exec):   Host: 172.16.2.163
  aws_instance.my_apache (remote-exec):   User: root
  aws_instance.my_apache (remote-exec):   Password: false
  aws_instance.my_apache (remote-exec):   Private key: false
  aws_instance.my_apache (remote-exec):   SSH Agent: true
  </code></pre>
  
  <p>It keeps on continuing.</p>
  
  <p>What could be the issue?.How to make apache run in that instance?</p>