core: Fix TestContext2Apply_destroyProvisionerWithMultipleLocals

This test was relying on the feature of the old provisioner API that gave
provisioners full access to the instance state of what they were
provisioning.

We no longer do this, and so instead the ApplyFn must distingish the
instances using a value from the provisioner's own configuration.
This commit is contained in:
Martin Atkins 2018-09-25 17:45:07 -07:00
parent 2bab5bf502
commit 5c4545dac2
2 changed files with 22 additions and 12 deletions

View File

@ -7725,6 +7725,10 @@ func TestContext2Apply_destroyProvisionerWithMultipleLocals(t *testing.T) {
pr.GetSchemaResponse = provisioners.GetSchemaResponse{
Provisioner: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"id": {
Type: cty.String,
Required: true,
},
"command": {
Type: cty.String,
Required: true,
@ -7742,8 +7746,12 @@ func TestContext2Apply_destroyProvisionerWithMultipleLocals(t *testing.T) {
if !ok {
return errors.New("no command in provisioner")
}
id, ok := rc.Get("id")
if !ok {
return errors.New("no id in provisioner")
}
switch is.ID {
switch id {
case "1234":
if cmd != "local" {
return fmt.Errorf("provisioner %q got:%q", is.ID, cmd)

View File

@ -1,24 +1,26 @@
locals {
value = "local"
foo_id = "${aws_instance.foo.id}"
value = "local"
foo_id = aws_instance.foo.id
// baz is not in the state during destroy, but this is a valid config that
// should not fail.
baz_id = "${aws_instance.baz.id}"
baz_id = aws_instance.baz.id
}
resource "aws_instance" "baz" {}
resource "aws_instance" "foo" {
provisioner "shell" {
command = "${local.value}"
when = "destroy"
}
provisioner "shell" {
id = self.id
command = local.value
when = "destroy"
}
}
resource "aws_instance" "bar" {
provisioner "shell" {
command = "${local.foo_id}"
when = "destroy"
}
provisioner "shell" {
id = self.id
command = local.foo_id
when = "destroy"
}
}