|
|
|
|
@ -5,12 +5,14 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/providers"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
|
|
|
"github.com/hashicorp/terraform/backend"
|
|
|
|
|
"github.com/hashicorp/terraform/configs/configschema"
|
|
|
|
|
"github.com/hashicorp/terraform/internal/initwd"
|
|
|
|
|
"github.com/hashicorp/terraform/providers"
|
|
|
|
|
"github.com/hashicorp/terraform/states"
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
|
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -19,7 +21,7 @@ func TestLocal_refresh(t *testing.T) {
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
|
|
|
|
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
testStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
|
|
|
|
|
p.ReadResourceFn = nil
|
|
|
|
|
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
@ -42,7 +44,7 @@ func TestLocal_refresh(t *testing.T) {
|
|
|
|
|
checkState(t, b.StateOutPath, `
|
|
|
|
|
test_instance.foo:
|
|
|
|
|
ID = yes
|
|
|
|
|
provider = provider["registry.terraform.io/-/test"]
|
|
|
|
|
provider = provider["registry.terraform.io/hashicorp/test"]
|
|
|
|
|
`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -50,7 +52,7 @@ func TestLocal_refreshNoConfig(t *testing.T) {
|
|
|
|
|
b, cleanup := TestLocal(t)
|
|
|
|
|
defer cleanup()
|
|
|
|
|
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
|
|
|
|
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
testStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
p.ReadResourceFn = nil
|
|
|
|
|
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"id": cty.StringVal("yes"),
|
|
|
|
|
@ -72,7 +74,7 @@ func TestLocal_refreshNoConfig(t *testing.T) {
|
|
|
|
|
checkState(t, b.StateOutPath, `
|
|
|
|
|
test_instance.foo:
|
|
|
|
|
ID = yes
|
|
|
|
|
provider = provider["registry.terraform.io/-/test"]
|
|
|
|
|
provider = provider["registry.terraform.io/hashicorp/test"]
|
|
|
|
|
`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -81,7 +83,7 @@ func TestLocal_refreshNilModuleWithInput(t *testing.T) {
|
|
|
|
|
b, cleanup := TestLocal(t)
|
|
|
|
|
defer cleanup()
|
|
|
|
|
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
|
|
|
|
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
testStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
p.ReadResourceFn = nil
|
|
|
|
|
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"id": cty.StringVal("yes"),
|
|
|
|
|
@ -105,7 +107,7 @@ func TestLocal_refreshNilModuleWithInput(t *testing.T) {
|
|
|
|
|
checkState(t, b.StateOutPath, `
|
|
|
|
|
test_instance.foo:
|
|
|
|
|
ID = yes
|
|
|
|
|
provider = provider["registry.terraform.io/-/test"]
|
|
|
|
|
provider = provider["registry.terraform.io/hashicorp/test"]
|
|
|
|
|
`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -113,7 +115,7 @@ func TestLocal_refreshInput(t *testing.T) {
|
|
|
|
|
b, cleanup := TestLocal(t)
|
|
|
|
|
defer cleanup()
|
|
|
|
|
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
|
|
|
|
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
testStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
|
|
|
|
|
p.GetSchemaReturn = &terraform.ProviderSchema{
|
|
|
|
|
Provider: &configschema.Block{
|
|
|
|
|
@ -163,7 +165,7 @@ func TestLocal_refreshInput(t *testing.T) {
|
|
|
|
|
checkState(t, b.StateOutPath, `
|
|
|
|
|
test_instance.foo:
|
|
|
|
|
ID = yes
|
|
|
|
|
provider = provider["registry.terraform.io/-/test"]
|
|
|
|
|
provider = provider["registry.terraform.io/hashicorp/test"]
|
|
|
|
|
`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -171,7 +173,7 @@ func TestLocal_refreshValidate(t *testing.T) {
|
|
|
|
|
b, cleanup := TestLocal(t)
|
|
|
|
|
defer cleanup()
|
|
|
|
|
p := TestLocalProvider(t, b, "test", refreshFixtureSchema())
|
|
|
|
|
terraform.TestStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
testStateFile(t, b.StatePath, testRefreshState())
|
|
|
|
|
p.ReadResourceFn = nil
|
|
|
|
|
p.ReadResourceResponse = providers.ReadResourceResponse{NewState: cty.ObjectVal(map[string]cty.Value{
|
|
|
|
|
"id": cty.StringVal("yes"),
|
|
|
|
|
@ -196,7 +198,7 @@ func TestLocal_refreshValidate(t *testing.T) {
|
|
|
|
|
checkState(t, b.StateOutPath, `
|
|
|
|
|
test_instance.foo:
|
|
|
|
|
ID = yes
|
|
|
|
|
provider = provider["registry.terraform.io/-/test"]
|
|
|
|
|
provider = provider["registry.terraform.io/hashicorp/test"]
|
|
|
|
|
`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -213,24 +215,18 @@ func testOperationRefresh(t *testing.T, configDir string) (*backend.Operation, f
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// testRefreshState is just a common state that we use for testing refresh.
|
|
|
|
|
func testRefreshState() *terraform.State {
|
|
|
|
|
return &terraform.State{
|
|
|
|
|
Version: 2,
|
|
|
|
|
Modules: []*terraform.ModuleState{
|
|
|
|
|
&terraform.ModuleState{
|
|
|
|
|
Path: []string{"root"},
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Outputs: map[string]*terraform.OutputState{},
|
|
|
|
|
},
|
|
|
|
|
func testRefreshState() *states.State {
|
|
|
|
|
state := states.NewState()
|
|
|
|
|
root := state.EnsureModule(addrs.RootModuleInstance)
|
|
|
|
|
root.SetResourceInstanceCurrent(
|
|
|
|
|
mustResourceInstanceAddr("test_instance.foo").Resource,
|
|
|
|
|
&states.ResourceInstanceObjectSrc{
|
|
|
|
|
Status: states.ObjectReady,
|
|
|
|
|
AttrsJSON: []byte(`{"id":"bar"}`),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
|
|
|
|
)
|
|
|
|
|
return state
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// refreshFixtureSchema returns a schema suitable for processing the
|
|
|
|
|
|