Open mildred opened 5 years ago
Hi @mildred,
Thanks for filing the issue!
While Terraform will not be able to determine what constitutes a unique identifier for a resource, I think it might be a good idea to try checking if a new instance is completely equal to its deposed instance and remove it from the state.
While Terraform will not be able to determine what constitutes a unique identifier for a resource
When the name for an auto scaling group changes, terraform knows it has to create a new resource. Can't that information be used to determine that if an identical named resource was created, it's no longer to be removed ?
Another way to fix this without having terraform knows about unique resource identifiers, would be to check during the plan phase if deposed resources are still there, and if deposed resources are detected as not existing, remove them from the state at that moment.
When the name for an auto scaling group changes, terraform knows it has to create a new resource. Can't that information be used to determine that if an identical named resource was created, it's no longer to be removed ?
Terraform does not have any way of knowing that a specific attribute must be unique between resources. The provider may have that information, but the best it can do is return an error when you attempt to create the duplicate resource.
The reason this doesn't come up often, is that if you cannot create multiple instances of a resource from the same config, you cannot use create_before_destroy
. This is why aws_autoscaling_group
has name_prefix
, which is used in a most of the samples, so that each instance receives a unique name allowing create_before_destroy
to work.
Hi,
I just had this issue where an ASG deployment failed[1] because of the requested instance type not being available. When terraform apply
is executed again[2] and the instance is available, terraform will complain as the ASG with the same name was already created.
If I delete the ASG manually (e.g. using AWS Console) and re-execute terraform[3], it will recreate-then-destroy the ASG as the ASG with that name, even though the ASG's ARN is different, is in the deposed state.
Maybe it's because terraform doesn't store deposed resource's ARN in its state, and it delete the resource by name https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_autoscaling_group.go#L979
~If I use name_prefix
for the ASG and do [2], will it generate a new name?~ EDIT: it is, as name prefix uses some kind of timestamp, so the execution will result in new names
Terraform Version
terraform 0.11.10
Terraform Configuration Files
Actual Behavior
In the following scenario, terraform is removing the auto scaling group it just created:
terraform starts and tries to create the ASG
terraform creates the launch configuration "terraform-20190215140012211400000002"
terraform creates an ASG with the name "etcd_server - terraform-20190215140012211400000002"
the ASG health check fails, and terraform fails with an error like:
the error is on the infrastructure, some changes are made to the infrastructure outside of terraform
the ASG is deleted manually
no modifications are made in terraform itself, terraform is executed again, it should work
terraform sees that the ASG "etcd_server - terraform-20190215140012211400000002" does not exists (the previous one failed too) and it creates it
terraform still remembers of the previous ASG named exactly the same and removes it
Log messages for this:
Here, terraform creates a resource and destroys it right after
Expected Behavior
Either: