add test for using a data source with depends_on
Ensure that a data source with depends_on not only plans to update during refresh, but evaluates correctly in the plan ensuring dependencies are planned accordingly.
This commit is contained in:
parent
44919641ef
commit
c6c851eb3f
|
@ -8724,7 +8724,20 @@ func TestContext2Apply_destroyNestedModuleWithAttrsReferencingResource(t *testin
|
|||
// that resource to be applied first.
|
||||
func TestContext2Apply_dataDependsOn(t *testing.T) {
|
||||
p := testProvider("null")
|
||||
m := testModule(t, "apply-data-depends-on")
|
||||
m := testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
resource "null_instance" "write" {
|
||||
foo = "attribute"
|
||||
}
|
||||
|
||||
data "null_data_source" "read" {
|
||||
depends_on = ["null_instance.write"]
|
||||
}
|
||||
|
||||
resource "null_instance" "depends" {
|
||||
foo = data.null_data_source.read.foo
|
||||
}
|
||||
`})
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
|
@ -8792,6 +8805,53 @@ func TestContext2Apply_dataDependsOn(t *testing.T) {
|
|||
t.Fatalf("unexpected change for %s", c.Addr)
|
||||
}
|
||||
}
|
||||
|
||||
// now we cause a change in the first resource, which should trigger a plan
|
||||
// in the data source, and the resource that depends on the data source
|
||||
// must plan a change as well.
|
||||
m = testModuleInline(t, map[string]string{
|
||||
"main.tf": `
|
||||
resource "null_instance" "write" {
|
||||
foo = "new"
|
||||
}
|
||||
|
||||
data "null_data_source" "read" {
|
||||
depends_on = ["null_instance.write"]
|
||||
}
|
||||
|
||||
resource "null_instance" "depends" {
|
||||
foo = data.null_data_source.read.foo
|
||||
}
|
||||
`})
|
||||
|
||||
p.ApplyFn = func(info *InstanceInfo, s *InstanceState, d *InstanceDiff) (*InstanceState, error) {
|
||||
// the side effect of the resource being applied
|
||||
provisionerOutput = "APPLIED_AGAIN"
|
||||
return testApplyFn(info, s, d)
|
||||
}
|
||||
|
||||
ctx = testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
State: state,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewDefaultProvider("null"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
plan, diags = ctx.Plan()
|
||||
assertNoErrors(t, diags)
|
||||
|
||||
expectedChanges := map[string]plans.Action{
|
||||
"null_instance.write": plans.Update,
|
||||
"data.null_data_source.read": plans.Read,
|
||||
"null_instance.depends": plans.Update,
|
||||
}
|
||||
|
||||
for _, c := range plan.Changes.Resources {
|
||||
if c.Action != expectedChanges[c.Addr.String()] {
|
||||
t.Errorf("unexpected %s for %s", c.Action, c.Addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_terraformWorkspace(t *testing.T) {
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
resource "null_instance" "write" {
|
||||
foo = "attribute"
|
||||
}
|
||||
|
||||
data "null_data_source" "read" {
|
||||
depends_on = ["null_instance.write"]
|
||||
}
|
Loading…
Reference in New Issue