mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 16:31:10 -06:00
47a16b0937
a large refactor to addrs.AbsProviderConfig, embedding the addrs.Provider instead of a Type string. I've added and updated tests, added some Legacy functions to support older state formats and shims, and added a normalization step when reading v4 (current) state files (not the added tests under states/statefile/roundtrip which work with both current and legacy-style AbsProviderConfig strings). The remaining 'fixme' and 'todo' comments are mostly going to be addressed in a subsequent PR and involve looking up a given local provider config's FQN. This is fine for now as we are only working with default assumption.
122 lines
4.5 KiB
Go
122 lines
4.5 KiB
Go
package terraform
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
)
|
|
|
|
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",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
b := &RefreshGraphBuilder{
|
|
Config: m,
|
|
State: state,
|
|
Components: simpleMockComponentFactory(),
|
|
Schemas: simpleTestSchemas(),
|
|
}
|
|
g, err := b.Build(addrs.RootModuleInstance)
|
|
if err != nil {
|
|
t.Fatalf("Error building graph: %s", err)
|
|
}
|
|
|
|
actual := strings.TrimSpace(g.StringWithNodeTypes())
|
|
expected := strings.TrimSpace(`
|
|
data.test_object.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
data.test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
data.test_object.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
data.test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
data.test_object.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
|
|
provider["registry.terraform.io/-/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
|
|
data.test_object.foo[0] - *terraform.NodeRefreshableManagedResourceInstance
|
|
data.test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
data.test_object.foo[1] - *terraform.NodeRefreshableManagedResourceInstance
|
|
data.test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
data.test_object.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
|
|
data.test_object.foo[2] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
test_object.foo - *terraform.NodeRefreshableManagedResource
|
|
test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
test_object.foo[2] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
test_object.foo - *terraform.NodeRefreshableManagedResource
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
test_object.foo[2] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
|
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
|
`)
|
|
if expected != actual {
|
|
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)
|
|
}
|
|
}
|