Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Update an instance template with terraform, will I lose all instance data?

I have a stateful MIG (Managed Instance Group) created using Terraform. I'm planning to update some labels and network tags in Terraform and then apply these changes. However, the Terraform plan indicates that the instance template will be replaced. My concern is: Will I lose all my data and application configurations when the instance template is recreated, or will the disks be detached, the instances updated, and then reattached with all my data and application configurations intact?

2 1 374
1 REPLY 1

Hello @M4theus-r0ss1  ,Welcome on Google Cloud Community.

Depends on your configuration. If you have in your TF code code with delete_rule = NEVER, that will detach disk without deletion, so all data stored at that disk will be kept. However, if you attached local SSD disk to your VMs, each restart will wipe data on disks. 

  stateful_disk {
    device_name = google_compute_disk.default.disk_id
    delete_rule = "NEVER"
  }

 Also, your changes will not be applied to VMs automatically if you didn't set update_policy block. If you don't have such config, in fact template will be updated, but you will be forced to either replace or restart your VMs, to apply changes.

  update_policy {
    type = "PROACTIVE"
    minimal_action                 = "RESTART"
  }

 --
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost