exoscale / terraform-provider-exoscale

Terraform Exoscale provider
https://www.terraform.io/docs/providers/exoscale/
Mozilla Public License 2.0
29 stars 25 forks source link

[Bug]: template id changes over time #366

Closed MartinTrifork closed 3 months ago

MartinTrifork commented 3 months ago

Current Behavior

The template: "Linux Ubuntu 22.04 LTS 64-bit" gets new template id's when there is a point release (i.e. 22.04.1)

When you have created a compute instance and want to create another one later by increasing the count (after the template id has been changed) Terraform will destroy the old compute instance and will create 2 new ones.

Expected Behavior

The template id shouldn't be changed. New templates should have a new name. For example:

That way if you add a compute instance it won't destroy the old ones.

With the code below I expect that on matter when you run it (in January or September) it will do exactly the same thing.

Steps To Reproduce

The first node was created with template id: 67756dc3-a1de-4abd-abcf-843ef9223bb6 (older Ubuntu 22.04)

By using the following code and changing toolbox_count from 1 to 2 it plans to add 2 and destroy one.

# toolbox variables
variable "toolbox_count" {default = "2"}

data "exoscale_template" "toolbox_template" {
    zone = var.zone
    name = "Linux Ubuntu 22.04 LTS 64-bit"
}

resource "exoscale_compute_instance" "toolbox" {
    zone = var.zone
    ssh_key = "iac-${var.env}"
    count = var.toolbox_count
    name = "iac-${var.env}-toolbox-${count.index + 1}"
    template_id = data.exoscale_template.toolbox_template.id
    type = "standard.tiny"
    disk_size = 10
    labels = {
        service = "toolbox",
        ansible = "true"
    }
    private = false
}

output "toolbox_template" {
    value = exoscale_compute_instance.toolbox.*.template_id
}

Probably the destroy and create will happen when you create with Ubuntu 22.04 and later run when 22.04.1 is out

I preferably don't want to add the template id as a variable here. Is there a proper work around?

Provider Version

0.58.0

Terraform Version

1.6.6

Relevant log output

Plan: 2 to add, 0 to change, 1 to destroy.

Changes to Outputs:
  ~ toolbox_template             = [
      - "67756dc3-a1de-4abd-abcf-843ef9223bb6",
      + "d0ad446f-8f21-4e60-9578-9b5206b5867d",
      + "d0ad446f-8f21-4e60-9578-9b5206b5867d",
    ]
sauterp commented 3 months ago

Hi Martin,

thanks for the report!

What you describe is indeed the intended behavior. We refresh our templates monthly and we keep the names the same so that new machines are created with the latest updates without re-referencing the new version in all configurations where the template is used.

That said, you should be able to create new instances with the newer template versions by employing ignore_changes. Also, this article should provide more guidance.

We hope this helps.

MartinTrifork commented 3 months ago

Thank you for your explanation. We tried the ignore_change and that works for us.

Maybe the information you provided could be added to https://github.com/exoscale/terraform-provider-exoscale/blob/master/docs/data-sources/template.md or to the example?

sauterp commented 3 months ago

Thanks for the suggestion, we will do just that https://github.com/exoscale/terraform-provider-exoscale/pull/368

Closing this, don't hesitate to reach out if you need more help.