title: How to import existing resources to terraform in a separate subdirectory?
body: <p>I have created some resources including VPC, ... in AWS using the console a long time ago and now I want to import them into Terraform. I already made a structure for my project like:</p>
  <pre><code>└── project_xxx
      ├── main.tf
      ├── modules
      │   ├── module_foo
      │   │   ├── main.tf
      │   │   ├── outputs.tf
      │   │   └── variables.tf
      │   ├── module_bar
      │   │   ├── main.tf
      │   │   ├── outputs.tf
      │   │   └── variables.tf
      │   ...
      ├── outputs.tf
      ├── provider.tf
      ├── README.md
      ├── terraform.tfvars
      ├── variables.tf
      └── versions.tf
  </code></pre>
  <p>but when I try to import resources in their modules, Terraform gives an Error and asks for creating them in root directory.
  Any suggestions?</p>
  <p>for example:
  in modules/module_foo/main.tf, I have the following codes:</p>
  <pre><code>  resource &quot;aws_vpc&quot; &quot;main&quot; {
    cidr_block       = &quot;10.0.0.0/16&quot;
    instance_tenancy = &quot;default&quot;
  
    tags = {
      Name = &quot;main&quot;
    }
  }
  </code></pre>
  <p>Then: in the root, I execute the following commands:</p>
  <pre><code>terraform init
  terraform plan # it shows one resource will be added
  terraform import aws_vpc.main vpc-xxx1234
  </code></pre>
  <p>Then I get the Error, that the resource must be created in root.</p>