title: How to launch ECs in an existing VPC using Terraform
body: <p>I need to create several new EC2, RDS, etc.using Terraform, in an existing AWS VPC. and the existing subnet, security group, iam, etc. they are not created by Terraform. it is created manually.</p>
  
  <p>I heard the right way is to use terraform import (it is correct?). To test how terraform import works, I first tested how to import an existing EC2 in stead of an existing VPC, Because I do not want to accidentally change anything In an exist VPC. </p>
  
  <p>before running </p>
  
  <pre><code>terraform import aws_instance.example i-XXXXXXXXXX
  </code></pre>
  
  <p>It looks like I need to create a very detailed EC2 resource in my ec2.tf file, such as:</p>
  
  <pre><code>resource "aws_instance" "example" {
    iam_instance_profile = XXXXXXXXXX
    instance_type = XXXXXXX
    ami = XXXXXXX
    tags {
      Name = XXXXX
      Department = XXXX
      ....
    }
  } 
  </code></pre>
  
  <p>if I just write:</p>
  
  <pre><code>resource "aws_instance" "example" {
  }
  </code></pre>
  
  <p>it showed I missed ami and instance type, </p>
  
  <p>if I write:</p>
  
  <pre><code>resource "aws_instance" "example" {
    instance_type = XXXXXXX
    ami = XXXXXXX
  }
  </code></pre>
  
  <p>then running "terraform apply"
  will change tags of my existing EC2 to nothing, change iam profile to nothing.</p>
  
  <p>I have not tried how to import existing vpc, subnet, security group yet. I am afraid if I try, I have to put a lot of information of the existing vpc, subnet, security group, etc. my system is complex. </p>
  
  <p>is it expected that I need to indicate so many details in my terraform code? isn't there a way so that I just simply indicate the id of existing stuff like vpc's id, and my new stuff will be created based on the existing id? sth. like:</p>
  
  <pre><code>data "aws_subnet" "public" {
      id = XXXXXXX
  }
  
  resource "aws_instance" "example" {
    instance_type = "t2.micro"
    ami = "${var.master_ami}"
    ......
    subnet_id = "${aws_subnet.public.id}"
  }
  </code></pre>