You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are scenarios where developers may want to use output values for checking plan differences rather than needing a "heavier" configuration setup of a managed resource to store the state and check against that managed resource for plan differences. Checking whole data source contents between provider versions is one such example.
If using the legacy null_resource managed resource, there's additional testing configuration necessary such as properly setting up the TestStep.ExternalProviders field.
Developers may not be contextually expecting that a managed resource is the correct way to store a value of a provider concept which implicitly does not store state across Terraform runs, instead reaching for an output, which can accomplish the same thing:
When testing this way via TestStep.PlanOnly though, output value changes do not cause the test to fail. Instead a plan check must be used, which there is no built-in plan check available today.
Proposal
At some point, we should likely consider deprecating PlanOnly since its a confusing abstraction for developers and instead recommend plan checks. This will be separately proposed though.
This Go module could introduce a new built-in plan check for this, e.g. as a code sketch
// naming debatable of course, this is just a working code sketchfuncExpectOutputNoChanges(outputstring) plancheck.PlanCheck {
returnexpectOutputNoChangesCheck{
output: output,
}
}
typeexpectOutputNoChangesCheckstruct {
outputstring
}
func (cexpectOutputNoChangesCheck) CheckPlan(ctx context.Context, req plancheck.CheckPlanRequest, resp*plancheck.CheckPlanResponse) {
iflen(req.Plan.OutputChanges) ==0 {
return
}
change, ok:=req.Plan.OutputChanges[c.output]
if!ok||change==nil {
return
}
resp.Error=fmt.Errorf("unexpected output %q change", c.output)
}
This then plan check is usable for this testing situation:
bflad
changed the title
Consider Plan Check for Output Value Changes
Consider Separate Plan Checks for Resource Changes and Output Changes
Nov 30, 2023
bflad
changed the title
Consider Separate Plan Checks for Resource Changes and Output Changes
Consider Plan Check for Output Value Changes
Nov 30, 2023
terraform-plugin-testing version
Use cases
There are scenarios where developers may want to use output values for checking plan differences rather than needing a "heavier" configuration setup of a managed resource to store the state and check against that managed resource for plan differences. Checking whole data source contents between provider versions is one such example.
For that example, the configuration looks like:
If using the legacy
null_resource
managed resource, there's additional testing configuration necessary such as properly setting up theTestStep.ExternalProviders
field.Developers may not be contextually expecting that a managed resource is the correct way to store a value of a provider concept which implicitly does not store state across Terraform runs, instead reaching for an output, which can accomplish the same thing:
When testing this way via
TestStep.PlanOnly
though, output value changes do not cause the test to fail. Instead a plan check must be used, which there is no built-in plan check available today.Proposal
At some point, we should likely consider deprecating
PlanOnly
since its a confusing abstraction for developers and instead recommend plan checks. This will be separately proposed though.This Go module could introduce a new built-in plan check for this, e.g. as a code sketch
This then plan check is usable for this testing situation:
References
The text was updated successfully, but these errors were encountered: