terraform: test that data sources can reference other data sources
This commit is contained in:
parent
69ce353815
commit
eb20db92cf
|
@ -640,6 +640,43 @@ func TestContext2Refresh_dataState(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContext2Refresh_dataStateRefData(t *testing.T) {
|
||||
p := testProvider("null")
|
||||
m := testModule(t, "refresh-data-ref-data")
|
||||
state := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
// Intentionally no resources since data resources are
|
||||
// supposed to refresh themselves even if they didn't
|
||||
// already exist.
|
||||
Resources: map[string]*ResourceState{},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"null": testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
||||
p.ReadDataDiffFn = testDataDiffFn
|
||||
p.ReadDataApplyFn = testDataApplyFn
|
||||
|
||||
s, err := ctx.Refresh()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(s.String())
|
||||
expected := strings.TrimSpace(testTerraformRefreshDataRefDataStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s\n\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Refresh_tainted(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "refresh-basic")
|
||||
|
|
|
@ -79,6 +79,18 @@ func testContext2(t *testing.T, opts *ContextOpts) *Context {
|
|||
return ctx
|
||||
}
|
||||
|
||||
func testDataApplyFn(
|
||||
info *InstanceInfo,
|
||||
d *InstanceDiff) (*InstanceState, error) {
|
||||
return testApplyFn(info, new(InstanceState), d)
|
||||
}
|
||||
|
||||
func testDataDiffFn(
|
||||
info *InstanceInfo,
|
||||
c *ResourceConfig) (*InstanceDiff, error) {
|
||||
return testDiffFn(info, new(InstanceState), c)
|
||||
}
|
||||
|
||||
func testApplyFn(
|
||||
info *InstanceInfo,
|
||||
s *InstanceState,
|
||||
|
|
|
@ -1492,3 +1492,17 @@ hcl_instance.hcltest:
|
|||
foo.1 = b
|
||||
type = hcl_instance
|
||||
`
|
||||
|
||||
const testTerraformRefreshDataRefDataStr = `
|
||||
data.null_data_source.bar:
|
||||
ID = foo
|
||||
bar = yes
|
||||
type = null_data_source
|
||||
|
||||
Dependencies:
|
||||
data.null_data_source.foo
|
||||
data.null_data_source.foo:
|
||||
ID = foo
|
||||
foo = yes
|
||||
type = null_data_source
|
||||
`
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
data "null_data_source" "foo" {
|
||||
foo = "yes"
|
||||
}
|
||||
|
||||
data "null_data_source" "bar" {
|
||||
bar = "${data.null_data_source.foo.foo}"
|
||||
}
|
Loading…
Reference in New Issue