mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-29 10:21:01 -06:00
36d0a50427
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/hcl/v2/hcldec"
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
|
"github.com/hashicorp/terraform/internal/configs"
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
|
)
|
|
|
|
func TestBuildProviderConfig(t *testing.T) {
|
|
configBody := configs.SynthBody("", map[string]cty.Value{
|
|
"set_in_config": cty.StringVal("config"),
|
|
})
|
|
providerAddr := addrs.AbsProviderConfig{
|
|
Module: addrs.RootModule,
|
|
Provider: addrs.NewDefaultProvider("foo"),
|
|
}
|
|
|
|
ctx := &MockEvalContext{
|
|
// The input values map is expected to contain only keys that aren't
|
|
// already present in the config, since we skip prompting for
|
|
// attributes that are already set.
|
|
ProviderInputValues: map[string]cty.Value{
|
|
"set_by_input": cty.StringVal("input"),
|
|
},
|
|
}
|
|
gotBody := buildProviderConfig(ctx, providerAddr, &configs.Provider{
|
|
Name: "foo",
|
|
Config: configBody,
|
|
})
|
|
|
|
schema := &configschema.Block{
|
|
Attributes: map[string]*configschema.Attribute{
|
|
"set_in_config": {Type: cty.String, Optional: true},
|
|
"set_by_input": {Type: cty.String, Optional: true},
|
|
},
|
|
}
|
|
got, diags := hcldec.Decode(gotBody, schema.DecoderSpec(), nil)
|
|
if diags.HasErrors() {
|
|
t.Fatalf("body decode failed: %s", diags.Error())
|
|
}
|
|
|
|
// We expect the provider config with the added input value
|
|
want := cty.ObjectVal(map[string]cty.Value{
|
|
"set_in_config": cty.StringVal("config"),
|
|
"set_by_input": cty.StringVal("input"),
|
|
})
|
|
if !got.RawEquals(want) {
|
|
t.Fatalf("incorrect merged config\ngot: %#v\nwant: %#v", got, want)
|
|
}
|
|
}
|