Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding a PlanCheck that verifies a resource is replaced - ExpectResourceReplacePaths #107

Open
austinvalle opened this issue Mar 21, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@austinvalle
Copy link
Member

austinvalle commented Mar 21, 2023

Description

After #63 is merged, we can create new built-in plan checks that may be useful for provider testing.

The plan contains change information for resources that indicate what object values resulted in a resource being replaced (deleted, then re-created):

{
  // ... other change representation fields

  // "replace_paths" is an array of arrays representing a set of paths into the
  // object value which resulted in the action being "replace". This will be
  // omitted if the action is not replace, or if no paths caused the
  // replacement (for example, if the resource was tainted). Each path
  // consists of one or more steps, each of which will be a number or a
  // string.
  "replace_paths": [["triggers"]]
}

This could be useful for provider developers that need to ensure that certain config changes result in a full delete/create, rather than an update in-place.

We'll need to ensure the terraform-json package is updated to marshal this replace_paths attribute

Other considerations

This implementation should also consider if the testing framework needs to build it's own path system to support functionality like this. The testing code is already leaning on a custom flatmap/HCL reference string syntax, but it can be confusing for developers and required non-HCL-existent syntax for set type attributes since they cannot be indexed.

terraform-plugin-framework's path package is available, but potentially awkward to link together with the actual JSON paths without also introducing JSON schema handling into the testing code. It would also be a goal to not import the framework code so the testing module remains portable across any existing or future Go-based SDKs.

@austinvalle austinvalle added the enhancement New feature or request label Mar 21, 2023
@bflad
Copy link
Contributor

bflad commented Mar 22, 2023

Now seeing the replace_paths implementation, we could consider follow the abstraction it already provides such as accepting a []string of path steps so we do not need to reinvent another path system. The plan JSON has been stable for awhile now, so I'm not sure if we necessarily need to abstract it. That sort of plan JSON change would introduce a large burden on the Terraform ecosystem so it wouldn't be done unless there were some major benefits to doing so.

The main consideration to a []string implementation would then be seeing how set element paths are represented, such as a set nested attribute or set nested block where an underlying attribute is what is triggering the replacement. I think that would help determine whether that type of solution would be okay.

@bflad
Copy link
Contributor

bflad commented Dec 21, 2023

This should be enabled in the next version of terraform-json: hashicorp/terraform-json#117

Please note that this plan replace path information is only populated by Terraform 0.15 and later.

@bflad
Copy link
Contributor

bflad commented Dec 21, 2023

@gdavison
Copy link
Contributor

It would be good to have two variants: one that passes as long as the ReplacePaths contains the given set (e.g. ExpectResourceReplacePathsContains) and one that must be a strict equality (e.g. ExpectResourceReplacePathsEquals)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants