Prior to terraform import, I have defined:
# instance.tf
resource "aws_instance" "appserver" {
}
Then I ran: terraform import aws_instance.appserver <instance-id>
and went smoothly, which I can see the imported ec2 resource by using terraform show. However, the mystery to me is to "transfer" this existing terraform state into the terraform config (instance.tf above) so that I can manage it as an Infrastructure as a Code (or at least that how I understood it). I added the ami and instance_type keys and their corresponding values but every time I issue terraform plan
, terraform seems to want to "replace" my existing instance.
1) Why is terraform want to replace that instance?
2) How can I "transfer" the instance's terraform state into the config? (is this possible?)
3) For you guys seasoned veterans, how were you guys able to manage an existing aws infrastructure in terraform?