failing test with for_each self reference

This commit is contained in:
James Bardin 2019-10-28 12:23:24 -04:00
parent 8a34c33ad3
commit f11c836181
2 changed files with 46 additions and 0 deletions

View File

@ -6137,6 +6137,44 @@ func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) {
}
}
func TestContext2Apply_provisionerForEachSelfRef(t *testing.T) {
m := testModule(t, "apply-provisioner-for-each-self")
p := testProvider("aws")
pr := testProvisioner()
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
val, ok := c.Config["command"]
if !ok {
t.Fatalf("bad value for command: %v %#v", val, c)
}
return nil
}
ctx := testContext2(t, &ContextOpts{
Config: m,
ProviderResolver: providers.ResolverFixed(
map[string]providers.Factory{
"aws": testProviderFuncFixed(p),
},
),
Provisioners: map[string]ProvisionerFactory{
"shell": testProvisionerFuncFixed(pr),
},
})
if _, diags := ctx.Plan(); diags.HasErrors() {
t.Fatalf("plan errors: %s", diags.Err())
}
_, diags := ctx.Apply()
if diags.HasErrors() {
t.Fatalf("diags: %s", diags.Err())
}
}
// Provisioner should NOT run on a diff, only create
func TestContext2Apply_Provisioner_Diff(t *testing.T) {
m := testModule(t, "apply-provisioner-diff")

View File

@ -0,0 +1,8 @@
resource "aws_instance" "foo" {
for_each = toset(["a", "b", "c"])
foo = "number ${each.value}"
provisioner "shell" {
command = "${self.foo}"
}
}