update output destroy test to reference expander

Have the output reference the expansion of a resource (via the whole
resource object), so that we can be sure we don't attempt to evaluate
that expansion during destroy.
This commit is contained in:
James Bardin 2020-07-07 11:08:14 -04:00
parent b6c409613e
commit b62640d2d5
2 changed files with 36 additions and 11 deletions

View File

@ -6275,13 +6275,24 @@ func TestContext2Apply_destroyWithModuleVariableAndCountNested(t *testing.T) {
func TestContext2Apply_destroyOutputs(t *testing.T) {
m := testModule(t, "apply-destroy-outputs")
p := testProvider("aws")
p := testProvider("test")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
// add the required id
m := req.Config.AsValueMap()
m["id"] = cty.StringVal("foo")
return providers.ReadDataSourceResponse{
State: cty.ObjectVal(m),
}
}
ctx := testContext2(t, &ContextOpts{
Config: m,
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
},
})
@ -6302,7 +6313,7 @@ func TestContext2Apply_destroyOutputs(t *testing.T) {
State: state,
Config: m,
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
},
})
@ -6326,7 +6337,7 @@ func TestContext2Apply_destroyOutputs(t *testing.T) {
State: state,
Config: m,
Providers: map[addrs.Provider]providers.Factory{
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
},
})
if _, diags := ctx.Plan(); diags.HasErrors() {

View File

@ -1,12 +1,26 @@
resource "aws_instance" "foo" {
num = "2"
data "test_data_source" "foo" {
foo = "ok"
}
resource "aws_instance" "bar" {
foo = "{aws_instance.foo.num}"
dep = "foo"
locals {
l = [
{
name = data.test_data_source.foo.id
val = "null"
},
]
m = { for v in local.l :
v.name => v
}
}
output "foo" {
value = "${aws_instance.foo.id}"
resource "test_instance" "bar" {
for_each = local.m
foo = format("%s", each.value.name)
dep = each.value.val
}
output "out" {
value = test_instance.bar
}