equinix / terraform-provider-equinix

Terraform Equinix provider
https://deploy.equinix.com/labs/terraform-provider-equinix/
MIT License
47 stars 45 forks source link

[Bug]: changes to order in spot market facilities array is not tolerated #425

Open displague opened 8 months ago

displague commented 8 months ago

Terraform Version

latest used in CI

Equinix Provider Version

version = "1.18.0"

Effected Terraform Resources

equinix_metal_spot_market_request

Terraform Config Files

resource "equinix_metal_project" "test" {
  name = "tfacc-spot_market_request-%s"
}

resource "equinix_metal_spot_market_request" "req" {
  project_id    = "${equinix_metal_project.test.id}"
  max_bid_price = 0.01
  facilities    = local.facilities
  devices_min   = 1
  devices_max   = 1
  wait_for_devices = false

  instance_parameters {
    hostname         = "tfacc-testspot"
    billing_cycle    = "hourly"
    operating_system = local.os
    plan             = local.plan
  }
}

data "equinix_metal_spot_market_request" "dreq" {
  request_id = equinix_metal_spot_market_request.req.id
}

Debug Output

resource "equinix_metal_spot_market_request" "req" {
              ~ facilities       = [ # forces replacement
                  + "am6",
                  + "ch3",
                    "da11",
                  - "tr2",
                  + "da6",
                  + "dc10",
                    "dc13",
                  - "ty11",
                  + "fr2",
                  + "hk2",
                  + "la4",
                  + "md2",
                    "ny7",
                  + "pa4",
                    "se4",
                  - "sg4",
                  - "dc10",
                    "sg1",
                  - "pa4",
                  - "fr2",
                  + "sg4",
                  + "sg5",
                    "sp4",
                  - "hk2",
                  + "sv15",
                    "sv16",
                  - "da6",
                  - "ch3",
                    "sy5",
                  - "am6",
                  - "md2",
                  - "sg5",
                  - "sv15",
                  + "tr2",
                  + "ty11",
                ]

Panic Output

No response

Expected Behavior

Mismatched order of the returned facilities should not trigger replacement.

Actual Behavior

replacement is needed

Steps to Reproduce

Run the project CI - that's where this bug was found. TestAccDataSourceMetalSpotMarketRequest_basic https://github.com/equinix/terraform-provider-equinix/actions/runs/6629149298/job/18007833452#step:5:3011

ctreatma commented 8 months ago

The resource already ignores changes to ordering in the facilities attribute, but it does that via a SuppressDiff function, so when other changes happen in the facilities attribute, the diff shows those changes as well as the changes to the ordering.

In this case, there is one facility added to the list: + "la4",. I'm not sure how that change is coming in; I guess the local.facilities--read from the plan data and cached in terraform state--includes la4, but the API response for the spot market request doesn't include that facility for some reason?

I'm not sure how much we should really sink into this, given the impending deprecation of facilities platform-wide. At some point soonish, the affected attribute should become read-only, at which point the weird diff behavior goes away. That said, adding a CustomizeDiff function for the resource would at least make it easier to see what the real change is, even if we can't track down why the facilities list is different.