Reputation: 135
provider "aws" {
region = "us-east-1"
access_key = "My access key"
secret_key = "My secret key"
}
resource "aws_eip" "lb" {
instance = aws_instance.myweb-server-instance.id
vpc = true
}
resource "aws_instance" "myweb-server-instance" {
ami = "ami-085925f297f89fce1"
instance_type = "t2.micro"
availability_zone = "us-east-1a"
}
The resources that were imported are shown below:
c:\terraform> terraform import aws_eip.lb
eipalloc-0ce64f24cdabcda76
aws_eip.lb: Importing from ID "eipalloc-0ce64f24cdabcda76"...
aws_eip.lb: Import prepared!
Prepared aws_eip for import
aws_eip.lb: Refreshing state... [id=eipalloc-0ce64f24cdabcda76]
Import successful!
These resources are now in
your Terraform state and will henceforth be managed by
Terraform.
But if I copy the above code and import statement in Azure Devops pipeline and run I am getting the following error:
Error: resource address "aws_eip.lb" does not exist in the configuration. Before importing this resource, please create its configuration in the root module.
Please let me know what I am missing here. Thanks.
Upvotes: 3
Views: 10299
Reputation: 71
When working with Terraform Cloud, be sure to pull the latest code from your version control to your local so that terraform
CLI can reconcile your latest Terraform config with the remote state file.
I ran into this trying to import state between two different repos controlling the same resource.
Upvotes: 0
Reputation: 135
I just noticed my config file(elastic_ip) is not having .tf extension and terraform was not reading my config file. After adding the .tf (elastic.tf) extension now the import is working in Azure Devops pipeline.
Upvotes: 1