test that Refresh updates Provider fields in state
This commit is contained in:
parent
09180a10ff
commit
3801ca5bbf
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
provider "aws" {
|
||||
alias = "foo"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
provider = "aws.foo"
|
||||
}
|
Loading…
Reference in New Issue