gridscale / terraform-provider-gridscale

Terraform gridscale provider
https://registry.terraform.io/providers/gridscale/gridscale/latest/docs
Mozilla Public License 2.0
12 stars 11 forks source link

Girdscale renamed their Ubuntu 20.04 template which causes either TF errors or replacement of all storages. #154

Closed envy closed 3 years ago

envy commented 3 years ago

We have been using the terraform provider for some months now but noticed today that it errors with:

Error: read template (Ubuntu 20.04 LTS (Focal Fossa)) datasource - error: Template Ubuntu 20.04 LTS (Focal Fossa) not found

Alright, seems like you renamend your template to Ubuntu 20.04. So I changed it in my config.

And now TF wants to replace all my storages using that template because apparently the template UUID changed.

This is a provider issue in my eyes, because:

After the storage has been created, the reference to the template should be irrelevant as the storage will not match the template anyway afterwards, so why is it relevant and kept around?

The only solution I saw was to replace the old template UUID with the new one in my state by changing the state JSON by hand so that it thinks all storages were created with the new template.

Terraform Version

Doesn't matter

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

resource "gridscale_storage" "this" {
  name = "somename"
  capacity = 20
  storage_type = "storage"
  template {
    template_uuid = data.gridscale_template.ubuntu2004.id
    sshkeys = [
      var.sshkey
    ]
  }
}

data "gridscale_template" "ubuntu2004" {
  name = "Ubuntu 20.04 LTS (Focal Fossa)"
}

Expected Behavior

Changing the template should not affect existing storages. They already diverted from the template the first time they booted.

Actual Behavior

TF wanted to replace all storages whose template changed.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Travel back in time and create a server using a template that existed then but does not exist now.
  2. Alternatively, ask someone at Gridscale to create a temporary template you can use.
  3. Wait for the template to be deleted
  4. Try to do something else in TF and see it fail at Gridscale
  5. Change the template name to the new name
  6. terraform plan will now show you that it wants to replace the storage because the template has changed.
nvthongswansea commented 3 years ago

@envy, thanks for reporting the issue. Actually, I think the issue presents since we update our Ubuntu 20.04 template. The update happened on our backend and caused the change of the Ubuntu 20.04 template UUID. To prevent this, you'd better use ignore_changes

resource "gridscale_storage" "this" {
  name = "somename"
  capacity = 20
  storage_type = "storage"
  template {
    template_uuid = data.gridscale_template.ubuntu2004.id
    sshkeys = [
      var.sshkey
    ]
  }
  lifecycle {
    ignore_changes = [
      template.0.template_uuid,
    ]
  }
}

@bkircher what do you think?

envy commented 3 years ago

Thanks! Will do that in the future.

Still, I think the provider should default to that behavior for the template when the storage already exists.

nvthongswansea commented 3 years ago

Thanks! Will do that in the future.

Still, I think the provider should default to that behavior for the template when the storage already exists.

Actually this behavior is expected in terraform since the UUID of the template is changed. I think this issue should be solved in our backend side, as a change in name of the template should not cause the change in template UUID. Anyway, we will look into this issue.

bkircher commented 3 years ago

Hey there,

We changed template UUIDs for CentOS 8 and Ubuntu 20.04 when we updated those templates earlier this week. This shouldn't have happened and we learned to not do that in the future for existing OS templates we publish on my.gridscale.io and partner sites.

That one is on me. Sorry, if that caused any trouble!

data "gridscale_template" "ubuntu2004" {
  name = "Ubuntu 20.04 LTS (Focal Fossa)"
}

Totally legit. I would use the template UUID as a reference since I can promise from now on that we don't change UUIDs anymore. (Names however might change. Not necessarily often, though.)

The use of the lifecycle ignore_changes meta-argument is really helpful here to have TF set the value when the data or resource is first created and ignore any subsequent change to it in any terraform apply that follows. Even if we remove OS templates because they become EOL.

I think we should incorporate such strategies in our TF examples.

bkircher commented 3 years ago

@envy FYI, OS templates have been reverted to their old UUIDs and names. In case for Ubuntu 20.04 this would be Ubuntu 20.04 LTS (Focal Fossa) and fd65f8ce-e2c6-40af-8fc3-92efa0d4eecb.

bkircher commented 3 years ago

Issue is resolved