mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
8a070ddef0
Backends are a mechanism that allow abstracting the behavior of Terraform CLI from the actual core. This allows us to slip in special behavior such as state loading, remote operations, etc.
36 lines
720 B
Go
36 lines
720 B
Go
package backend
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
// TestBackendConfig validates and configures the backend with the
|
|
// given configuration.
|
|
func TestBackendConfig(t *testing.T, b Backend, c map[string]interface{}) Backend {
|
|
// Get the proper config structure
|
|
rc, err := config.NewRawConfig(c)
|
|
if err != nil {
|
|
t.Fatalf("bad: %s", err)
|
|
}
|
|
conf := terraform.NewResourceConfig(rc)
|
|
|
|
// Validate
|
|
warns, errs := b.Validate(conf)
|
|
if len(warns) > 0 {
|
|
t.Fatalf("warnings: %s", warns)
|
|
}
|
|
if len(errs) > 0 {
|
|
t.Fatalf("errors: %s", errs)
|
|
}
|
|
|
|
// Configure
|
|
if err := b.Configure(conf); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
return b
|
|
}
|