After importing an EC2 instance, every plan shows `user_data` changes or a replacement.
IntermediateTroubleshootingImport, Already Exists and State Surgery
Answer
Likely causes → The provider stores a hash/base64 of user data; your code's template renders differently (trailing newline, different variables). With user_data_replace_on_change = true this forces replacement.
Diagnose →
aws ec2 describe-instance-attribute --instance-id i-0abc123 --attribute userData \
--query 'UserData.Value' --output text | base64 -d > real.sh
diff real.sh <(terraform console <<< 'local.user_data')
Fix → Make the template output byte-identical, or ignore_changes = [user_data] for instances where user data only matters at first boot.
Prevent → For long-lived instances, keep user data minimal and push config via SSM/Ansible.
More on Import, Already Exists and State Surgery
Apply fails with `EntityAlreadyExists: Role with name app-role already exists.`Beginner`terraform apply` on a new bucket fails with `BucketAlreadyExists`. You have never created that bucket.Beginner`Error: Resource already managed by Terraform` when running `terraform import aws_s3_bucket.logs acme-logs`.Beginner`Error: Cannot import non-existent remote object` for a resource you can see in the console.Intermediate`Error: Configuration for import target does not exist` when running `terraform plan` with an `import` block.Beginner`terraform plan -generate-config-out=generated.tf` fails with `Conflicting configuration arguments` in the generated file.Intermediate