ovh / terraform-provider-ovh

Terraform OVH provider
https://registry.terraform.io/providers/ovh/ovh/latest/docs
Mozilla Public License 2.0
183 stars 135 forks source link

[BUG] Importing ovh_vrack forces replacement #734

Open maxime1907 opened 2 days ago

maxime1907 commented 2 days ago

Describe the bug

We are trying to import an existing vrack into terraform. We have the correct vrack id and the import is successful, however, when running terraform plan it shows that we have to replace the vrack and everything inside it because the plan and ovh_subsidiary objects are added. I assume this is not intended behaviour.

Terraform Version

v1.9.6

OVH Terraform Provider Version

v0.50.0

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

data "ovh_me" "account" {}

data "ovh_order_cart" "cart" {
  ovh_subsidiary = data.ovh_me.account.ovh_subsidiary
}

data "ovh_order_cart_product_plan" "vrack" {
  cart_id        = data.ovh_order_cart.cart.id
  price_capacity = "renew"
  product        = "vrack"
  plan_code      = "vrack"
}

resource "ovh_vrack" "vrack" {
  ovh_subsidiary = data.ovh_order_cart.cart.ovh_subsidiary
  name           = var.vrack_name
  description    = var.vrack_description

  plan {
    duration     = data.ovh_order_cart_product_plan.vrack.selected_price.0.duration
    plan_code    = data.ovh_order_cart_product_plan.vrack.plan_code
    pricing_mode = data.ovh_order_cart_product_plan.vrack.selected_price.0.pricing_mode
  }
}

Expected Behavior

VRack is imported and next terraform plan only updates its fields.

Actual Behavior

After importing the resource it is forced to be replaced.

Steps to Reproduce

  1. terraform import 'module.ovh_managed_kubernetes.ovh_vrack.vrack' 'pn-XXXXXX'
  2. terraform plan -out=terraform.plan

Temporary workaround

  lifecycle {
    ignore_changes = [
      ovh_subsidiary,
    ]
  }

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

amstuta commented 11 hours ago

Hello @maxime1907, thanks for opening this issue.

I took your exact configuration and I'm not able to reproduce the issue (ovh_subsidiary is fetched from the same API call when reading a vrack resource and when using datasource ovh_me, so it should not be different when importing the resource).

What are the values that you have before and after for ovh_subsidiary ? And additionally that would help us debug if you could provide us the debug log of the import using TF_LOG=debug terraform import ....

maxime1907 commented 9 hours ago

Hello, thanks for your answer

Here is the debug output log of this command:

TF_LOG=debug terraform import 'module.ovh_managed_kubernetes.ovh_vrack.vrack' 'pn-REDACTED' > /tmp/output.log 2>&1

output_redacted.log

Here is the output of terraform plan after the import:

  # module.ovh_managed_kubernetes.ovh_vrack.vrack must be replaced
-/+ resource "ovh_vrack" "vrack" {
      ~ id             = "pn-REDACTED" -> (known after apply)
        name           = "REDACTED"
      ~ ovh_subsidiary = "FR" -> (known after apply) # forces replacement
      ~ service_name   = "pn-REDACTED" -> (known after apply)
      ~ urn            = "urn:v1:eu:resource:vrack:pn-REDACTED" -> (known after apply)
        # (1 unchanged attribute hidden)

      ~ order (known after apply)

      ~ plan {
          ~ duration     = "P1M" -> (known after apply)
          ~ pricing_mode = "default" -> (known after apply)
            # (2 unchanged attributes hidden)
        }
    }