-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: Add deferred action testing support (plan checks, version check,…
… and CLI options) (#331) * sloppy first commit! * add version checks and tests * add changelogs * update terraform-plugin-go * spelling fix * update `terraform-json` * switch to pointer bool value
- Loading branch information
1 parent
4c2e5cd
commit cb1f2b6
Showing
19 changed files
with
717 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: ENHANCEMENTS | ||
body: 'helper/resource: Added `(TestCase).AdditionalCLIOptions` with `AllowDeferral` | ||
option for plan and apply commands.' | ||
time: 2024-05-03T16:17:09.64792-04:00 | ||
custom: | ||
Issue: "331" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'plancheck: Added `ExpectDeferredChange` and `ExpectNoDeferredChanges` checks | ||
for experimental deferred action support.' | ||
time: 2024-05-03T16:15:31.03438-04:00 | ||
custom: | ||
Issue: "331" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `SkipIfNotPrerelease` version check for testing experimental | ||
features of prerelease Terraform builds.' | ||
time: 2024-05-03T16:18:02.132794-04:00 | ||
custom: | ||
Issue: "331" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package resource | ||
|
||
// AdditionalCLIOptions allows an intentionally limited set of options to be passed | ||
// to the Terraform CLI when executing test steps. | ||
type AdditionalCLIOptions struct { | ||
// Apply represents options to be passed to the `terraform apply` command. | ||
Apply ApplyOptions | ||
|
||
// Plan represents options to be passed to the `terraform plan` command. | ||
Plan PlanOptions | ||
} | ||
|
||
// ApplyOptions represents options to be passed to the `terraform apply` command. | ||
type ApplyOptions struct { | ||
// AllowDeferral will pass the experimental `-allow-deferral` flag to the apply command. | ||
AllowDeferral bool | ||
} | ||
|
||
// PlanOptions represents options to be passed to the `terraform plan` command. | ||
type PlanOptions struct { | ||
// AllowDeferral will pass the experimental `-allow-deferral` flag to the plan command. | ||
AllowDeferral bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package plancheck | ||
|
||
// DeferredReason is a string stored in the plan file which indicates why Terraform | ||
// is deferring a change for a resource. | ||
type DeferredReason string | ||
|
||
const ( | ||
// DeferredReasonResourceConfigUnknown is used to indicate that the resource configuration | ||
// is partially unknown and the real values need to be known before the change can be planned. | ||
DeferredReasonResourceConfigUnknown DeferredReason = "resource_config_unknown" | ||
|
||
// DeferredReasonProviderConfigUnknown is used to indicate that the provider configuration | ||
// is partially unknown and the real values need to be known before the change can be planned. | ||
DeferredReasonProviderConfigUnknown DeferredReason = "provider_config_unknown" | ||
|
||
// DeferredReasonAbsentPrereq is used to indicate that a hard dependency has not been satisfied. | ||
DeferredReasonAbsentPrereq DeferredReason = "absent_prereq" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package plancheck | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
var _ PlanCheck = expectDeferredChange{} | ||
|
||
type expectDeferredChange struct { | ||
resourceAddress string | ||
reason DeferredReason | ||
} | ||
|
||
// CheckPlan implements the plan check logic. | ||
func (e expectDeferredChange) CheckPlan(ctx context.Context, req CheckPlanRequest, resp *CheckPlanResponse) { | ||
foundResource := false | ||
|
||
for _, dc := range req.Plan.DeferredChanges { | ||
if dc.ResourceChange == nil || e.resourceAddress != dc.ResourceChange.Address { | ||
continue | ||
} | ||
|
||
if e.reason != DeferredReason(dc.Reason) { | ||
resp.Error = fmt.Errorf("'%s' - expected %q, got deferred reason: %q", dc.ResourceChange.Address, e.reason, dc.Reason) | ||
return | ||
} | ||
|
||
foundResource = true | ||
break | ||
} | ||
|
||
if !foundResource { | ||
resp.Error = fmt.Errorf("%s - No deferred changes found for resource", e.resourceAddress) | ||
return | ||
} | ||
} | ||
|
||
// ExpectDeferredChange returns a plan check that asserts that a given resource will have a | ||
// deferred change in the plan with the given reason. | ||
func ExpectDeferredChange(resourceAddress string, reason DeferredReason) PlanCheck { | ||
return expectDeferredChange{ | ||
resourceAddress: resourceAddress, | ||
reason: reason, | ||
} | ||
} |
Oops, something went wrong.