Skip to content

Commit

Permalink
test multi-instance postcondition self eval
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Oct 23, 2024
1 parent 987d4f7 commit 7a508a6
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions internal/terraform/context_plan2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5955,3 +5955,60 @@ output "staying" {
t.Fatalf("unexpected changes: %s", diff)
}
}

func TestContext2Plan_multiInstanceSelfRef(t *testing.T) {
// The postcondition here references self, but because instances are
// processed concurrently some instances may not be registered yet during
// evaluation. This should still evaluate without error, because we know our
// self value exists.
m := testModuleInline(t, map[string]string{
"main.tf": `
resource "test_resource" "test" {
}
data "test_data_source" "foo" {
count = 100
lifecycle {
postcondition {
condition = self.attr == null
error_message = "error"
}
}
depends_on = [test_resource.test]
}
`,
})

p := new(testing_provider.MockProvider)
p.GetProviderSchemaResponse = getProviderSchemaResponseFromProviderSchema(&providerSchema{
DataSources: map[string]*configschema.Block{
"test_data_source": {
Attributes: map[string]*configschema.Attribute{
"attr": {
Type: cty.String,
Computed: true,
},
},
},
},
ResourceTypes: map[string]*configschema.Block{
"test_resource": {
Attributes: map[string]*configschema.Attribute{
"attr": {
Type: cty.String,
Computed: true,
},
},
},
},
})

ctx := testContext2(t, &ContextOpts{
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
},
})

_, diags := ctx.Plan(m, states.NewState(), SimplePlanOpts(plans.NormalMode, testInputValuesUnset(m.Module.Variables)))
assertNoErrors(t, diags)
}

0 comments on commit 7a508a6

Please sign in to comment.