GCP compute instance - terraform delete protection flag with disk resizing

Viewed 173

we have recently come across an issue where an engineer has made a disk change in the console to a boot disk and it has caused our cloudbuild trigger to fail as it detects the size difference between what it is in code and in console (100GB vs 128GB) The issue we have is in terraform we have deletion protection set to true so it wont allow us to make any changes until this is set to false.

However if i change this to false and push this change it will delete and recreate the boot disk as it will see the 100gb in terraform being less than the 130gb in console.

Is it possible to increase the disk size and disable the delete protection in the same code push?

2 Answers

For reference no you cannot make any amendment to an instance at the same time as the flag change if already enabled. Terraform looks at that status first and if enabled will ignore all other changes.

I'd do a terraform apply -refresh-only first in order to sync the size of the manual change with terraform state and then disable the delete protection set on the resource.

Related