Open AndreasBergmeier6176 opened 2 years ago
@AndreasBergmeier6176 can you share a sanitized debug log of your error executing?
Wondering whether someone found work-around related this.
Facing the same issue with this. Is this fixed? @c2thorn
Hello @RonLek,
It is not clear to me what is happening or how to recreate. An invalid config from the start fails during apply but still creates the template?
Did you also recreate due to the service_account
field? A sanitized log would help me debug.
@c2thorn I started with applying this terraform. My use case involves having a default service account for the VMs and I realized the example didn't have it already, so I added the service_account
field following the resource docs for the instance template post creation.
On doing a plan it says "forces replacement" but on apply it gives the above error. Consequently I had to do a terraform destroy
followed by an apply as a workaround.
I am facing the same issue too, works only after i do a terraform destroy. Expected behaviour is, for a replacement it should execute first a delete and then a create
I am also having this issue, and I have a lifecycle rule in place, I can provide you with logs at the trace level. Basically I am attempting to use the random_id with the google_compute_instance_template to generate a new template when something changes.
I would also like to note here that I am using a lifecycle meta that is not being honored properly, however that might be due to the fact that it "already exists" and I need to work around it with my random_id to adjust this a bit more.
But here are some trace logs, however this is alot so I apologize and I am aware and currently working on this. terraform.log.gz
Using name_prefix
instead of name
seems to work. This causes Terraform to generate a unique name each time the template needs to be recreated, allowing the create/delete sequence to proceed without conflict. The value can only be 36 characters long, so something like format("%s-", substr(var.template_name_base, 0, 35))
might be needed.
Couldn't recreate the issue on the original terraform config that was provided.
But this doc has an invalid configuration.
It has name
instead of name_prefix
set. The lifecycle rule create_before_destroy=true
allows for dynamic change of a used template in the MIG
without destroying every resource tied to it, but when using it with name
it will just fail with error already exists etc.
When using name_prefix
it will create a random string of numbers that will be used as the template name and allow the create before destroy action because the 2 resources have unique names.
Here is how it goes with a correct configuration
google_compute_instance_template.instance_template: Creating...
google_compute_instance_template.instance_template: Still creating... [10s elapsed]
google_compute_instance_template.instance_template: Creation complete after 12s [id=projects/iac-poc-krakow/global/instanceTemplates/l7-ilb-mig-template-20240817085222513400000001]
google_compute_region_instance_group_manager.mig: Modifying... [id=projects/iac-poc-krakow/regions/europe-west1/instanceGroupManagers/l7-ilb-mig1]
google_compute_region_instance_group_manager.mig: Still modifying... [id=projects/iac-poc-krakow/regions/europe-west1/instanceGroupManagers/l7-ilb-mig1, 10s elapsed]
google_compute_region_instance_group_manager.mig: Still modifying... [id=projects/iac-poc-krakow/regions/europe-west1/instanceGroupManagers/l7-ilb-mig1, 20s elapsed]
google_compute_region_instance_group_manager.mig: Still modifying... [id=projects/iac-poc-krakow/regions/europe-west1/instanceGroupManagers/l7-ilb-mig1, 31s elapsed]
google_compute_region_instance_group_manager.mig: Modifications complete after 33s [id=projects/iac-poc-krakow/regions/europe-west1/instanceGroupManagers/l7-ilb-mig1]
google_compute_instance_template.instance_template (deposed object 9f32e407): Destroying... [id=projects/iac-poc-krakow/global/instanceTemplates/l7-ilb-mig-template-20240817085017446300000001]
google_compute_instance_template.instance_template: Still destroying... [id=projects/iac-poc-krakow/global/instance...ig-template-20240817085017446300000001, 10s elapsed]
google_compute_instance_template.instance_template: Destruction complete after 11s
Will escalate this doc change.
@karolgorc just hit this issue and can confirm, switching from name
to name-prefix
works.
Community Note
modular-magician
user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot
, a community member has claimed the issue already.Terraform Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
Expected Behavior
For a replacement it should execute first a delete and then a create.
Actual Behavior
For an replacement, it is not executing delete but only a create which leads to:
Steps to Reproduce
terraform apply
b/308756477