ovh/terraform-provider-ovh

[BUG] terraform plan replaces compute instance instead of doing nothing

Closed this issue · 4 comments

Describe the bug

I deployed an openstack_compute_instance_v2 with image_name = "Ubuntu 22.04" a few days ago.
OVH deprecated the image on 18/04/2024 (it's shown in ovh manager UI: Ubuntu 22.04 - deprecated - 2024-04-18)
Running terraform now causes a replacement of the compute instance, which is not the expected behavior

This is a blocking on using terraform to deploy and maintain OVH infra on the long run

Terraform Version

Terraform v1.7.1

OVH Terraform Provider Version

  • Reusing previous version of terraform-provider-openstack/openstack from the dependency lock file
  • Reusing previous version of ovh/ovh from the dependency lock file
  • Reusing previous version of hashicorp/aws from the dependency lock file
  • Reusing previous version of hashicorp/google from the dependency lock file
  • Using previously-installed hashicorp/aws v4.67.0
  • Using previously-installed hashicorp/google v5.25.0
  • Using previously-installed terraform-provider-openstack/openstack v1.42.0
  • Using previously-installed ovh/ovh v0.42.0

Affected Resource(s)

Please list the resources as a list, for example:

  • openstack_compute_instance_v2

Terraform Configuration Files

resource "openstack_compute_instance_v2" "INSTANCE_NAME" {
  count       = 1
  name        = "INSTANCE_NAME"
  key_pair    = openstack_compute_keypair_v2.my_sskkey.name
  flavor_name = "b3-8"
  image_name  = "Ubuntu 22.04"
  region      = "SBG7"
  network {
    name = "Ext-Net"
  }
  network {
    name = ovh_cloud_project_network_private.my_network.name
  }
  /*metadata = {
    "ovh-monthly-instance" = 1
  }*/
}

Debug Output

terraform plan gives

  # openstack_compute_instance_v2.INSTANCE_NAME[0] must be replaced
-/+ resource "openstack_compute_instance_v2" "INSTANCE_NAME" {
      ~ access_ip_v4        = "RETRACTED" -> (known after apply)
      ~ access_ip_v6        = "[RETRACTED]" -> (known after apply)
      ~ all_metadata        = {} -> (known after apply)
      ~ all_tags            = [] -> (known after apply)
      ~ availability_zone   = "nova" -> (known after apply)
      ~ flavor_id           = "945a6e11-2563-475b-bb92-c41fa5ef1020" -> (known after apply)
      ~ id                  = "RETRACTED" -> (known after apply)
      ~ image_id            = "610542c0-65bb-4251-9225-44d73feea678" -> (known after apply)
      ~ image_name          = "Image not found" -> "Ubuntu 22.04" # forces replacement
        name                = "INSTANCE_NAME"
      ~ security_groups     = [
          - "default",
        ] -> (known after apply)
      - tags                = [] -> null
        # (6 unchanged attributes hidden)

      ~ network {
          ~ fixed_ip_v4    = "RETRACTED" -> (known after apply)
          ~ fixed_ip_v6    = "[RETRACTED]" -> (known after apply)
          + floating_ip    = (known after apply)
          ~ mac            = "RETRACTED" -> (known after apply)
            name           = "Ext-Net"
          + port           = (known after apply)
          ~ uuid           = "RETRACTED" -> (known after apply)
            # (1 unchanged attribute hidden)
        }
      ~ network {
          ~ fixed_ip_v4    = "10.3.153.10" -> (known after apply)
          + fixed_ip_v6    = (known after apply)
          + floating_ip    = (known after apply)
          ~ mac            = "RETRACTED" -> (known after apply)
            name           = "RETRACTED"
          + port           = (known after apply)
          ~ uuid           = "RETRACTED" -> (known after apply)
            # (1 unchanged attribute hidden)
        }
    }

Expected Behavior

Since no change has been made to terraform, neither to the instance configuration, there should be no change

On solution would be to update the images after deprecation for this :

  image_name  = "Image not found"

But this is not satisfying

Hello @vparpoil,

Indeed the image name can be updated to indicate deprecations for example. To solve your issue, you should not rely on the image_name but only on the image_id, which is immutable.

You should use image_name at instance creation but ignore it afterwards using ignore_changes (https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).

Hi @amstuta ,
Thanks for your answer. Indeed, ignore_changes solves my issue.
I think those best practices should be highlighted in the docs , I didn't came with image_name on my own ;)

Great :) You're right, the info has been raised to the right team and they will update the docs.