Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 37 additions & 130 deletions internal/command/meta_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,32 +2099,7 @@ func TestMetaBackend_configureNewStateStore(t *testing.T) {
//
// This imagines a provider called foo that contains
// a pluggable state store implementation called bar.
mock := &testing_provider.MockProvider{
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
Provider: providers.Schema{
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"region": {Type: cty.String, Optional: true},
},
},
},
DataSources: map[string]providers.Schema{},
ResourceTypes: map[string]providers.Schema{},
ListResourceTypes: map[string]providers.Schema{},
StateStores: map[string]providers.Schema{
"foo_bar": {
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"bar": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
}
mock := testStateStoreMock(t)
factory := func() (providers.Interface, error) {
return mock, nil
}
Expand Down Expand Up @@ -2214,32 +2189,7 @@ func TestMetaBackend_reconfigureStateStoreChange(t *testing.T) {
//
// This imagines a provider called foo that contains
// a pluggable state store implementation called bar.
mock := &testing_provider.MockProvider{
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
Provider: providers.Schema{
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"region": {Type: cty.String, Optional: true},
},
},
},
DataSources: map[string]providers.Schema{},
ResourceTypes: map[string]providers.Schema{},
ListResourceTypes: map[string]providers.Schema{},
StateStores: map[string]providers.Schema{
"foo_bar": {
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"bar": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
}
mock := testStateStoreMock(t)
factory := func() (providers.Interface, error) {
return mock, nil
}
Expand Down Expand Up @@ -2285,32 +2235,7 @@ func TestMetaBackend_changeConfiguredStateStore(t *testing.T) {
//
// This imagines a provider called foo that contains
// a pluggable state store implementation called bar.
mock := &testing_provider.MockProvider{
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
Provider: providers.Schema{
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"region": {Type: cty.String, Optional: true},
},
},
},
DataSources: map[string]providers.Schema{},
ResourceTypes: map[string]providers.Schema{},
ListResourceTypes: map[string]providers.Schema{},
StateStores: map[string]providers.Schema{
"foo_bar": {
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"bar": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
}
mock := testStateStoreMock(t)
factory := func() (providers.Interface, error) {
return mock, nil
}
Expand Down Expand Up @@ -2353,32 +2278,7 @@ func TestMetaBackend_configuredBackendToStateStore(t *testing.T) {
//
// This imagines a provider called foo that contains
// a pluggable state store implementation called bar.
mock := &testing_provider.MockProvider{
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
Provider: providers.Schema{
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"region": {Type: cty.String, Optional: true},
},
},
},
DataSources: map[string]providers.Schema{},
ResourceTypes: map[string]providers.Schema{},
ListResourceTypes: map[string]providers.Schema{},
StateStores: map[string]providers.Schema{
"foo_bar": {
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"bar": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
}
mock := testStateStoreMock(t)
factory := func() (providers.Interface, error) {
return mock, nil
}
Expand Down Expand Up @@ -2475,32 +2375,7 @@ func TestMetaBackend_configureStateStoreVariableUse(t *testing.T) {
//
// This imagines a provider called foo that contains
// a pluggable state store implementation called bar.
mock := &testing_provider.MockProvider{
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
Provider: providers.Schema{
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"region": {Type: cty.String, Optional: true},
},
},
},
DataSources: map[string]providers.Schema{},
ResourceTypes: map[string]providers.Schema{},
ListResourceTypes: map[string]providers.Schema{},
StateStores: map[string]providers.Schema{
"foo_bar": {
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"bar": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
}
mock := testStateStoreMock(t)
factory := func() (providers.Interface, error) {
return mock, nil
}
Expand Down Expand Up @@ -2538,3 +2413,35 @@ func testMetaBackend(t *testing.T, args []string) *Meta {

return &m
}

// testStateStoreMock returns a mock provider that has a state store implementation
// The provider uses the name "test" and the store inside is "test_store".
func testStateStoreMock(t *testing.T) *testing_provider.MockProvider {
t.Helper()
return &testing_provider.MockProvider{
GetProviderSchemaResponse: &providers.GetProviderSchemaResponse{
Provider: providers.Schema{
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"region": {Type: cty.String, Optional: true},
},
},
},
DataSources: map[string]providers.Schema{},
ResourceTypes: map[string]providers.Schema{},
ListResourceTypes: map[string]providers.Schema{},
StateStores: map[string]providers.Schema{
"test_store": {
Body: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"value": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
}
}
10 changes: 5 additions & 5 deletions internal/command/testdata/backend-to-state-store/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
terraform {
required_providers {
foo = {
source = "my-org/foo"
test = {
source = "hashicorp/test"
}
}
state_store "foo_bar" {
provider "foo" {}
state_store "test_store" {
provider "test" {}

bar = "foobar"
value = "foobar"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"serial": 0,
"lineage": "666f9301-7e65-4b19-ae23-71184bb19b03",
"state_store": {
"type": "foo_bar",
"type": "test_store",
"config": {
"bar": "old-value"
"value": "old-value"
},
"provider": {
"version": "1.2.3",
Expand Down
10 changes: 5 additions & 5 deletions internal/command/testdata/state-store-changed/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
terraform {
required_providers {
foo = {
source = "my-org/foo"
test = {
source = "hashicorp/test"
}
}
state_store "foo_bar" {
provider "foo" {}
state_store "test_store" {
provider "test" {}

bar = "changed-value" # changed versus backend state file
value = "changed-value" # changed versus backend state file
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ variable "foo" { default = "bar" }

terraform {
required_providers {
foo = {
source = "my-org/foo"
test = {
source = "hashicorp/test"
}
}
state_store "foo_bar" {
provider "foo" {
state_store "test_store" {
provider "test" {
region = var.foo
}

bar = "hardcoded"
value = "hardcoded"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ variable "foo" { default = "bar" }

terraform {
required_providers {
foo = {
source = "my-org/foo"
test = {
source = "hashicorp/test"
}
}
state_store "foo_bar" {
provider "foo" {
state_store "test_store" {
provider "test" {
region = "hardcoded"
}

bar = var.foo
value = var.foo
}
}
10 changes: 5 additions & 5 deletions internal/command/testdata/state-store-new/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
terraform {
required_providers {
foo = {
source = "my-org/foo"
test = {
source = "hashicorp/test"
}
}
state_store "foo_bar" {
provider "foo" {}
state_store "test_store" {
provider "test" {}

bar = "foobar"
value = "foobar"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"serial": 0,
"lineage": "666f9301-7e65-4b19-ae23-71184bb19b03",
"state_store": {
"type": "foo_bar",
"type": "test_store",
"config": {
"bar": "old-value"
"value": "old-value"
},
"provider": {
"version": "1.2.3",
Expand Down
10 changes: 5 additions & 5 deletions internal/command/testdata/state-store-reconfigure/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
terraform {
required_providers {
foo = {
source = "my-org/foo"
test = {
source = "hashicorp/test"
}
}
state_store "foo_bar" {
provider "foo" {}
state_store "test_store" {
provider "test" {}

bar = "changed-value" # changed versus backend state file
value = "changed-value" # changed versus backend state file
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"serial": 0,
"lineage": "666f9301-7e65-4b19-ae23-71184bb19b03",
"state_store": {
"type": "foo_bar",
"type": "test_store",
"config": {
"bar": "foobar"
"value": "foobar"
},
"provider": {
"version": "1.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"serial": 0,
"lineage": "666f9301-7e65-4b19-ae23-71184bb19b03",
"state_store": {
"type": "foo_bar",
"type": "test_store",
"config": {
"bar": "foobar"
"value": "foobar"
},
"provider": {
"version": "1.2.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ terraform {
}
}

state_store "foo_bar" {
provider "foo" {}
required_providers {
test = {
source = "hashicorp/test"
}
}
state_store "test_store" {
provider "test" {}

custom_attr = "override"
value = "override"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
terraform {
state_store "foo_bar" {
provider "foo" {}
required_providers {
test = {
source = "hashicorp/test"
}
}
state_store "test_store" {
provider "test" {}

custom_attr = "override"
}
Expand Down
Loading
Loading