|
|
|
|
@ -3,7 +3,6 @@ package local
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strings"
|
|
|
|
|
@ -20,6 +19,7 @@ import (
|
|
|
|
|
"github.com/hashicorp/terraform/states"
|
|
|
|
|
"github.com/hashicorp/terraform/states/statemgr"
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestLocal_applyBasic(t *testing.T) {
|
|
|
|
|
@ -122,45 +122,32 @@ func TestLocal_applyEmptyDirDestroy(t *testing.T) {
|
|
|
|
|
func TestLocal_applyError(t *testing.T) {
|
|
|
|
|
b, cleanup := TestLocal(t)
|
|
|
|
|
defer cleanup()
|
|
|
|
|
p := TestLocalProvider(t, b, "test", nil)
|
|
|
|
|
p := TestLocalProvider(t, b, "test", applyFixtureSchema())
|
|
|
|
|
|
|
|
|
|
var lock sync.Mutex
|
|
|
|
|
errored := false
|
|
|
|
|
p.GetSchemaReturn = &terraform.ProviderSchema{
|
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
|
|
|
"test_instance": {
|
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
|
"ami": {Type: cty.String, Optional: true},
|
|
|
|
|
"error": {Type: cty.String, Optional: true},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
p.ApplyFn = func(
|
|
|
|
|
info *terraform.InstanceInfo,
|
|
|
|
|
s *terraform.InstanceState,
|
|
|
|
|
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
|
|
|
|
|
p.ApplyResourceChangeFn = func(
|
|
|
|
|
r providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse {
|
|
|
|
|
|
|
|
|
|
lock.Lock()
|
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
var diags tfdiags.Diagnostics
|
|
|
|
|
|
|
|
|
|
if !errored && info.Id == "test_instance.bar" {
|
|
|
|
|
ami := r.Config.GetAttr("ami").AsString()
|
|
|
|
|
if !errored && ami == "error" {
|
|
|
|
|
errored = true
|
|
|
|
|
return nil, fmt.Errorf("error")
|
|
|
|
|
diags = diags.Append(errors.New("error"))
|
|
|
|
|
return providers.ApplyResourceChangeResponse{
|
|
|
|
|
Diagnostics: diags,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return providers.ApplyResourceChangeResponse{
|
|
|
|
|
Diagnostics: diags,
|
|
|
|
|
NewState: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"id": cty.StringVal("foo"),
|
|
|
|
|
"ami": cty.StringVal("bar"),
|
|
|
|
|
}),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &terraform.InstanceState{ID: "foo"}, nil
|
|
|
|
|
}
|
|
|
|
|
p.DiffFn = func(
|
|
|
|
|
*terraform.InstanceInfo,
|
|
|
|
|
*terraform.InstanceState,
|
|
|
|
|
*terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
|
|
|
|
|
return &terraform.InstanceDiff{
|
|
|
|
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
|
|
|
|
"ami": &terraform.ResourceAttrDiff{
|
|
|
|
|
New: "bar",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
op, configCleanup := testOperationApply(t, "./test-fixtures/apply-error")
|
|
|
|
|
@ -179,6 +166,7 @@ func TestLocal_applyError(t *testing.T) {
|
|
|
|
|
test_instance.foo:
|
|
|
|
|
ID = foo
|
|
|
|
|
provider = provider.test
|
|
|
|
|
ami = bar
|
|
|
|
|
`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|