๐ How Import Works
Import command:
terraform import <terraform_resource_address> <aws_resource_identifier>After import:
- Terraform updates
terraform.tfstate - But *does NOT write code for you
- You must have matching resource config in
.tffiles
๐ Example โ Import IAM Role
Terraform code:
resource "aws_iam_role" "lambda_role" {
name = "OrderUpLambdaExecutionRole"
}Import:
terraform import aws_iam_role.lambda_role OrderUpLambdaExecutionRoleNow Terraform knows:
โThis existing IAM role belongs to this resource block.โ
๐ Important Rules
โ Resource MUST exist in AWS
โ Resource MUST exist as a block in Terraform
โ Import ONLY updates state, not your .tf code
โ After import: run terraform plan
๐ Workflow Summary
- Write the resource block in
.tf - Run
terraform import - Run
terraform plan - Fix any differences
- Run
terraform apply