Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform_labels can't be updated on google_compute_instance_template #16374

Closed
khtelus opened this issue Oct 25, 2023 · 9 comments · Fixed by GoogleCloudPlatform/magic-modules#9394

Comments

@khtelus
Copy link

khtelus commented Oct 25, 2023

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
  • Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.
  • If an issue is assigned to the 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 to hashibot, a community member has claimed the issue already.

Terraform Version

Terraform v1.5.2
on linux_amd64

Provider version 5.3.0

Affected Resource(s)

  • google_compute_instance_template

Terraform Configuration Files

 resource "google_compute_instance_template" "default" {
   project              = var.project_id
   name_prefix          = "my-host-template-"
   machine_type         = var.instance_template.machine_type
   region               = var.region
   can_ip_forward       = false
   tags                 = var.tags

   disk {
     boot         = true
     source_image = data.google_compute_image.default.self_link
     disk_type    = "pd-balanced"
     disk_size_gb = data.google_compute_image.default.disk_size_gb
   }

   network_interface {
     subnetwork         = var.subnet
     subnetwork_project = var.vpc_host_project == null ? var.project_id : var.vpc_host_project
   }

   service_account {
     email  = var.instance_template.service_account_email
     scopes = ["cloud-platform"]
   }

   metadata = {
     enable-oslogin  = "TRUE"
     enable-osconfig = "TRUE"
   }

   lifecycle {
     create_before_destroy = true
   }

   labels = var.labels
 }

Debug Output

Panic Output

Expected Behavior

With create_before_destroy set to true as per the configuration a new template should be created on update (in this case to terraform_labels) and then the deposed object deleted.

Actual Behavior

Errors out with Error: doesn't support update

Step #1 - "terraform-apply":   # module.my_hosts.google_compute_instance_template.default will be updated in-place
Step #1 - "terraform-apply":   ~ resource "google_compute_instance_template" "default" {
Step #1 - "terraform-apply":         id                   = "projects/my-project/global/instanceTemplates/my-host-template-20230320160805321300000001"
Step #1 - "terraform-apply":         name                 = "my-host-template-20230320160805321300000001"
Step #1 - "terraform-apply":         tags                 = [
Step #1 - "terraform-apply":             "tag-a",
Step #1 - "terraform-apply":             "tag-b",
Step #1 - "terraform-apply":         ]
Step #1 - "terraform-apply":       ~ terraform_labels     = {
Step #1 - "terraform-apply":           + "applicationgroup"   = "appgroup"
Step #1 - "terraform-apply":           + "contact"            = "admins_at_domain_dot_com"
Step #1 - "terraform-apply":           + "costcenter"         = "1122334455"
Step #1 - "terraform-apply":           + "dataclassification" = "tbd"
Step #1 - "terraform-apply":           + "env"                = "np"
Step #1 - "terraform-apply":         }
Step #1 - "terraform-apply":         # (12 unchanged attributes hidden)
Step #1 - "terraform-apply": 
Step #1 - "terraform-apply":         # (4 unchanged blocks hidden)
Step #1 - "terraform-apply":     }
Step #1 - "terraform-apply": 
Step #1 - "terraform-apply": Plan: 0 to add, 3 to change, 0 to destroy.
Step #1 - "terraform-apply": module.my_hosts.google_compute_instance_template.default: Modifying... [id=projects/my-project/global/instanceTemplates/my-host-template-20230320160805321300000001]
Step #1 - "terraform-apply": ╷
Step #1 - "terraform-apply": │ Error: doesn't support update
Step #1 - "terraform-apply": │ 
Step #1 - "terraform-apply": │   with module.my_hosts.google_compute_instance_template.default,
Step #1 - "terraform-apply": │   on .terraform/modules/my_hosts/main.tf line 70, in resource "google_compute_instance_template" "default":
Step #1 - "terraform-apply": │   70: resource "google_compute_instance_template" "default" {
Step #1 - "terraform-apply": │ 
Step #1 - "terraform-apply": ╵

Steps to Reproduce

  1. terraform apply

Important Factoids

References

@zli82016
Copy link
Collaborator

zli82016 commented Nov 2, 2023

Sorry for the issue. @khtelus, can you please confirm if are you trying to upgrade the provider from 4.x to 5.3.0? And also can you please provide the value of var.labels? Thanks.

@khtelus
Copy link
Author

khtelus commented Nov 2, 2023

Thanks @zli82016 the provider (and my remote state) has already been upgraded unfortunately. Had I known, would have pinned to last v4....

Value of var.labels in this case is exactly the same as terraform_labels in example above. So var.labels would be:

labels = {
  "env"                = "np",
  "contact"            = "admins_at_domain_dot_com",
  "costcenter"         = "1122334455",
  "applicationgroup"   = "appgroup",
  "dataclassification" = "tbd"
}

Thanks!

@zli82016
Copy link
Collaborator

zli82016 commented Nov 2, 2023

The workaround could be to make some other change- such as adding a new label or modifying the existing one to make the update success.

@khtelus
Copy link
Author

khtelus commented Nov 2, 2023

The workaround could be to make some other change- such as adding a new label or modifying the existing one to make the update success.

This does indeed appear to be a workaround @zli82016 - if I add a new "test" tag for example running a plan step changes the expected operation on the instance group to a replace vs. an updated in-place although would need to test this out.

@khtelus
Copy link
Author

khtelus commented Nov 3, 2023

@zli82016 I think one of the keys points here is - I don't want to change my template. Changing the template will of course in turn force re-creation of the VM instances based on this template. So adding another change (such as another label or a tag for example) to workaround this change is undesirable in my case...

@zli82016
Copy link
Collaborator

zli82016 commented Nov 8, 2023

The PR 9394 made the fix to the resource google_compute_instance_template by adding an empty update method to make the provider upgrade succeed without resource recreation.

@zli82016 zli82016 closed this as completed Nov 8, 2023
@saurabh21316
Copy link

saurabh21316 commented Nov 10, 2023

@zli82016 @khtelus

I know this issue is closed but I would appreciate if someone can please help.
terraform plan:

module.ComputeInstance.google_compute_instance.mon_abc_c will be updated in-place

~ resource "google_compute_instance" "mon_abc_c" {
id = "projects/abc/zones/northamerica-northeast1-c/instances/mon-abc-c"
name = "mon-abc-c"
tags = [
"allow-healthchecks",
"mon-abc",
]
~ terraform_labels = {
+ "allow-healthchecks" = (known after apply)
+ "mon-abc" = (known after apply)
}
# (18 unchanged attributes hidden)

    # (5 unchanged blocks hidden)
}

when run terraform apply, it doesn't throw any error and running terraform plan again it shows the same output

@zli82016
Copy link
Collaborator

Hello, @saurabh21316 , can you please provide more details how to reproduce this issue? Which provider version does it happen? Does it happen when upgrading the provider from 4.x to 5.x? Thanks.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants