core: Remove TestContext2Apply_provisionerMultiSelfRefSingle
We no longer support using "self.count" in a provisioner to access the resolved count meta-argument value of the associated resource. This was only possible before because of a special exception in how Terraform resolved variables, and in new HCL that exception isn't possible because resource instances are real values in the scope and we don't want to add this implied "count" attribute to all of them. "count" is a property of the resource config rather than of the resource instances, and since "self" is a resource _instance_ it doesn't make sense to expose it there. There is no replacement for this feature. In the rare case where it is needed, the user must factor the count out into a named local value and refer to that both in the count meta-argument and in the provisioner.
This commit is contained in:
parent
1caffba0e6
commit
5cf06e86c6
|
@ -5606,61 +5606,6 @@ func TestContext2Apply_provisionerMultiSelfRefSingle(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_provisionerMultiSelfRefCount(t *testing.T) {
|
||||
var lock sync.Mutex
|
||||
commands := make([]string, 0, 5)
|
||||
|
||||
m := testModule(t, "apply-provisioner-multi-self-ref-count")
|
||||
p := testProvider("aws")
|
||||
pr := testProvisioner()
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
pr.ApplyFn = func(rs *InstanceState, c *ResourceConfig) error {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
|
||||
val, ok := c.Config["command"]
|
||||
if !ok {
|
||||
t.Fatalf("bad value for command: %v %#v", val, c)
|
||||
}
|
||||
|
||||
commands = append(commands, val.(string))
|
||||
return nil
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
ProviderResolver: ResourceProviderResolverFixed(
|
||||
map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
),
|
||||
Provisioners: map[string]ResourceProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
},
|
||||
})
|
||||
|
||||
if _, diags := ctx.Plan(); diags.HasErrors() {
|
||||
t.Fatalf("diags: %s", diags.Err())
|
||||
}
|
||||
|
||||
if _, diags := ctx.Apply(); diags.HasErrors() {
|
||||
t.Fatalf("diags: %s", diags.Err())
|
||||
}
|
||||
|
||||
// Verify apply was invoked
|
||||
if !pr.ApplyCalled {
|
||||
t.Fatalf("provisioner not invoked")
|
||||
}
|
||||
|
||||
// Verify our result
|
||||
sort.Strings(commands)
|
||||
expectedCommands := []string{"3", "3", "3"}
|
||||
if !reflect.DeepEqual(commands, expectedCommands) {
|
||||
t.Fatalf("bad: %#v", commands)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_provisionerExplicitSelfRef(t *testing.T) {
|
||||
m := testModule(t, "apply-provisioner-explicit-self-ref")
|
||||
p := testProvider("aws")
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
resource "aws_instance" "foo" {
|
||||
count = 3
|
||||
|
||||
provisioner "shell" {
|
||||
command = "${self.count}"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue