diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 7ad55e4d4..300c9d21d 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -8908,7 +8908,6 @@ func TestContext2Apply_destroyWithLocals(t *testing.T) { p.ApplyFn = testApplyFn p.DiffFn = func(info *InstanceInfo, s *InstanceState, c *ResourceConfig) (*InstanceDiff, error) { d, err := testDiffFn(info, s, c) - fmt.Println("DIFF:", d) return d, err } diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index 0065a458c..53e5534cd 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -1110,3 +1110,53 @@ func TestContext2Refresh_noDiffHookOnScaleOut(t *testing.T) { t.Fatal("PostDiff should not have been called") } } + +func TestContext2Refresh_updateProviderInState(t *testing.T) { + m := testModule(t, "update-resource-provider") + p := testProvider("aws") + + p.DiffFn = testDiffFn + p.ApplyFn = testApplyFn + + s := &State{ + Modules: []*ModuleState{ + &ModuleState{ + Path: rootModulePath, + Resources: map[string]*ResourceState{ + "aws_instance.bar": &ResourceState{ + Type: "aws_instance", + Primary: &InstanceState{ + ID: "foo", + }, + Provider: "provider.aws.baz", + }, + }, + }, + }, + } + + ctx := testContext2(t, &ContextOpts{ + Module: m, + ProviderResolver: ResourceProviderResolverFixed( + map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + ), + State: s, + }) + + expected := strings.TrimSpace(` +aws_instance.bar: + ID = foo + provider = provider.aws.foo`) + + state, err := ctx.Refresh() + if err != nil { + t.Fatal(err) + } + + actual := state.String() + if actual != expected { + t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual) + } +} diff --git a/terraform/test-fixtures/update-resource-provider/main.tf b/terraform/test-fixtures/update-resource-provider/main.tf new file mode 100644 index 000000000..6c082d540 --- /dev/null +++ b/terraform/test-fixtures/update-resource-provider/main.tf @@ -0,0 +1,7 @@ +provider "aws" { + alias = "foo" +} + +resource "aws_instance" "bar" { + provider = "aws.foo" +}