|
|
|
|
@ -744,6 +744,58 @@ check "error" {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestContextChecks_DoesNotPanicOnModuleExpansion(t *testing.T) {
|
|
|
|
|
// This is a bit of a special test, we're adding it to verify that
|
|
|
|
|
// https://github.com/hashicorp/terraform/issues/34062 is fixed.
|
|
|
|
|
//
|
|
|
|
|
// Essentially we make a check block in a child module that depends on a
|
|
|
|
|
// resource that has no changes. We don't care about the actual behaviour
|
|
|
|
|
// of the check block. We just don't want the apply operation to crash.
|
|
|
|
|
|
|
|
|
|
m := testModuleInline(t, map[string]string{
|
|
|
|
|
"main.tf": `
|
|
|
|
|
module "panic_at_the_disco" {
|
|
|
|
|
source = "./panic"
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
"panic/main.tf": `
|
|
|
|
|
resource "test_object" "object" {
|
|
|
|
|
test_string = "Hello, world!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check "check_should_not_panic" {
|
|
|
|
|
assert {
|
|
|
|
|
condition = test_object.object.test_string == "Hello, world!"
|
|
|
|
|
error_message = "condition violated"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
p := simpleMockProvider()
|
|
|
|
|
|
|
|
|
|
ctx := testContext2(t, &ContextOpts{
|
|
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
|
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
plan, diags := ctx.Plan(m, states.BuildState(func(state *states.SyncState) {
|
|
|
|
|
state.SetResourceInstanceCurrent(
|
|
|
|
|
mustResourceInstanceAddr("module.panic_at_the_disco.test_object.object"),
|
|
|
|
|
&states.ResourceInstanceObjectSrc{
|
|
|
|
|
AttrsJSON: []byte(`{"test_string":"Hello, world!"}`),
|
|
|
|
|
Status: states.ObjectReady,
|
|
|
|
|
},
|
|
|
|
|
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
|
|
|
|
)
|
|
|
|
|
}), DefaultPlanOpts)
|
|
|
|
|
assertNoErrors(t, diags)
|
|
|
|
|
|
|
|
|
|
_, diags = ctx.Apply(plan, m)
|
|
|
|
|
assertNoErrors(t, diags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func validateCheckDiagnostics(t *testing.T, stage string, expectedWarning, expectedError string, actual tfdiags.Diagnostics) bool {
|
|
|
|
|
if expectedError != "" {
|
|
|
|
|
if !actual.HasErrors() {
|
|
|
|
|
|