DataDog / terraform-provider-datadog

Terraform Datadog provider
https://www.terraform.io/docs/providers/datadog/
Mozilla Public License 2.0
403 stars 379 forks source link

[datadog_synthetics_test] prevent overriding the local state element from the backend response #2460

Closed etnbrd closed 4 months ago

etnbrd commented 4 months ago

The element field of a browser test step contains the element locator, which auto-heals on the backend side, and constantly changes independently from any changes on the terraform config. Because of that, terraform is constantly prompting about these changes, which are confusing since these changes are not initiated by the user.

In response to this, we disabled the diff on the element field, preventing terraform from updating the element at all: https://github.com/DataDog/terraform-provider-datadog/pull/854. We also introduced force_element_update to allow users to force updating the element if desired.

However the initial implementation didn't prevent the state from being updated when applying the config with other changes. The undesired diff kept reappearing. Moreover, force_element_update will always update the online resource, giving a false sense that the resource was modified.

This PR now prevents terraform from overriding the browser_step.*.params.element field in the local state with the response from the backend at all. If force_element_update is set to true, it'll still keep in state the value from the config to track changes in the config.

If force_element_update is not set or set to false, terraform will just ignore the element part from the backend entirely. If force_element_update is set to true, terraform won't prompt for any changes of element from the backend, and will update the online resource at every apply.