Mastercard / terraform-provider-restapi

A terraform provider to manage objects in a RESTful API
Other
785 stars 215 forks source link

Add support to ignore changes in read-only attributes #237

Open mohitatsafe opened 10 months ago

mohitatsafe commented 10 months ago

The state of the "restapi_object" resource changes when there is any change to the read-only attributes like api_data and api_response outside of Terraform, and it shows up in terraform plan/apply output.

For example:

~ resource "restapi_object" "check" {
      ~ api_response = jsonencode(
          ~ {
              ~ check = {
                  ~ lastdownend              = 1695240733 -> 1695314473
                }
            }
        )
    }

I tried to ignore these changes using the lifecycle block's ignore_changes argument as follows, which I think has no effect (see warning below):

resource "restapi_object" "check" {
  lifecycle {
    ignore_changes = [ api_response ]
  }
}

After adding the above changes, I see the following warning in Terraform plan/apply output:

 Warning: Redundant ignore_changes element
│
│   39: resource "restapi_object" "check" {
│
│ Adding an attribute name to ignore_changes tells Terraform to ignore future changes to the argument in
│ configuration after the object has been created, retaining the value originally configured.
│
│ The attribute api_response is decided by the provider alone and therefore there can be no configured value to
│ compare with. Including this attribute in ignore_changes has no effect. Remove the attribute from
│ ignore_changes to quiet this warning.

Versions

Terraform v1.4.6 Mastercard/restapi v1.18.0

kladiv commented 8 months ago

+1 how can we overcome this behavior?

farnoy commented 7 months ago

Also seeing this. You can't use anything dynamic in ignore_changes, so something like this is impossible:

  lifecycle {
    ignore_changes = [jsondecode(api_response).status]
  }

I don't understand why this provider outputs api_data as a string formatted with Go syntax instead of giving us a decoded object