Mildwonkey/tests (#24522)
* terraform: add helper functions for creating test state testSetResourceInstanceCurrent and testSetResourceInstanceTainted are wrapper functions around states.Module.SetResourceInstanceCurrent() used to set a resource in state. They work with current, non-deposed resources with no dependencies. testSetResourceInstanceDeposed can be used to set a desosed resource in state. * terraform: update all tests to use modern providers and state
This commit is contained in:
parent
e683a6adef
commit
3f6ce3c588
|
@ -2,13 +2,9 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
"github.com/hashicorp/terraform/configs"
|
||||
"github.com/hashicorp/terraform/moduledeps"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
"github.com/hashicorp/terraform/tfdiags"
|
||||
"github.com/xlab/treeprint"
|
||||
)
|
||||
|
||||
|
@ -35,6 +31,7 @@ func (c *ProvidersCommand) Run(args []string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
/*
|
||||
configPath, err := ModulePath(cmdFlags.Args())
|
||||
if err != nil {
|
||||
c.Ui.Error(err.Error())
|
||||
|
@ -109,7 +106,9 @@ func (c *ProvidersCommand) Run(args []string) int {
|
|||
if diags.HasErrors() {
|
||||
return 1
|
||||
}
|
||||
*/
|
||||
|
||||
c.Ui.Output(fmt.Sprintf("terraform providers is temporarily disabled"))
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ func simpleMockComponentFactory() *basicComponentFactory {
|
|||
provisioner := simpleMockProvisioner()
|
||||
return &basicComponentFactory{
|
||||
providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): func() (providers.Interface, error) {
|
||||
addrs.NewDefaultProvider("test"): func() (providers.Interface, error) {
|
||||
return provider, nil
|
||||
},
|
||||
},
|
||||
|
|
|
@ -22,32 +22,23 @@ func TestContext2Refresh(t *testing.T) {
|
|||
p := testProvider("aws")
|
||||
m := testModule(t, "refresh-basic")
|
||||
|
||||
startingState := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"id": "foo",
|
||||
"foo": "bar",
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("aws_instance.web").Resource,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"foo","foo":"bar"}`),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`),
|
||||
)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: startingState,
|
||||
State: state,
|
||||
})
|
||||
|
||||
schema := p.GetSchemaReturn.ResourceTypes["aws_instance"]
|
||||
|
@ -102,7 +93,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"dynamic":{"type":"string","value":"hello"}}`),
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("test"),
|
||||
Provider: addrs.NewDefaultProvider("test"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -131,7 +122,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: startingState,
|
||||
})
|
||||
|
@ -165,7 +156,7 @@ func TestContext2Refresh_dataComputedModuleVar(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -250,25 +241,20 @@ func TestContext2Refresh_targeted(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_vpc.metoo", `{"id":"vpc-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.notme", `{"id":"i-bcd345"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.me", `{"id":"i-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_elb.meneither", `{"id":"lb-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
m := testModule(t, "refresh-targeted")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_vpc.metoo": resourceState("aws_vpc", "vpc-abc123"),
|
||||
"aws_instance.notme": resourceState("aws_instance", "i-bcd345"),
|
||||
"aws_instance.me": resourceState("aws_instance", "i-abc123"),
|
||||
"aws_elb.meneither": resourceState("aws_elb", "lb-abc123"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
Targets: []addrs.Targetable{
|
||||
addrs.RootModuleInstance.Resource(
|
||||
addrs.ManagedResourceMode, "aws_instance", "me",
|
||||
|
@ -331,27 +317,22 @@ func TestContext2Refresh_targetedCount(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_vpc.metoo", `{"id":"vpc-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.notme", `{"id":"i-bcd345"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.me[0]", `{"id":"i-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.me[1]", `{"id":"i-cde567"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.me[2]", `{"id":"i-cde789"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_elb.meneither", `{"id":"lb-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
m := testModule(t, "refresh-targeted-count")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_vpc.metoo": resourceState("aws_vpc", "vpc-abc123"),
|
||||
"aws_instance.notme": resourceState("aws_instance", "i-bcd345"),
|
||||
"aws_instance.me.0": resourceState("aws_instance", "i-abc123"),
|
||||
"aws_instance.me.1": resourceState("aws_instance", "i-cde567"),
|
||||
"aws_instance.me.2": resourceState("aws_instance", "i-cde789"),
|
||||
"aws_elb.meneither": resourceState("aws_elb", "lb-abc123"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
Targets: []addrs.Targetable{
|
||||
addrs.RootModuleInstance.Resource(
|
||||
addrs.ManagedResourceMode, "aws_instance", "me",
|
||||
|
@ -422,27 +403,22 @@ func TestContext2Refresh_targetedCountIndex(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_vpc.metoo", `{"id":"vpc-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.notme", `{"id":"i-bcd345"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.me[0]", `{"id":"i-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.me[1]", `{"id":"i-cde567"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.me[2]", `{"id":"i-cde789"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_elb.meneither", `{"id":"lb-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
m := testModule(t, "refresh-targeted-count")
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_vpc.metoo": resourceState("aws_vpc", "vpc-abc123"),
|
||||
"aws_instance.notme": resourceState("aws_instance", "i-bcd345"),
|
||||
"aws_instance.me.0": resourceState("aws_instance", "i-abc123"),
|
||||
"aws_instance.me.1": resourceState("aws_instance", "i-cde567"),
|
||||
"aws_instance.me.2": resourceState("aws_instance", "i-cde789"),
|
||||
"aws_elb.meneither": resourceState("aws_elb", "lb-abc123"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
Targets: []addrs.Targetable{
|
||||
addrs.RootModuleInstance.ResourceInstance(
|
||||
addrs.ManagedResourceMode, "aws_instance", "me", addrs.IntKey(0),
|
||||
|
@ -493,7 +469,7 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -507,26 +483,17 @@ func TestContext2Refresh_moduleComputedVar(t *testing.T) {
|
|||
func TestContext2Refresh_delete(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "refresh-basic")
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.web", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
})
|
||||
|
||||
p.ReadResourceFn = nil
|
||||
|
@ -551,7 +518,7 @@ func TestContext2Refresh_ignoreUncreated(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: nil,
|
||||
})
|
||||
|
@ -576,27 +543,18 @@ func TestContext2Refresh_hook(t *testing.T) {
|
|||
h := new(MockHook)
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "refresh-basic")
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.web", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Hooks: []Hook{h},
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
})
|
||||
|
||||
if _, diags := ctx.Refresh(); diags.HasErrors() {
|
||||
|
@ -613,38 +571,17 @@ func TestContext2Refresh_hook(t *testing.T) {
|
|||
func TestContext2Refresh_modules(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "refresh-modules")
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
Tainted: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
&ModuleState{
|
||||
Path: []string{"root", "child"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceTainted(root, "aws_instance.web", `{"id":"bar"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey))
|
||||
testSetResourceInstanceCurrent(child, "aws_instance.web", `{"id":"baz"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -704,7 +641,7 @@ func TestContext2Refresh_moduleInputComputedOutput(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -720,7 +657,7 @@ func TestContext2Refresh_moduleVarModule(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -736,7 +673,7 @@ func TestContext2Refresh_noState(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -773,38 +710,18 @@ func TestContext2Refresh_output(t *testing.T) {
|
|||
}
|
||||
|
||||
m := testModule(t, "refresh-output")
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.web", `{"id":"foo","foo":"bar"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
root.SetOutputValue("foo", cty.StringVal("foo"), false)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"id": "foo",
|
||||
"foo": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Outputs: map[string]*OutputState{
|
||||
"foo": &OutputState{
|
||||
Type: "string",
|
||||
Sensitive: false,
|
||||
Value: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
})
|
||||
|
||||
s, diags := ctx.Refresh()
|
||||
|
@ -847,27 +764,16 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
|
|||
NewState: cty.NullVal(p.GetSchemaReturn.ResourceTypes["aws_instance"].ImpliedType()),
|
||||
}
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.foo", `{}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
Outputs: map[string]*OutputState{},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
})
|
||||
|
||||
s, diags := ctx.Refresh()
|
||||
|
@ -885,25 +791,15 @@ func TestContext2Refresh_outputPartial(t *testing.T) {
|
|||
func TestContext2Refresh_stateBasic(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "refresh-basic")
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.web", `{"id":"bar"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -976,7 +872,7 @@ func TestContext2Refresh_dataCount(t *testing.T) {
|
|||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
Config: m,
|
||||
})
|
||||
|
@ -1002,25 +898,13 @@ func TestContext2Refresh_dataCount(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_dataOrphan(t *testing.T) {
|
||||
p := testProvider("null")
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"data.null_data_source.bar": &ResourceState{
|
||||
Type: "null_data_source",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
Provider: "provider.null",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "data.null_data_source.bar", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/null"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("null"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("null"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -1035,19 +919,7 @@ func TestContext2Refresh_dataOrphan(t *testing.T) {
|
|||
|
||||
func TestContext2Refresh_dataState(t *testing.T) {
|
||||
m := testModule(t, "refresh-data-resource-basic")
|
||||
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
// Intentionally no resources since data resources are
|
||||
// supposed to refresh themselves even if they didn't
|
||||
// already exist.
|
||||
Resources: map[string]*ResourceState{},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
schema := &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
"inputs": {
|
||||
|
@ -1068,7 +940,7 @@ func TestContext2Refresh_dataState(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("null"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("null"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -1159,21 +1031,11 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) {
|
|||
}
|
||||
|
||||
m := testModule(t, "refresh-data-ref-data")
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
// Intentionally no resources since data resources are
|
||||
// supposed to refresh themselves even if they didn't
|
||||
// already exist.
|
||||
Resources: map[string]*ResourceState{},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("null"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("null"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -1203,26 +1065,15 @@ func TestContext2Refresh_dataStateRefData(t *testing.T) {
|
|||
func TestContext2Refresh_tainted(t *testing.T) {
|
||||
p := testProvider("aws")
|
||||
m := testModule(t, "refresh-basic")
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
Tainted: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceTainted(root, "aws_instance.web", `{"id":"bar"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -1261,31 +1112,21 @@ func TestContext2Refresh_unknownProvider(t *testing.T) {
|
|||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.web", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
_, diags := NewContext(&ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
})
|
||||
|
||||
if !diags.HasErrors() {
|
||||
t.Fatal("successfully created context; want error")
|
||||
}
|
||||
|
||||
if !regexp.MustCompile(`provider ".+" is not available`).MatchString(diags.Err().Error()) {
|
||||
if !regexp.MustCompile(`Failed to instantiate provider ".+"`).MatchString(diags.Err().Error()) {
|
||||
t.Fatalf("wrong error: %s", diags.Err())
|
||||
}
|
||||
}
|
||||
|
@ -1312,27 +1153,16 @@ func TestContext2Refresh_vars(t *testing.T) {
|
|||
}
|
||||
|
||||
m := testModule(t, "refresh-vars")
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.web", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
})
|
||||
|
||||
readStateVal, err := schema.CoerceValue(cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -1397,85 +1227,37 @@ func TestContext2Refresh_orphanModule(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "i-abc123",
|
||||
Attributes: map[string]string{
|
||||
"id": "i-abc123",
|
||||
"childid": "i-bcd234",
|
||||
"grandchildid": "i-cde345",
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("aws_instance.foo").Resource,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"i-abc123"}`),
|
||||
Dependencies: []addrs.ConfigResource{
|
||||
addrs.ConfigResource{Module: addrs.Module{"module.child"}},
|
||||
addrs.ConfigResource{Module: addrs.Module{"module.child"}},
|
||||
},
|
||||
},
|
||||
Dependencies: []string{
|
||||
"module.child",
|
||||
"module.child",
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`),
|
||||
)
|
||||
child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey))
|
||||
child.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("aws_instance.bar").Resource,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"i-bcd23"}`),
|
||||
Dependencies: []addrs.ConfigResource{addrs.ConfigResource{Module: addrs.Module{"module.grandchild"}}},
|
||||
},
|
||||
Provider: "provider.aws",
|
||||
},
|
||||
},
|
||||
},
|
||||
&ModuleState{
|
||||
Path: append(rootModulePath, "child"),
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.bar": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "i-bcd234",
|
||||
Attributes: map[string]string{
|
||||
"id": "i-bcd234",
|
||||
"grandchildid": "i-cde345",
|
||||
},
|
||||
},
|
||||
Dependencies: []string{
|
||||
"module.grandchild",
|
||||
},
|
||||
Provider: "provider.aws",
|
||||
},
|
||||
},
|
||||
Outputs: map[string]*OutputState{
|
||||
"id": &OutputState{
|
||||
Value: "i-bcd234",
|
||||
Type: "string",
|
||||
},
|
||||
"grandchild_id": &OutputState{
|
||||
Value: "i-cde345",
|
||||
Type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
&ModuleState{
|
||||
Path: append(rootModulePath, "child", "grandchild"),
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.baz": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "i-cde345",
|
||||
Attributes: map[string]string{
|
||||
"id": "i-cde345",
|
||||
},
|
||||
},
|
||||
Provider: "provider.aws",
|
||||
},
|
||||
},
|
||||
Outputs: map[string]*OutputState{
|
||||
"id": &OutputState{
|
||||
Value: "i-cde345",
|
||||
Type: "string",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/aws"]`),
|
||||
)
|
||||
grandchild := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey).Child("grandchild", addrs.NoKey))
|
||||
testSetResourceInstanceCurrent(grandchild, "aws_instance.baz", `{"id":"i-cde345"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -1483,7 +1265,7 @@ func TestContext2Refresh_orphanModule(t *testing.T) {
|
|||
testCheckDeadlock(t, func() {
|
||||
_, err := ctx.Refresh()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
t.Fatalf("err: %s", err.Err())
|
||||
}
|
||||
|
||||
// TODO: handle order properly for orphaned modules / resources
|
||||
|
@ -1518,7 +1300,7 @@ func TestContext2Validate(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1543,43 +1325,16 @@ func TestContext2Refresh_noDiffHookOnScaleOut(t *testing.T) {
|
|||
// we need to make DiffFn available to let that complete.
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo.0": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Deposed: []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"id": "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"aws_instance.foo.1": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Deposed: []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"id": "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.foo[0]", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.foo[1]", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Hooks: []Hook{h},
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -1602,45 +1357,29 @@ func TestContext2Refresh_updateProviderInState(t *testing.T) {
|
|||
p.DiffFn = testDiffFn
|
||||
p.ApplyFn = testApplyFn
|
||||
|
||||
s := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.bar": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"id": "foo",
|
||||
},
|
||||
},
|
||||
Provider: "provider.aws.baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.bar", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/aws"].baz`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: s,
|
||||
State: state,
|
||||
})
|
||||
|
||||
expected := strings.TrimSpace(`
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
provider = provider["registry.terraform.io/-/aws"].foo`)
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"].foo`)
|
||||
|
||||
state, diags := ctx.Refresh()
|
||||
s, diags := ctx.Refresh()
|
||||
if diags.HasErrors() {
|
||||
t.Fatal(diags.Err())
|
||||
}
|
||||
|
||||
actual := state.String()
|
||||
actual := s.String()
|
||||
if actual != expected {
|
||||
t.Fatalf("expected:\n%s\n\ngot:\n%s", expected, actual)
|
||||
}
|
||||
|
@ -1685,7 +1424,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
|
|||
},
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("test"),
|
||||
Provider: addrs.NewDefaultProvider("test"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -1694,7 +1433,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: s,
|
||||
})
|
||||
|
@ -1723,7 +1462,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) {
|
|||
want := strings.TrimSpace(`
|
||||
test_thing.bar:
|
||||
ID =
|
||||
provider = provider["registry.terraform.io/-/test"]
|
||||
provider = provider["registry.terraform.io/hashicorp/test"]
|
||||
name = foo
|
||||
`)
|
||||
if got != want {
|
||||
|
@ -1769,7 +1508,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"foo"}`),
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("test"),
|
||||
Provider: addrs.NewDefaultProvider("test"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -1778,7 +1517,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: s,
|
||||
})
|
||||
|
@ -1805,7 +1544,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) {
|
|||
want := strings.TrimSpace(`
|
||||
test_thing.bar:
|
||||
ID =
|
||||
provider = provider["registry.terraform.io/-/test"]
|
||||
provider = provider["registry.terraform.io/hashicorp/test"]
|
||||
name = foo
|
||||
`)
|
||||
if got != want {
|
||||
|
@ -1836,7 +1575,7 @@ data "aws_data_source" "foo" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1874,32 +1613,16 @@ func TestContext2Refresh_dataResourceDependsOn(t *testing.T) {
|
|||
}
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
s := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"test_resource.a": &ResourceState{
|
||||
Type: "test_resource",
|
||||
Provider: "provider.test",
|
||||
Primary: &InstanceState{
|
||||
ID: "a",
|
||||
Attributes: map[string]string{
|
||||
"id": "a",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "test_resource.a", `{"id":"a"}`, `provider["registry.terraform.io/hashicorp/test"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: s,
|
||||
State: state,
|
||||
})
|
||||
|
||||
_, diags := ctx.Refresh()
|
||||
|
@ -1934,7 +1657,7 @@ func TestRefresh_updateDependencies(t *testing.T) {
|
|||
},
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -1949,7 +1672,7 @@ func TestRefresh_updateDependencies(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"bar","foo":"foo"}`),
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -1971,7 +1694,7 @@ resource "aws_instance" "foo" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -1984,14 +1707,14 @@ resource "aws_instance" "foo" {
|
|||
expect := strings.TrimSpace(`
|
||||
aws_instance.bar:
|
||||
ID = bar
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
foo = foo
|
||||
|
||||
Dependencies:
|
||||
aws_instance.foo
|
||||
aws_instance.foo:
|
||||
ID = foo
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
|
||||
Dependencies:
|
||||
aws_instance.baz
|
||||
|
|
|
@ -1086,18 +1086,18 @@ root
|
|||
const testContextRefreshModuleStr = `
|
||||
aws_instance.web: (tainted)
|
||||
ID = bar
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
|
||||
module.child:
|
||||
aws_instance.web:
|
||||
ID = new
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
`
|
||||
|
||||
const testContextRefreshOutputStr = `
|
||||
aws_instance.web:
|
||||
ID = foo
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
foo = bar
|
||||
|
||||
Outputs:
|
||||
|
@ -1112,5 +1112,5 @@ const testContextRefreshOutputPartialStr = `
|
|||
const testContextRefreshTaintedStr = `
|
||||
aws_instance.web: (tainted)
|
||||
ID = foo
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
`
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestContext2Validate_badCount(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -57,7 +57,7 @@ func TestContext2Validate_badVar(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -86,7 +86,7 @@ func TestContext2Validate_varMapOverrideOld(t *testing.T) {
|
|||
_, diags := NewContext(&ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Variables: InputValues{},
|
||||
})
|
||||
|
@ -136,8 +136,8 @@ func TestContext2Validate_computedVar(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(pt),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(pt),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -183,7 +183,7 @@ func TestContext2Validate_computedInFunction(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -218,7 +218,7 @@ func TestContext2Validate_countComputed(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -242,7 +242,7 @@ func TestContext2Validate_countNegative(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -268,7 +268,7 @@ func TestContext2Validate_countVariable(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -294,7 +294,7 @@ func TestContext2Validate_countVariableNoDefault(t *testing.T) {
|
|||
_, diags := NewContext(&ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
if !diags.HasErrors() {
|
||||
|
@ -319,7 +319,7 @@ func TestContext2Validate_moduleBadOutput(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -345,7 +345,7 @@ func TestContext2Validate_moduleGood(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -369,7 +369,7 @@ func TestContext2Validate_moduleBadResource(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -399,7 +399,7 @@ func TestContext2Validate_moduleDepsShouldNotCycle(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -430,7 +430,7 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Variables: InputValues{
|
||||
"provider_var": &InputValue{
|
||||
|
@ -471,7 +471,7 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -499,25 +499,15 @@ func TestContext2Validate_orphans(t *testing.T) {
|
|||
}
|
||||
|
||||
m := testModule(t, "validate-good")
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.web": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.web", `{"id":"bar"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -557,7 +547,7 @@ func TestContext2Validate_providerConfig_bad(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -593,7 +583,7 @@ func TestContext2Validate_providerConfig_badEmpty(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -626,7 +616,7 @@ func TestContext2Validate_providerConfig_good(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -654,7 +644,7 @@ func TestContext2Validate_provisionerConfig_bad(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
|
@ -689,7 +679,7 @@ func TestContext2Validate_badResourceConnection(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
|
@ -721,7 +711,7 @@ func TestContext2Validate_badProvisionerConnection(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
|
@ -767,7 +757,7 @@ func TestContext2Validate_provisionerConfig_good(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
|
@ -796,7 +786,7 @@ func TestContext2Validate_requiredVar(t *testing.T) {
|
|||
_, diags := NewContext(&ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
if !diags.HasErrors() {
|
||||
|
@ -821,7 +811,7 @@ func TestContext2Validate_resourceConfig_bad(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -851,7 +841,7 @@ func TestContext2Validate_resourceConfig_good(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -875,26 +865,14 @@ func TestContext2Validate_tainted(t *testing.T) {
|
|||
}
|
||||
|
||||
m := testModule(t, "validate-good")
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
Tainted: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceTainted(root, "aws_instance.foo", `{"id":"bar"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
@ -932,25 +910,20 @@ func TestContext2Validate_targetedDestroy(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.foo", `{"id":"i-bcd345"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
testSetResourceInstanceCurrent(root, "aws_instance.bar", `{"id":"i-abc123"}`, `provider["registry.terraform.io/hashicorp/aws"]`)
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
},
|
||||
State: MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.foo": resourceState("aws_instance", "i-bcd345"),
|
||||
"aws_instance.bar": resourceState("aws_instance", "i-abc123"),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
State: state,
|
||||
Targets: []addrs.Targetable{
|
||||
addrs.RootModuleInstance.Resource(
|
||||
addrs.ManagedResourceMode, "aws_instance", "foo",
|
||||
|
@ -980,7 +953,7 @@ func TestContext2Validate_varRefUnknown(t *testing.T) {
|
|||
c := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
Variables: InputValues{
|
||||
"foo": &InputValue{
|
||||
|
@ -1028,7 +1001,7 @@ func TestContext2Validate_interpolateVar(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("template"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("template"): testProviderFuncFixed(p),
|
||||
},
|
||||
UIInput: input,
|
||||
})
|
||||
|
@ -1061,7 +1034,7 @@ func TestContext2Validate_interpolateComputedModuleVarDef(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
UIInput: input,
|
||||
})
|
||||
|
@ -1084,7 +1057,7 @@ func TestContext2Validate_interpolateMap(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("template"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("template"): testProviderFuncFixed(p),
|
||||
},
|
||||
UIInput: input,
|
||||
})
|
||||
|
@ -1162,7 +1135,7 @@ output "out" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1199,7 +1172,7 @@ resource "aws_instance" "foo" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1228,7 +1201,7 @@ output "out" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1259,7 +1232,7 @@ output "out" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1290,7 +1263,7 @@ output "out" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1320,7 +1293,7 @@ resource "test_instance" "bar" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1353,7 +1326,7 @@ resource "test_instance" "bar" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1378,7 +1351,7 @@ func TestContext2Validate_variableCustomValidationsFail(t *testing.T) {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1421,7 +1394,7 @@ variable "test" {
|
|||
ctx := testContext2(t, &ContextOpts{
|
||||
Config: m,
|
||||
Providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): testProviderFuncFixed(p),
|
||||
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||
},
|
||||
Variables: InputValues{
|
||||
"test": &InputValue{
|
||||
|
|
|
@ -26,11 +26,11 @@ func TestBuiltinEvalContextProviderInput(t *testing.T) {
|
|||
|
||||
providerAddr1 := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewLegacyProvider("foo"),
|
||||
Provider: addrs.NewDefaultProvider("foo"),
|
||||
}
|
||||
providerAddr2 := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule.Child("child"),
|
||||
Provider: addrs.NewLegacyProvider("foo"),
|
||||
Provider: addrs.NewDefaultProvider("foo"),
|
||||
}
|
||||
|
||||
expected1 := map[string]cty.Value{"value": cty.StringVal("foo")}
|
||||
|
@ -61,17 +61,17 @@ func TestBuildingEvalContextInitProvider(t *testing.T) {
|
|||
ctx.ProviderCache = make(map[string]providers.Interface)
|
||||
ctx.Components = &basicComponentFactory{
|
||||
providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): providers.FactoryFixed(testP),
|
||||
addrs.NewDefaultProvider("test"): providers.FactoryFixed(testP),
|
||||
},
|
||||
}
|
||||
|
||||
providerAddrDefault := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewLegacyProvider("test"),
|
||||
Provider: addrs.NewDefaultProvider("test"),
|
||||
}
|
||||
providerAddrAlias := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewLegacyProvider("test"),
|
||||
Provider: addrs.NewDefaultProvider("test"),
|
||||
Alias: "foo",
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestBuildProviderConfig(t *testing.T) {
|
|||
})
|
||||
providerAddr := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewLegacyProvider("foo"),
|
||||
Provider: addrs.NewDefaultProvider("foo"),
|
||||
}
|
||||
|
||||
ctx := &MockEvalContext{
|
||||
|
@ -70,7 +70,7 @@ func TestEvalConfigProvider(t *testing.T) {
|
|||
rp := providers.Interface(provider)
|
||||
providerAddr := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewLegacyProvider("foo"),
|
||||
Provider: addrs.NewDefaultProvider("foo"),
|
||||
}
|
||||
n := &EvalConfigProvider{
|
||||
Addr: providerAddr,
|
||||
|
@ -104,7 +104,7 @@ func TestEvalInitProvider_impl(t *testing.T) {
|
|||
func TestEvalInitProvider(t *testing.T) {
|
||||
providerAddr := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewLegacyProvider("foo"),
|
||||
Provider: addrs.NewDefaultProvider("foo"),
|
||||
}
|
||||
n := &EvalInitProvider{
|
||||
Addr: providerAddr,
|
||||
|
@ -118,7 +118,7 @@ func TestEvalInitProvider(t *testing.T) {
|
|||
if !ctx.InitProviderCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if ctx.InitProviderAddr.String() != `provider["registry.terraform.io/-/foo"]` {
|
||||
if ctx.InitProviderAddr.String() != `provider["registry.terraform.io/hashicorp/foo"]` {
|
||||
t.Fatalf("wrong provider address %s", ctx.InitProviderAddr)
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func TestEvalInitProvider(t *testing.T) {
|
|||
func TestEvalCloseProvider(t *testing.T) {
|
||||
providerAddr := addrs.AbsProviderConfig{
|
||||
Module: addrs.RootModule,
|
||||
Provider: addrs.NewLegacyProvider("foo"),
|
||||
Provider: addrs.NewDefaultProvider("foo"),
|
||||
}
|
||||
n := &EvalCloseProvider{
|
||||
Addr: providerAddr,
|
||||
|
@ -140,7 +140,7 @@ func TestEvalCloseProvider(t *testing.T) {
|
|||
if !ctx.CloseProviderCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if ctx.CloseProviderAddr.String() != `provider["registry.terraform.io/-/foo"]` {
|
||||
if ctx.CloseProviderAddr.String() != `provider["registry.terraform.io/hashicorp/foo"]` {
|
||||
t.Fatalf("wrong provider address %s", ctx.CloseProviderAddr)
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func TestEvalGetProvider_impl(t *testing.T) {
|
|||
func TestEvalGetProvider(t *testing.T) {
|
||||
var actual providers.Interface
|
||||
n := &EvalGetProvider{
|
||||
Addr: addrs.RootModuleInstance.ProviderConfigDefault(addrs.NewLegacyProvider("foo")),
|
||||
Addr: addrs.RootModuleInstance.ProviderConfigDefault(addrs.NewDefaultProvider("foo")),
|
||||
Output: &actual,
|
||||
}
|
||||
provider := &MockProvider{}
|
||||
|
@ -167,7 +167,7 @@ func TestEvalGetProvider(t *testing.T) {
|
|||
if !ctx.ProviderCalled {
|
||||
t.Fatal("should be called")
|
||||
}
|
||||
if ctx.ProviderAddr.String() != `provider["registry.terraform.io/-/foo"]` {
|
||||
if ctx.ProviderAddr.String() != `provider["registry.terraform.io/hashicorp/foo"]` {
|
||||
t.Fatalf("wrong provider address %s", ctx.ProviderAddr)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ func TestEvalWriteState(t *testing.T) {
|
|||
State: &obj,
|
||||
|
||||
ProviderSchema: &providerSchema,
|
||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault(addrs.NewLegacyProvider("aws")),
|
||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault(addrs.NewDefaultProvider("aws")),
|
||||
}
|
||||
_, err := node.Eval(ctx)
|
||||
if err != nil {
|
||||
|
@ -224,7 +224,7 @@ func TestEvalWriteState(t *testing.T) {
|
|||
checkStateString(t, state, `
|
||||
aws_instance.foo:
|
||||
ID = i-abc123
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
`)
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ func TestEvalWriteStateDeposed(t *testing.T) {
|
|||
State: &obj,
|
||||
|
||||
ProviderSchema: &providerSchema,
|
||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault(addrs.NewLegacyProvider("aws")),
|
||||
ProviderAddr: addrs.RootModuleInstance.ProviderConfigDefault(addrs.NewDefaultProvider("aws")),
|
||||
}
|
||||
_, err := node.Eval(ctx)
|
||||
if err != nil {
|
||||
|
@ -271,7 +271,7 @@ func TestEvalWriteStateDeposed(t *testing.T) {
|
|||
checkStateString(t, state, `
|
||||
aws_instance.foo: (1 deposed)
|
||||
ID = <not created>
|
||||
provider = provider["registry.terraform.io/-/aws"]
|
||||
provider = provider["registry.terraform.io/hashicorp/aws"]
|
||||
Deposed ID 1 = i-abc123
|
||||
`)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ For example, to correlate with indices of a referring resource, use:
|
|||
Config: cfg,
|
||||
Schemas: &Schemas{
|
||||
Providers: map[addrs.Provider]*ProviderSchema{
|
||||
addrs.NewLegacyProvider("aws"): {
|
||||
addrs.NewDefaultProvider("aws"): {
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": {},
|
||||
},
|
||||
|
|
|
@ -97,7 +97,7 @@ func TestApplyGraphBuilder_depCbd(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B").Resource,
|
||||
|
@ -106,7 +106,7 @@ func TestApplyGraphBuilder_depCbd(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
b := &ApplyGraphBuilder{
|
||||
|
@ -266,7 +266,7 @@ func TestApplyGraphBuilder_destroyStateOnly(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"foo"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
child.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B").Resource,
|
||||
|
@ -275,7 +275,7 @@ func TestApplyGraphBuilder_destroyStateOnly(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"bar"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
b := &ApplyGraphBuilder{
|
||||
|
@ -370,7 +370,7 @@ func TestApplyGraphBuilder_moduleDestroy(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"foo"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
modB := state.EnsureModule(addrs.RootModuleInstance.Child("B", addrs.NoKey))
|
||||
modB.SetResourceInstanceCurrent(
|
||||
|
@ -380,7 +380,7 @@ func TestApplyGraphBuilder_moduleDestroy(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"foo","value":"foo"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("module.A.test_object.foo")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
b := &ApplyGraphBuilder{
|
||||
|
@ -508,7 +508,7 @@ func TestApplyGraphBuilder_targetModule(t *testing.T) {
|
|||
// that resource is destroyed.
|
||||
func TestApplyGraphBuilder_updateFromOrphan(t *testing.T) {
|
||||
schemas := simpleTestSchemas()
|
||||
instanceSchema := schemas.Providers[addrs.NewLegacyProvider("test")].ResourceTypes["test_object"]
|
||||
instanceSchema := schemas.Providers[addrs.NewDefaultProvider("test")].ResourceTypes["test_object"]
|
||||
|
||||
bBefore, _ := plans.NewDynamicValue(
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -553,7 +553,7 @@ func TestApplyGraphBuilder_updateFromOrphan(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"a_id"}`),
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("test"),
|
||||
Provider: addrs.NewDefaultProvider("test"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -578,7 +578,7 @@ func TestApplyGraphBuilder_updateFromOrphan(t *testing.T) {
|
|||
},
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("test"),
|
||||
Provider: addrs.NewDefaultProvider("test"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -614,7 +614,7 @@ test_object.b
|
|||
// a CBD resource is destroyed.
|
||||
func TestApplyGraphBuilder_updateFromCBDOrphan(t *testing.T) {
|
||||
schemas := simpleTestSchemas()
|
||||
instanceSchema := schemas.Providers[addrs.NewLegacyProvider("test")].ResourceTypes["test_object"]
|
||||
instanceSchema := schemas.Providers[addrs.NewDefaultProvider("test")].ResourceTypes["test_object"]
|
||||
|
||||
bBefore, _ := plans.NewDynamicValue(
|
||||
cty.ObjectVal(map[string]cty.Value{
|
||||
|
@ -659,7 +659,7 @@ func TestApplyGraphBuilder_updateFromCBDOrphan(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"a_id"}`),
|
||||
CreateBeforeDestroy: true,
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
addrs.Resource{
|
||||
|
@ -681,7 +681,7 @@ func TestApplyGraphBuilder_updateFromCBDOrphan(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
b := &ApplyGraphBuilder{
|
||||
|
@ -732,7 +732,7 @@ func TestApplyGraphBuilder_orphanedWithProvider(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"].foo`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"].foo`),
|
||||
)
|
||||
|
||||
b := &ApplyGraphBuilder{
|
||||
|
@ -764,16 +764,16 @@ module.child.test_object.create
|
|||
module.child.test_object.create (prepare state)
|
||||
module.child.test_object.create (prepare state)
|
||||
module.child
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
provisioner.test
|
||||
module.child.test_object.other
|
||||
module.child.test_object.create
|
||||
module.child.test_object.other (prepare state)
|
||||
module.child.test_object.other (prepare state)
|
||||
module.child
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
module.child.test_object.other
|
||||
test_object.other
|
||||
provisioner.test
|
||||
|
@ -781,36 +781,36 @@ provisioner.test (close)
|
|||
module.child.test_object.create
|
||||
root
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
provisioner.test (close)
|
||||
test_object.create
|
||||
test_object.create (prepare state)
|
||||
test_object.create (prepare state)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_object.other
|
||||
test_object.create
|
||||
test_object.other (prepare state)
|
||||
test_object.other (prepare state)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
`
|
||||
|
||||
const testApplyGraphBuilderDestroyCountStr = `
|
||||
meta.count-boundary (EachMode fixup)
|
||||
test_object.B
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
test_object.B
|
||||
root
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
test_object.A (prepare state)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_object.A[1] (destroy)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_object.B
|
||||
test_object.A (prepare state)
|
||||
test_object.A[1] (destroy)
|
||||
test_object.B (prepare state)
|
||||
test_object.B (prepare state)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
`
|
||||
|
|
|
@ -35,8 +35,8 @@ func TestPlanGraphBuilder(t *testing.T) {
|
|||
}
|
||||
components := &basicComponentFactory{
|
||||
providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): providers.FactoryFixed(awsProvider),
|
||||
addrs.NewLegacyProvider("openstack"): providers.FactoryFixed(openstackProvider),
|
||||
addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider),
|
||||
addrs.NewDefaultProvider("openstack"): providers.FactoryFixed(openstackProvider),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -45,8 +45,8 @@ func TestPlanGraphBuilder(t *testing.T) {
|
|||
Components: components,
|
||||
Schemas: &Schemas{
|
||||
Providers: map[addrs.Provider]*ProviderSchema{
|
||||
addrs.NewLegacyProvider("aws"): awsProvider.GetSchemaReturn,
|
||||
addrs.NewLegacyProvider("openstack"): openstackProvider.GetSchemaReturn,
|
||||
addrs.NewDefaultProvider("aws"): awsProvider.GetSchemaReturn,
|
||||
addrs.NewDefaultProvider("openstack"): openstackProvider.GetSchemaReturn,
|
||||
},
|
||||
},
|
||||
DisableReduce: true,
|
||||
|
@ -93,7 +93,7 @@ func TestPlanGraphBuilder_dynamicBlock(t *testing.T) {
|
|||
}
|
||||
components := &basicComponentFactory{
|
||||
providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): providers.FactoryFixed(provider),
|
||||
addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ func TestPlanGraphBuilder_dynamicBlock(t *testing.T) {
|
|||
Components: components,
|
||||
Schemas: &Schemas{
|
||||
Providers: map[addrs.Provider]*ProviderSchema{
|
||||
addrs.NewLegacyProvider("test"): provider.GetSchemaReturn,
|
||||
addrs.NewDefaultProvider("test"): provider.GetSchemaReturn,
|
||||
},
|
||||
},
|
||||
DisableReduce: true,
|
||||
|
@ -125,25 +125,25 @@ func TestPlanGraphBuilder_dynamicBlock(t *testing.T) {
|
|||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(`
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.a
|
||||
test_thing.b
|
||||
test_thing.c
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.a
|
||||
test_thing.b
|
||||
test_thing.c
|
||||
root
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
test_thing.a
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.b
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.c
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.a
|
||||
test_thing.b
|
||||
`)
|
||||
|
@ -172,7 +172,7 @@ func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) {
|
|||
}
|
||||
components := &basicComponentFactory{
|
||||
providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("test"): providers.FactoryFixed(provider),
|
||||
addrs.NewDefaultProvider("test"): providers.FactoryFixed(provider),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) {
|
|||
Components: components,
|
||||
Schemas: &Schemas{
|
||||
Providers: map[addrs.Provider]*ProviderSchema{
|
||||
addrs.NewLegacyProvider("test"): provider.GetSchemaReturn,
|
||||
addrs.NewDefaultProvider("test"): provider.GetSchemaReturn,
|
||||
},
|
||||
},
|
||||
DisableReduce: true,
|
||||
|
@ -204,21 +204,21 @@ func TestPlanGraphBuilder_attrAsBlocks(t *testing.T) {
|
|||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(`
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.a
|
||||
test_thing.b
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.a
|
||||
test_thing.b
|
||||
root
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/test"] (close)
|
||||
provider["registry.terraform.io/hashicorp/test"] (close)
|
||||
test_thing.a
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.b
|
||||
provider["registry.terraform.io/-/test"]
|
||||
provider["registry.terraform.io/hashicorp/test"]
|
||||
test_thing.a
|
||||
`)
|
||||
if actual != expected {
|
||||
|
@ -243,7 +243,7 @@ func TestPlanGraphBuilder_targetModule(t *testing.T) {
|
|||
|
||||
t.Logf("Graph: %s", g.String())
|
||||
|
||||
testGraphNotContains(t, g, `module.child1.provider["registry.terraform.io/-/test"]`)
|
||||
testGraphNotContains(t, g, `module.child1.provider["registry.terraform.io/hashicorp/test"]`)
|
||||
testGraphNotContains(t, g, "module.child1.test_object.foo")
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ func TestPlanGraphBuilder_forEach(t *testing.T) {
|
|||
|
||||
components := &basicComponentFactory{
|
||||
providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider("aws"): providers.FactoryFixed(awsProvider),
|
||||
addrs.NewDefaultProvider("aws"): providers.FactoryFixed(awsProvider),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,7 @@ func TestPlanGraphBuilder_forEach(t *testing.T) {
|
|||
Components: components,
|
||||
Schemas: &Schemas{
|
||||
Providers: map[addrs.Provider]*ProviderSchema{
|
||||
addrs.NewLegacyProvider("aws"): awsProvider.GetSchemaReturn,
|
||||
addrs.NewDefaultProvider("aws"): awsProvider.GetSchemaReturn,
|
||||
},
|
||||
},
|
||||
DisableReduce: true,
|
||||
|
@ -295,13 +295,13 @@ func TestPlanGraphBuilder_forEach(t *testing.T) {
|
|||
const testPlanGraphBuilderStr = `
|
||||
aws_instance.web
|
||||
aws_security_group.firewall
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
var.foo
|
||||
aws_load_balancer.weblb
|
||||
aws_instance.web
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
aws_security_group.firewall
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
local.instance_id
|
||||
aws_instance.web
|
||||
meta.count-boundary (EachMode fixup)
|
||||
|
@ -311,44 +311,44 @@ meta.count-boundary (EachMode fixup)
|
|||
local.instance_id
|
||||
openstack_floating_ip.random
|
||||
output.instance_id
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/openstack"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/openstack"]
|
||||
var.foo
|
||||
openstack_floating_ip.random
|
||||
provider["registry.terraform.io/-/openstack"]
|
||||
provider["registry.terraform.io/hashicorp/openstack"]
|
||||
output.instance_id
|
||||
local.instance_id
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
openstack_floating_ip.random
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
aws_instance.web
|
||||
aws_load_balancer.weblb
|
||||
aws_security_group.firewall
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/openstack"]
|
||||
provider["registry.terraform.io/-/openstack"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/openstack"]
|
||||
provider["registry.terraform.io/hashicorp/openstack"] (close)
|
||||
openstack_floating_ip.random
|
||||
provider["registry.terraform.io/-/openstack"]
|
||||
provider["registry.terraform.io/hashicorp/openstack"]
|
||||
root
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/-/openstack"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/openstack"] (close)
|
||||
var.foo
|
||||
`
|
||||
const testPlanGraphBuilderForEachStr = `
|
||||
aws_instance.bar
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
aws_instance.bar2
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
aws_instance.bat
|
||||
aws_instance.boo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
aws_instance.baz
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
aws_instance.boo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
aws_instance.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
meta.count-boundary (EachMode fixup)
|
||||
aws_instance.bar
|
||||
aws_instance.bar2
|
||||
|
@ -356,17 +356,17 @@ meta.count-boundary (EachMode fixup)
|
|||
aws_instance.baz
|
||||
aws_instance.boo
|
||||
aws_instance.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
aws_instance.bar
|
||||
aws_instance.bar2
|
||||
aws_instance.bat
|
||||
aws_instance.baz
|
||||
aws_instance.boo
|
||||
aws_instance.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
root
|
||||
meta.count-boundary (EachMode fixup)
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
`
|
||||
|
|
|
@ -5,69 +5,24 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
"github.com/hashicorp/terraform/states"
|
||||
)
|
||||
|
||||
func TestRefreshGraphBuilder_configOrphans(t *testing.T) {
|
||||
|
||||
m := testModule(t, "refresh-config-orphan")
|
||||
|
||||
state := MustShimLegacyState(&State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"test_object.foo.0": &ResourceState{
|
||||
Type: "test_object",
|
||||
Deposed: []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
"test_object.foo.1": &ResourceState{
|
||||
Type: "test_object",
|
||||
Deposed: []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
"test_object.foo.2": &ResourceState{
|
||||
Type: "test_object",
|
||||
Deposed: []*InstanceState{
|
||||
&InstanceState{
|
||||
ID: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
"data.test_object.foo.0": &ResourceState{
|
||||
Type: "test_object",
|
||||
Deposed: []*InstanceState{ // NOTE: Real-world data resources don't get deposed
|
||||
&InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
"data.test_object.foo.1": &ResourceState{
|
||||
Type: "test_object",
|
||||
Deposed: []*InstanceState{ // NOTE: Real-world data resources don't get deposed
|
||||
&InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
"data.test_object.foo.2": &ResourceState{
|
||||
Type: "test_object",
|
||||
Deposed: []*InstanceState{ // NOTE: Real-world data resources don't get deposed
|
||||
&InstanceState{
|
||||
ID: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
state := states.NewState()
|
||||
root := state.EnsureModule(addrs.RootModuleInstance)
|
||||
deposedKey := states.DeposedKey("00000001")
|
||||
testSetResourceInstanceDeposed(root, "test_object.foo[0]", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/test"]`, deposedKey)
|
||||
testSetResourceInstanceDeposed(root, "test_object.foo[1]", `{"id":"bar"}`, `provider["registry.terraform.io/hashicorp/test"]`, deposedKey)
|
||||
testSetResourceInstanceDeposed(root, "test_object.foo[2]", `{"id":"baz"}`, `provider["registry.terraform.io/hashicorp/test"]`, deposedKey)
|
||||
|
||||
// NOTE: Real-world data resources don't get deposed
|
||||
testSetResourceInstanceDeposed(root, "data.test_object.foo[0]", `{"id":"foo"}`, `provider["registry.terraform.io/hashicorp/test"]`, deposedKey)
|
||||
testSetResourceInstanceDeposed(root, "data.test_object.foo[1]", `{"id":"bar"}`, `provider["registry.terraform.io/hashicorp/test"]`, deposedKey)
|
||||
testSetResourceInstanceDeposed(root, "data.test_object.foo[2]", `{"id":"baz"}`, `provider["registry.terraform.io/hashicorp/test"]`, deposedKey)
|
||||
|
||||
b := &RefreshGraphBuilder{
|
||||
Config: m,
|
||||
|
@ -83,19 +38,19 @@ func TestRefreshGraphBuilder_configOrphans(t *testing.T) {
|
|||
actual := strings.TrimSpace(g.StringWithNodeTypes())
|
||||
expected := strings.TrimSpace(`
|
||||
data.test_object.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
data.test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
data.test_object.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
data.test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
data.test_object.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
data.test_object.foo[2] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/-/test"] (close) - *terraform.graphNodeCloseProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] (close) - *terraform.graphNodeCloseProvider
|
||||
data.test_object.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
|
||||
data.test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
data.test_object.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
|
||||
|
@ -109,13 +64,13 @@ provider["registry.terraform.io/-/test"] (close) - *terraform.graphNodeCloseProv
|
|||
root - *terraform.nodeCloseModule
|
||||
provider["registry.terraform.io/-/test"] (close) - *terraform.graphNodeCloseProvider
|
||||
test_object.foo - *terraform.nodeExpandRefreshableManagedResource
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
test_object.foo[2] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
provider["registry.terraform.io/hashicorp/test"] - *terraform.NodeApplyableProvider
|
||||
`)
|
||||
if expected != actual {
|
||||
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
|
||||
|
|
|
@ -1,211 +0,0 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
version "github.com/hashicorp/go-version"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
"github.com/hashicorp/terraform/configs"
|
||||
"github.com/hashicorp/terraform/moduledeps"
|
||||
"github.com/hashicorp/terraform/plugin/discovery"
|
||||
"github.com/hashicorp/terraform/states"
|
||||
)
|
||||
|
||||
// ConfigTreeDependencies returns the dependencies of the tree of modules
|
||||
// described by the given configuration and state.
|
||||
//
|
||||
// Both configuration and state are required because there can be resources
|
||||
// implied by instances in the state that no longer exist in config.
|
||||
func ConfigTreeDependencies(root *configs.Config, state *states.State) *moduledeps.Module {
|
||||
// First we walk the configuration tree to build the overall structure
|
||||
// and capture the explicit/implicit/inherited provider dependencies.
|
||||
deps := configTreeConfigDependencies(root, nil)
|
||||
|
||||
// Next we walk over the resources in the state to catch any additional
|
||||
// dependencies created by existing resources that are no longer in config.
|
||||
// Most things we find in state will already be present in 'deps', but
|
||||
// we're interested in the rare thing that isn't.
|
||||
configTreeMergeStateDependencies(deps, state)
|
||||
|
||||
return deps
|
||||
}
|
||||
|
||||
func configTreeConfigDependencies(root *configs.Config, inheritProviders map[string]*configs.Provider) *moduledeps.Module {
|
||||
if root == nil {
|
||||
// If no config is provided, we'll make a synthetic root.
|
||||
// This isn't necessarily correct if we're called with a nil that
|
||||
// *isn't* at the root, but in practice that can never happen.
|
||||
return &moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: make(moduledeps.Providers),
|
||||
}
|
||||
}
|
||||
|
||||
name := "root"
|
||||
if len(root.Path) != 0 {
|
||||
name = root.Path[len(root.Path)-1]
|
||||
}
|
||||
|
||||
ret := &moduledeps.Module{
|
||||
Name: name,
|
||||
}
|
||||
|
||||
module := root.Module
|
||||
|
||||
// Provider dependencies
|
||||
{
|
||||
providers := make(moduledeps.Providers)
|
||||
|
||||
// The main way to declare a provider dependency is explicitly inside
|
||||
// the "terraform" block, which allows declaring a requirement without
|
||||
// also creating a configuration.
|
||||
for localName, req := range module.ProviderRequirements {
|
||||
// The handling here is a bit fiddly because the moduledeps package
|
||||
// was designed around the legacy (pre-0.12) configuration model
|
||||
// and hasn't yet been revised to handle the new model. As a result,
|
||||
// we need to do some translation here.
|
||||
// FIXME: Eventually we should adjust the underlying model so we
|
||||
// can also retain the source location of each constraint, for
|
||||
// more informative output from the "terraform providers" command.
|
||||
var rawConstraints version.Constraints
|
||||
for _, constraint := range req.VersionConstraints {
|
||||
rawConstraints = append(rawConstraints, constraint.Required...)
|
||||
}
|
||||
discoConstraints := discovery.NewConstraints(rawConstraints)
|
||||
fqn := req.Type
|
||||
if fqn.IsZero() {
|
||||
fqn = addrs.NewLegacyProvider(localName)
|
||||
}
|
||||
|
||||
providers[req.Type] = moduledeps.ProviderDependency{
|
||||
Constraints: discoConstraints,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
}
|
||||
}
|
||||
|
||||
// Provider configurations can also include version constraints,
|
||||
// allowing for more terse declaration in situations where both a
|
||||
// configuration and a constraint are defined in the same module.
|
||||
for _, pCfg := range module.ProviderConfigs {
|
||||
fqn := module.ProviderForLocalConfig(pCfg.Addr())
|
||||
|
||||
discoConstraints := discovery.AllVersions
|
||||
if pCfg.Version.Required != nil {
|
||||
discoConstraints = discovery.NewConstraints(pCfg.Version.Required)
|
||||
}
|
||||
if existing, exists := providers[fqn]; exists {
|
||||
constraints := existing.Constraints.Append(discoConstraints)
|
||||
providers[fqn] = moduledeps.ProviderDependency{
|
||||
Constraints: constraints,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
}
|
||||
} else {
|
||||
providers[fqn] = moduledeps.ProviderDependency{
|
||||
Constraints: discoConstraints,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Each resource in the configuration creates an *implicit* provider
|
||||
// dependency, though we'll only record it if there isn't already
|
||||
// an explicit dependency on the same provider.
|
||||
for _, rc := range module.ManagedResources {
|
||||
addr := rc.ProviderConfigAddr()
|
||||
fqn := module.ProviderForLocalConfig(addr)
|
||||
|
||||
if _, exists := providers[fqn]; exists {
|
||||
// Explicit dependency already present
|
||||
continue
|
||||
}
|
||||
|
||||
reason := moduledeps.ProviderDependencyImplicit
|
||||
if _, inherited := inheritProviders[addr.StringCompact()]; inherited {
|
||||
reason = moduledeps.ProviderDependencyInherited
|
||||
}
|
||||
|
||||
providers[fqn] = moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: reason,
|
||||
}
|
||||
}
|
||||
for _, rc := range module.DataResources {
|
||||
addr := rc.ProviderConfigAddr()
|
||||
fqn := module.ProviderForLocalConfig(addr)
|
||||
|
||||
if _, exists := providers[fqn]; exists {
|
||||
// Explicit dependency already present
|
||||
continue
|
||||
}
|
||||
|
||||
reason := moduledeps.ProviderDependencyImplicit
|
||||
if _, inherited := inheritProviders[addr.String()]; inherited {
|
||||
reason = moduledeps.ProviderDependencyInherited
|
||||
}
|
||||
|
||||
providers[fqn] = moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: reason,
|
||||
}
|
||||
}
|
||||
|
||||
ret.Providers = providers
|
||||
}
|
||||
|
||||
childInherit := make(map[string]*configs.Provider)
|
||||
for k, v := range inheritProviders {
|
||||
childInherit[k] = v
|
||||
}
|
||||
for k, v := range module.ProviderConfigs {
|
||||
childInherit[k] = v
|
||||
}
|
||||
for _, c := range root.Children {
|
||||
ret.Children = append(ret.Children, configTreeConfigDependencies(c, childInherit))
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func configTreeMergeStateDependencies(root *moduledeps.Module, state *states.State) {
|
||||
if state == nil {
|
||||
return
|
||||
}
|
||||
|
||||
findModule := func(path addrs.ModuleInstance) *moduledeps.Module {
|
||||
module := root
|
||||
for _, step := range path {
|
||||
var next *moduledeps.Module
|
||||
for _, cm := range module.Children {
|
||||
if cm.Name == step.Name {
|
||||
next = cm
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if next == nil {
|
||||
// If we didn't find a next node, we'll need to make one
|
||||
next = &moduledeps.Module{
|
||||
Name: step.Name,
|
||||
Providers: make(moduledeps.Providers),
|
||||
}
|
||||
module.Children = append(module.Children, next)
|
||||
}
|
||||
|
||||
module = next
|
||||
}
|
||||
return module
|
||||
}
|
||||
|
||||
for _, ms := range state.Modules {
|
||||
module := findModule(ms.Addr)
|
||||
|
||||
for _, rs := range ms.Resources {
|
||||
fqn := rs.ProviderConfig.Provider
|
||||
if _, exists := module.Providers[fqn]; !exists {
|
||||
module.Providers[fqn] = moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/hashicorp/terraform/addrs"
|
||||
"github.com/hashicorp/terraform/configs"
|
||||
"github.com/hashicorp/terraform/moduledeps"
|
||||
"github.com/hashicorp/terraform/plugin/discovery"
|
||||
)
|
||||
|
||||
func TestModuleTreeDependencies(t *testing.T) {
|
||||
tests := map[string]struct {
|
||||
ConfigDir string // directory name from testdata dir
|
||||
State *State
|
||||
Want *moduledeps.Module
|
||||
}{
|
||||
"no config or state": {
|
||||
"",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"empty config no state": {
|
||||
"empty",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"explicit provider": {
|
||||
"module-deps-explicit-provider",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0,>=2.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"required_providers block": {
|
||||
"module-deps-required-providers",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"explicit provider unconstrained": {
|
||||
"module-deps-explicit-provider-unconstrained",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"implicit provider": {
|
||||
"module-deps-implicit-provider",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"explicit provider with resource": {
|
||||
"module-deps-explicit-provider-resource",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"inheritance of providers": {
|
||||
"module-deps-inherit-provider",
|
||||
nil,
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
addrs.NewLegacyProvider("bar"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
Children: []*moduledeps.Module{
|
||||
{
|
||||
Name: "child",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyInherited,
|
||||
},
|
||||
addrs.NewLegacyProvider("baz"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyImplicit,
|
||||
},
|
||||
},
|
||||
Children: []*moduledeps.Module{
|
||||
{
|
||||
Name: "grandchild",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("bar"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyInherited,
|
||||
},
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"provider from state": {
|
||||
"empty",
|
||||
&State{
|
||||
Modules: []*ModuleState{
|
||||
{
|
||||
Path: []string{"root"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"foo_bar.baz": {
|
||||
Type: "foo_bar",
|
||||
Provider: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
},
|
||||
},
|
||||
Children: nil,
|
||||
},
|
||||
},
|
||||
"providers in both config and state": {
|
||||
"module-deps-explicit-provider",
|
||||
&State{
|
||||
Modules: []*ModuleState{
|
||||
{
|
||||
Path: []string{"root"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"foo_bar.test1": {
|
||||
Type: "foo_bar",
|
||||
Provider: "",
|
||||
},
|
||||
"baz_bar.test": {
|
||||
Type: "baz_bar",
|
||||
Provider: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
// note that we've skipped root.child intentionally here,
|
||||
// to verify that we'll infer it based on the following
|
||||
// module rather than crashing.
|
||||
{
|
||||
Path: []string{"root", "child", "grandchild"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"banana_skin.test": {
|
||||
Type: "banana_skin",
|
||||
Provider: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&moduledeps.Module{
|
||||
Name: "root",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("foo"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.ConstraintStr(">=1.0.0,>=2.0.0").MustParse(),
|
||||
Reason: moduledeps.ProviderDependencyExplicit,
|
||||
},
|
||||
|
||||
addrs.NewLegacyProvider("baz"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
},
|
||||
},
|
||||
Children: []*moduledeps.Module{
|
||||
{
|
||||
Name: "child",
|
||||
Providers: make(moduledeps.Providers),
|
||||
Children: []*moduledeps.Module{
|
||||
{
|
||||
Name: "grandchild",
|
||||
Providers: moduledeps.Providers{
|
||||
addrs.NewLegacyProvider("banana"): moduledeps.ProviderDependency{
|
||||
Constraints: discovery.AllVersions,
|
||||
Reason: moduledeps.ProviderDependencyFromState,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
var root *configs.Config
|
||||
if test.ConfigDir != "" {
|
||||
root = testModule(t, test.ConfigDir)
|
||||
}
|
||||
|
||||
got := ConfigTreeDependencies(root, MustShimLegacyState(test.State))
|
||||
if !cmp.Equal(got, test.Want) {
|
||||
t.Error(cmp.Diff(got, test.Want))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -126,7 +126,7 @@ func TestNodeRefreshableDataResourceDynamicExpand_scaleIn(t *testing.T) {
|
|||
Addr: addr,
|
||||
Config: m.Module.DataResources["data.aws_instance.foo"],
|
||||
ResolvedProvider: addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestMockResourceProvider_impl(t *testing.T) {
|
|||
func testProviderComponentFactory(name string, provider providers.Interface) *basicComponentFactory {
|
||||
return &basicComponentFactory{
|
||||
providers: map[addrs.Provider]providers.Factory{
|
||||
addrs.NewLegacyProvider(name): providers.FactoryFixed(provider),
|
||||
addrs.NewDefaultProvider(name): providers.FactoryFixed(provider),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ func simpleTestSchemas() *Schemas {
|
|||
provisioner := simpleMockProvisioner()
|
||||
return &Schemas{
|
||||
Providers: map[addrs.Provider]*ProviderSchema{
|
||||
addrs.NewLegacyProvider("test"): provider.GetSchemaReturn,
|
||||
addrs.NewDefaultProvider("test"): provider.GetSchemaReturn,
|
||||
},
|
||||
Provisioners: map[string]*configschema.Block{
|
||||
"test": provisioner.GetSchemaResponse.Provisioner,
|
||||
|
|
|
@ -190,6 +190,46 @@ func testModuleInline(t *testing.T, sources map[string]string) *configs.Config {
|
|||
return config
|
||||
}
|
||||
|
||||
// testSetResourceInstanceCurrent is a helper function for tests that sets a Current,
|
||||
// Ready resource instance for the given module.
|
||||
func testSetResourceInstanceCurrent(module *states.Module, resource, attrsJson, provider string) {
|
||||
module.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr(resource).Resource,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(attrsJson),
|
||||
},
|
||||
mustProviderConfig(provider),
|
||||
)
|
||||
}
|
||||
|
||||
// testSetResourceInstanceTainted is a helper function for tests that sets a Current,
|
||||
// Tainted resource instance for the given module.
|
||||
func testSetResourceInstanceTainted(module *states.Module, resource, attrsJson, provider string) {
|
||||
module.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr(resource).Resource,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectTainted,
|
||||
AttrsJSON: []byte(attrsJson),
|
||||
},
|
||||
mustProviderConfig(provider),
|
||||
)
|
||||
}
|
||||
|
||||
// testSetResourceInstanceDeposed is a helper function for tests that sets a
|
||||
// Deposed resource instance for the given module.
|
||||
func testSetResourceInstanceDeposed(module *states.Module, resource, attrsJson, provider string, key states.DeposedKey) {
|
||||
module.SetResourceInstanceDeposed(
|
||||
mustResourceInstanceAddr(resource).Resource,
|
||||
key,
|
||||
&states.ResourceInstanceObjectSrc{
|
||||
Status: states.ObjectTainted,
|
||||
AttrsJSON: []byte(attrsJson),
|
||||
},
|
||||
mustProviderConfig(provider),
|
||||
)
|
||||
}
|
||||
|
||||
func testProviderFuncFixed(rp providers.Interface) providers.Factory {
|
||||
return func() (providers.Interface, error) {
|
||||
return rp, nil
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
your_aws = {
|
||||
// This is temporarily using the legacy provider namespace so that we can
|
||||
// write tests without fully supporting provider source
|
||||
source = "-/aws"
|
||||
source = "hashicorp/aws"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
my_aws = {
|
||||
// This is temporarily using the legacy provider namespace so that we can
|
||||
// write tests without fully supporting provider source
|
||||
source = "-/aws"
|
||||
source = "hashicorp/aws"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
my_aws = {
|
||||
// This is temporarily using the legacy provider namespace so that we can
|
||||
// write tests without fully supporting provider source
|
||||
source = "-/aws"
|
||||
source = "hashicorp/aws"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ func TestCBDEdgeTransformer(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B").Resource,
|
||||
|
@ -96,7 +96,7 @@ func TestCBDEdgeTransformer(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
g := cbdTestGraph(t, "transform-destroy-cbd-edge-basic", changes, state)
|
||||
|
@ -149,7 +149,7 @@ func TestCBDEdgeTransformerMulti(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B").Resource,
|
||||
|
@ -157,7 +157,7 @@ func TestCBDEdgeTransformerMulti(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"B"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.C").Resource,
|
||||
|
@ -169,7 +169,7 @@ func TestCBDEdgeTransformerMulti(t *testing.T) {
|
|||
mustResourceAddr("test_object.B"),
|
||||
},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
g := cbdTestGraph(t, "transform-destroy-cbd-edge-multi", changes, state)
|
||||
|
@ -227,7 +227,7 @@ func TestCBDEdgeTransformer_depNonCBDCount(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B[0]").Resource,
|
||||
|
@ -236,7 +236,7 @@ func TestCBDEdgeTransformer_depNonCBDCount(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B[1]").Resource,
|
||||
|
@ -245,7 +245,7 @@ func TestCBDEdgeTransformer_depNonCBDCount(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
g := cbdTestGraph(t, "transform-cbd-destroy-edge-count", changes, state)
|
||||
|
@ -305,7 +305,7 @@ func TestCBDEdgeTransformer_depNonCBDCountBoth(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.A[1]").Resource,
|
||||
|
@ -313,7 +313,7 @@ func TestCBDEdgeTransformer_depNonCBDCountBoth(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B[0]").Resource,
|
||||
|
@ -322,7 +322,7 @@ func TestCBDEdgeTransformer_depNonCBDCountBoth(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B[1]").Resource,
|
||||
|
@ -331,7 +331,7 @@ func TestCBDEdgeTransformer_depNonCBDCountBoth(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_list":["x"]}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
g := cbdTestGraph(t, "transform-cbd-destroy-edge-both-count", changes, state)
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestDestroyEdgeTransformer_basic(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B").Resource,
|
||||
|
@ -30,7 +30,7 @@ func TestDestroyEdgeTransformer_basic(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_string":"x"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
if err := (&AttachStateTransformer{State: state}).Transform(&g); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -65,7 +65,7 @@ func TestDestroyEdgeTransformer_multi(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"A"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.B").Resource,
|
||||
|
@ -74,7 +74,7 @@ func TestDestroyEdgeTransformer_multi(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"B","test_string":"x"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("test_object.A")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
root.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.C").Resource,
|
||||
|
@ -86,7 +86,7 @@ func TestDestroyEdgeTransformer_multi(t *testing.T) {
|
|||
mustResourceAddr("test_object.B"),
|
||||
},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
if err := (&AttachStateTransformer{State: state}).Transform(&g); err != nil {
|
||||
|
@ -140,7 +140,7 @@ func TestDestroyEdgeTransformer_module(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"a"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.test_object.b")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
child.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.b").Resource,
|
||||
|
@ -148,7 +148,7 @@ func TestDestroyEdgeTransformer_module(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"b","test_string":"x"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
if err := (&AttachStateTransformer{State: state}).Transform(&g); err != nil {
|
||||
|
@ -184,7 +184,7 @@ func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
AttrsJSON: []byte(`{"id":"a"}`),
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
child.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.b").Resource,
|
||||
|
@ -193,7 +193,7 @@ func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) {
|
|||
AttrsJSON: []byte(`{"id":"b","test_string":"x"}`),
|
||||
Dependencies: []addrs.ConfigResource{mustResourceAddr("module.child.test_object.a")},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
child.SetResourceInstanceCurrent(
|
||||
mustResourceInstanceAddr("test_object.c").Resource,
|
||||
|
@ -205,7 +205,7 @@ func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) {
|
|||
mustResourceAddr("module.child.test_object.b"),
|
||||
},
|
||||
},
|
||||
mustProviderConfig(`provider["registry.terraform.io/-/test"]`),
|
||||
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
||||
)
|
||||
|
||||
if err := (&AttachStateTransformer{State: state}).Transform(&g); err != nil {
|
||||
|
|
|
@ -44,7 +44,7 @@ func TestDiffTransformer(t *testing.T) {
|
|||
Name: "foo",
|
||||
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
||||
ProviderAddr: addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
ChangeSrc: plans.ChangeSrc{
|
||||
|
|
|
@ -358,7 +358,7 @@ func TestOrphanResourceCountTransformer_ForEachEdgesAdded(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModuleInstance,
|
||||
},
|
||||
)
|
||||
|
@ -377,7 +377,7 @@ func TestOrphanResourceCountTransformer_ForEachEdgesAdded(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModuleInstance,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestOrphanResourceInstanceTransformer(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -46,7 +46,7 @@ func TestOrphanResourceInstanceTransformer(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -95,7 +95,7 @@ func TestOrphanResourceInstanceTransformer_countGood(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -112,7 +112,7 @@ func TestOrphanResourceInstanceTransformer_countGood(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -160,7 +160,7 @@ func TestOrphanResourceInstanceTransformer_countBad(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -177,7 +177,7 @@ func TestOrphanResourceInstanceTransformer_countBad(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -225,7 +225,7 @@ func TestOrphanResourceInstanceTransformer_modules(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -242,7 +242,7 @@ func TestOrphanResourceInstanceTransformer_modules(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -461,8 +461,8 @@ func TestProviderConfigTransformer_implicitModule(t *testing.T) {
|
|||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(`module.mod.aws_instance.bar
|
||||
provider["registry.terraform.io/-/aws"].foo
|
||||
provider["registry.terraform.io/-/aws"].foo`)
|
||||
provider["registry.terraform.io/hashicorp/aws"].foo
|
||||
provider["registry.terraform.io/hashicorp/aws"].foo`)
|
||||
if actual != expected {
|
||||
t.Fatalf("wrong result\n\nexpected:\n%s\n\ngot:\n%s", expected, actual)
|
||||
}
|
||||
|
@ -492,101 +492,101 @@ func TestProviderConfigTransformer_invalidProvider(t *testing.T) {
|
|||
if err == nil {
|
||||
t.Fatal("expected missing provider error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), `provider["registry.terraform.io/-/aws"].foo`) {
|
||||
if !strings.Contains(err.Error(), `provider["registry.terraform.io/hashicorp/aws"].foo`) {
|
||||
t.Fatalf("error should reference missing provider, got: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
const testTransformProviderBasicStr = `
|
||||
aws_instance.web
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
`
|
||||
|
||||
const testTransformCloseProviderBasicStr = `
|
||||
aws_instance.web
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
aws_instance.web
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
`
|
||||
|
||||
const testTransformMissingProviderBasicStr = `
|
||||
aws_instance.web
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
foo_instance.web
|
||||
provider["registry.terraform.io/-/foo"]
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/foo"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
aws_instance.web
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/foo"]
|
||||
provider["registry.terraform.io/-/foo"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/foo"]
|
||||
provider["registry.terraform.io/hashicorp/foo"] (close)
|
||||
foo_instance.web
|
||||
provider["registry.terraform.io/-/foo"]
|
||||
provider["registry.terraform.io/hashicorp/foo"]
|
||||
`
|
||||
|
||||
const testTransformMissingGrandchildProviderStr = `
|
||||
module.sub.module.subsub.bar_instance.two
|
||||
provider["registry.terraform.io/-/bar"]
|
||||
provider["registry.terraform.io/hashicorp/bar"]
|
||||
module.sub.module.subsub.foo_instance.one
|
||||
module.sub.provider["registry.terraform.io/-/foo"]
|
||||
module.sub.provider["registry.terraform.io/-/foo"]
|
||||
provider["registry.terraform.io/-/bar"]
|
||||
module.sub.provider["registry.terraform.io/hashicorp/foo"]
|
||||
module.sub.provider["registry.terraform.io/hashicorp/foo"]
|
||||
provider["registry.terraform.io/hashicorp/bar"]
|
||||
`
|
||||
|
||||
const testTransformPruneProviderBasicStr = `
|
||||
foo_instance.web
|
||||
provider["registry.terraform.io/-/foo"]
|
||||
provider["registry.terraform.io/-/foo"]
|
||||
provider["registry.terraform.io/-/foo"] (close)
|
||||
provider["registry.terraform.io/hashicorp/foo"]
|
||||
provider["registry.terraform.io/hashicorp/foo"]
|
||||
provider["registry.terraform.io/hashicorp/foo"] (close)
|
||||
foo_instance.web
|
||||
provider["registry.terraform.io/-/foo"]
|
||||
provider["registry.terraform.io/hashicorp/foo"]
|
||||
`
|
||||
|
||||
const testTransformDisableProviderBasicStr = `
|
||||
module.child
|
||||
provider["registry.terraform.io/-/aws"] (disabled)
|
||||
provider["registry.terraform.io/hashicorp/aws"] (disabled)
|
||||
var.foo
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
module.child
|
||||
provider["registry.terraform.io/-/aws"] (disabled)
|
||||
provider["registry.terraform.io/-/aws"] (disabled)
|
||||
provider["registry.terraform.io/hashicorp/aws"] (disabled)
|
||||
provider["registry.terraform.io/hashicorp/aws"] (disabled)
|
||||
var.foo
|
||||
`
|
||||
|
||||
const testTransformDisableProviderKeepStr = `
|
||||
aws_instance.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
module.child
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
var.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"] (close)
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"] (close)
|
||||
aws_instance.foo
|
||||
module.child
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
var.foo
|
||||
`
|
||||
|
||||
const testTransformModuleProviderConfigStr = `
|
||||
module.child.aws_instance.thing
|
||||
provider["registry.terraform.io/-/aws"].foo
|
||||
provider["registry.terraform.io/-/aws"].foo
|
||||
provider["registry.terraform.io/hashicorp/aws"].foo
|
||||
provider["registry.terraform.io/hashicorp/aws"].foo
|
||||
`
|
||||
|
||||
const testTransformModuleProviderGrandparentStr = `
|
||||
module.child.module.grandchild.aws_instance.baz
|
||||
provider["registry.terraform.io/-/aws"].foo
|
||||
provider["registry.terraform.io/-/aws"].foo
|
||||
provider["registry.terraform.io/hashicorp/aws"].foo
|
||||
provider["registry.terraform.io/hashicorp/aws"].foo
|
||||
`
|
||||
|
||||
const testTransformImportModuleChildStr = `
|
||||
module.child.aws_instance.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
module.child.aws_instance.foo (import id "bar")
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
module.child.module.nested.aws_instance.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/aws"]`
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]`
|
||||
|
|
|
@ -71,7 +71,7 @@ func TestMissingProvisionerTransformer_module(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
@ -88,7 +88,7 @@ func TestMissingProvisionerTransformer_module(t *testing.T) {
|
|||
Status: states.ObjectReady,
|
||||
},
|
||||
addrs.AbsProviderConfig{
|
||||
Provider: addrs.NewLegacyProvider("aws"),
|
||||
Provider: addrs.NewDefaultProvider("aws"),
|
||||
Module: addrs.RootModule,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -58,11 +58,11 @@ func TestRootTransformer(t *testing.T) {
|
|||
|
||||
const testTransformRootBasicStr = `
|
||||
aws_instance.foo
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
do_droplet.bar
|
||||
provider["registry.terraform.io/-/do"]
|
||||
provider["registry.terraform.io/-/aws"]
|
||||
provider["registry.terraform.io/-/do"]
|
||||
provider["registry.terraform.io/hashicorp/do"]
|
||||
provider["registry.terraform.io/hashicorp/aws"]
|
||||
provider["registry.terraform.io/hashicorp/do"]
|
||||
root
|
||||
aws_instance.foo
|
||||
do_droplet.bar
|
||||
|
|
|
@ -32,7 +32,7 @@ func TestTransitiveReductionTransformer(t *testing.T) {
|
|||
transform := &AttachSchemaTransformer{
|
||||
Schemas: &Schemas{
|
||||
Providers: map[addrs.Provider]*ProviderSchema{
|
||||
addrs.NewLegacyProvider("aws"): {
|
||||
addrs.NewDefaultProvider("aws"): {
|
||||
ResourceTypes: map[string]*configschema.Block{
|
||||
"aws_instance": &configschema.Block{
|
||||
Attributes: map[string]*configschema.Attribute{
|
||||
|
|
Loading…
Reference in New Issue