2015-07-10 15:08:49 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
2018-05-04 21:24:06 -05:00
|
|
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
2018-05-24 20:31:45 -05:00
|
|
|
|
2018-09-26 20:06:03 -05:00
|
|
|
"github.com/hashicorp/terraform/addrs"
|
2018-07-05 12:33:29 -05:00
|
|
|
"github.com/hashicorp/terraform/configs/configschema"
|
2018-09-26 20:06:03 -05:00
|
|
|
"github.com/hashicorp/terraform/providers"
|
|
|
|
"github.com/hashicorp/terraform/states"
|
2015-07-10 15:08:49 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestContext2Input_provider(t *testing.T) {
|
|
|
|
m := testModule(t, "input-provider")
|
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2018-05-31 22:03:03 -05:00
|
|
|
p.GetSchemaReturn = &ProviderSchema{
|
|
|
|
Provider: &configschema.Block{
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"foo": {
|
|
|
|
Type: cty.String,
|
|
|
|
Required: true,
|
|
|
|
Description: "something something",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
2020-10-08 07:56:03 -05:00
|
|
|
"aws_instance": {
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"id": {
|
|
|
|
Type: cty.String,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-05-31 22:03:03 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
inp := &MockUIInput{
|
|
|
|
InputReturnMap: map[string]string{
|
|
|
|
"provider.aws.foo": "bar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2018-05-31 22:03:03 -05:00
|
|
|
UIInput: inp,
|
2015-07-10 15:08:49 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
var actual interface{}
|
2020-10-08 11:26:12 -05:00
|
|
|
p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
|
|
|
actual = req.Config.GetAttr("foo").AsString()
|
|
|
|
return
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-31 22:03:03 -05:00
|
|
|
if !inp.InputCalled {
|
|
|
|
t.Fatal("no input prompt; want prompt for argument \"foo\"")
|
|
|
|
}
|
|
|
|
if got, want := inp.InputOpts.Description, "something something"; got != want {
|
|
|
|
t.Errorf("wrong description\ngot: %q\nwant: %q", got, want)
|
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Plan(); diags.HasErrors() {
|
|
|
|
t.Fatalf("plan errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Apply(); diags.HasErrors() {
|
|
|
|
t.Fatalf("apply errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, "bar") {
|
2018-05-24 20:20:02 -05:00
|
|
|
t.Fatalf("wrong result\ngot: %#v\nwant: %#v", actual, "bar")
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContext2Input_providerMulti(t *testing.T) {
|
|
|
|
m := testModule(t, "input-provider-multi")
|
2018-05-31 22:03:03 -05:00
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2018-05-31 22:03:03 -05:00
|
|
|
p.GetSchemaReturn = &ProviderSchema{
|
|
|
|
Provider: &configschema.Block{
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"foo": {
|
|
|
|
Type: cty.String,
|
|
|
|
Required: true,
|
|
|
|
Description: "something something",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
2020-10-08 07:56:03 -05:00
|
|
|
"aws_instance": {
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"id": {
|
|
|
|
Type: cty.String,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-05-31 22:03:03 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
inp := &MockUIInput{
|
|
|
|
InputReturnMap: map[string]string{
|
|
|
|
"provider.aws.foo": "bar",
|
|
|
|
"provider.aws.east.foo": "bar",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2018-05-31 22:03:03 -05:00
|
|
|
UIInput: inp,
|
2015-07-10 15:08:49 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
var actual []interface{}
|
|
|
|
var lock sync.Mutex
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Plan(); diags.HasErrors() {
|
|
|
|
t.Fatalf("plan errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2020-10-08 11:26:12 -05:00
|
|
|
p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
2018-05-31 22:03:03 -05:00
|
|
|
lock.Lock()
|
|
|
|
defer lock.Unlock()
|
2020-10-08 11:26:12 -05:00
|
|
|
actual = append(actual, req.Config.GetAttr("foo").AsString())
|
|
|
|
return
|
2018-05-31 22:03:03 -05:00
|
|
|
}
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Apply(); diags.HasErrors() {
|
|
|
|
t.Fatalf("apply errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := []interface{}{"bar", "bar"}
|
|
|
|
if !reflect.DeepEqual(actual, expected) {
|
2018-05-24 20:20:02 -05:00
|
|
|
t.Fatalf("wrong result\ngot: %#v\nwant: %#v", actual, expected)
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContext2Input_providerOnce(t *testing.T) {
|
|
|
|
m := testModule(t, "input-provider-once")
|
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2015-07-10 15:08:49 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2015-07-10 15:08:49 -05:00
|
|
|
})
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContext2Input_providerId(t *testing.T) {
|
|
|
|
input := new(MockUIInput)
|
2018-05-31 22:03:03 -05:00
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
m := testModule(t, "input-provider")
|
2018-05-31 22:03:03 -05:00
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2018-05-31 22:03:03 -05:00
|
|
|
p.GetSchemaReturn = &ProviderSchema{
|
|
|
|
Provider: &configschema.Block{
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"foo": {
|
|
|
|
Type: cty.String,
|
|
|
|
Required: true,
|
|
|
|
Description: "something something",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
2020-10-08 07:56:03 -05:00
|
|
|
"aws_instance": {
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"id": {
|
|
|
|
Type: cty.String,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-05-31 22:03:03 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2015-07-10 15:08:49 -05:00
|
|
|
UIInput: input,
|
|
|
|
})
|
|
|
|
|
|
|
|
var actual interface{}
|
2020-10-08 11:26:12 -05:00
|
|
|
p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
|
|
|
actual = req.Config.GetAttr("foo").AsString()
|
|
|
|
return
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
input.InputReturnMap = map[string]string{
|
|
|
|
"provider.aws.foo": "bar",
|
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Plan(); diags.HasErrors() {
|
|
|
|
t.Fatalf("plan errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Apply(); diags.HasErrors() {
|
|
|
|
t.Fatalf("apply errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, "bar") {
|
2018-05-24 20:20:02 -05:00
|
|
|
t.Fatalf("wrong result\ngot: %#v\nwant: %#v", actual, "bar")
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContext2Input_providerOnly(t *testing.T) {
|
|
|
|
input := new(MockUIInput)
|
2018-05-31 22:03:03 -05:00
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
m := testModule(t, "input-provider-vars")
|
2018-05-31 22:03:03 -05:00
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2018-05-31 22:03:03 -05:00
|
|
|
p.GetSchemaReturn = &ProviderSchema{
|
|
|
|
Provider: &configschema.Block{
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"foo": {
|
|
|
|
Type: cty.String,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ResourceTypes: map[string]*configschema.Block{
|
|
|
|
"aws_instance": {
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
2018-09-26 20:06:03 -05:00
|
|
|
"foo": {Type: cty.String, Required: true},
|
|
|
|
"id": {Type: cty.String, Computed: true},
|
|
|
|
"type": {Type: cty.String, Computed: true},
|
2018-05-31 22:03:03 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-07-10 15:08:49 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2018-05-04 21:24:06 -05:00
|
|
|
Variables: InputValues{
|
|
|
|
"foo": &InputValue{
|
|
|
|
Value: cty.StringVal("us-west-2"),
|
|
|
|
SourceType: ValueFromCaller,
|
|
|
|
},
|
2015-07-10 15:08:49 -05:00
|
|
|
},
|
|
|
|
UIInput: input,
|
|
|
|
})
|
|
|
|
|
|
|
|
input.InputReturnMap = map[string]string{
|
2018-05-31 22:03:03 -05:00
|
|
|
"provider.aws.foo": "bar",
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var actual interface{}
|
2020-10-08 11:26:12 -05:00
|
|
|
p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
|
|
|
actual = req.Config.GetAttr("foo").AsString()
|
|
|
|
return
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := ctx.Input(InputModeProvider); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Plan(); diags.HasErrors() {
|
|
|
|
t.Fatalf("plan errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
state, err := ctx.Apply()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, "bar") {
|
2018-05-24 20:20:02 -05:00
|
|
|
t.Fatalf("wrong result\ngot: %#v\nwant: %#v", actual, "bar")
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
actualStr := strings.TrimSpace(state.String())
|
|
|
|
expectedStr := strings.TrimSpace(testTerraformInputProviderOnlyStr)
|
|
|
|
if actualStr != expectedStr {
|
2018-05-24 20:20:02 -05:00
|
|
|
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actualStr, expectedStr)
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContext2Input_providerVars(t *testing.T) {
|
|
|
|
input := new(MockUIInput)
|
|
|
|
m := testModule(t, "input-provider-with-vars")
|
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2015-07-10 15:08:49 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2018-05-04 21:24:06 -05:00
|
|
|
Variables: InputValues{
|
|
|
|
"foo": &InputValue{
|
|
|
|
Value: cty.StringVal("bar"),
|
|
|
|
SourceType: ValueFromCaller,
|
|
|
|
},
|
2015-07-10 15:08:49 -05:00
|
|
|
},
|
|
|
|
UIInput: input,
|
|
|
|
})
|
|
|
|
|
|
|
|
input.InputReturnMap = map[string]string{
|
|
|
|
"var.foo": "bar",
|
|
|
|
}
|
|
|
|
|
|
|
|
var actual interface{}
|
2020-10-08 11:26:12 -05:00
|
|
|
p.ConfigureFn = func(req providers.ConfigureRequest) (resp providers.ConfigureResponse) {
|
|
|
|
actual = req.Config.GetAttr("foo").AsString()
|
|
|
|
return
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Plan(); diags.HasErrors() {
|
|
|
|
t.Fatalf("plan errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Apply(); diags.HasErrors() {
|
|
|
|
t.Fatalf("apply errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, "bar") {
|
|
|
|
t.Fatalf("bad: %#v", actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestContext2Input_providerVarsModuleInherit(t *testing.T) {
|
|
|
|
input := new(MockUIInput)
|
|
|
|
m := testModule(t, "input-provider-with-vars-and-module")
|
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2015-07-10 15:08:49 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2015-07-10 15:08:49 -05:00
|
|
|
UIInput: input,
|
|
|
|
})
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2015-07-10 15:08:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 09:30:14 -05:00
|
|
|
// adding a list interpolation in fails to interpolate the count variable
|
|
|
|
func TestContext2Input_submoduleTriggersInvalidCount(t *testing.T) {
|
|
|
|
input := new(MockUIInput)
|
|
|
|
m := testModule(t, "input-submodule-count")
|
|
|
|
p := testProvider("aws")
|
2020-10-08 12:13:13 -05:00
|
|
|
p.ApplyResourceChangeFn = testApplyFn
|
|
|
|
p.PlanResourceChangeFn = testDiffFn
|
2017-03-16 09:30:14 -05:00
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("aws"): testProviderFuncFixed(p),
|
|
|
|
},
|
2017-03-16 09:30:14 -05:00
|
|
|
UIInput: input,
|
|
|
|
})
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2017-03-16 09:30:14 -05:00
|
|
|
}
|
|
|
|
}
|
2017-08-10 13:12:59 -05:00
|
|
|
|
|
|
|
// In this case, a module variable can't be resolved from a data source until
|
|
|
|
// it's refreshed, but it can't be refreshed during Input.
|
|
|
|
func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) {
|
|
|
|
input := new(MockUIInput)
|
|
|
|
p := testProvider("null")
|
|
|
|
m := testModule(t, "input-module-data-vars")
|
|
|
|
|
2018-05-24 20:35:44 -05:00
|
|
|
p.GetSchemaReturn = &ProviderSchema{
|
|
|
|
DataSources: map[string]*configschema.Block{
|
|
|
|
"null_data_source": {
|
|
|
|
Attributes: map[string]*configschema.Attribute{
|
|
|
|
"foo": {Type: cty.List(cty.String), Optional: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2018-09-05 16:35:30 -05:00
|
|
|
p.ReadDataSourceFn = func(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse {
|
|
|
|
return providers.ReadDataSourceResponse{
|
|
|
|
State: req.Config,
|
|
|
|
}
|
|
|
|
}
|
2017-08-10 13:12:59 -05:00
|
|
|
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 16:24:45 -05:00
|
|
|
state := states.BuildState(func(s *states.SyncState) {
|
|
|
|
s.SetResourceInstanceCurrent(
|
|
|
|
addrs.Resource{
|
|
|
|
Mode: addrs.DataResourceMode,
|
|
|
|
Type: "null_data_source",
|
|
|
|
Name: "bar",
|
|
|
|
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
|
|
|
|
&states.ResourceInstanceObjectSrc{
|
|
|
|
AttrsFlat: map[string]string{
|
|
|
|
"id": "-",
|
|
|
|
"foo.#": "1",
|
|
|
|
"foo.0": "a",
|
|
|
|
// foo.1 exists in the data source, but needs to be refreshed.
|
2017-08-10 13:12:59 -05:00
|
|
|
},
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 16:24:45 -05:00
|
|
|
Status: states.ObjectReady,
|
2017-08-10 13:12:59 -05:00
|
|
|
},
|
2020-02-13 14:32:58 -06:00
|
|
|
addrs.AbsProviderConfig{
|
2020-03-31 13:03:33 -05:00
|
|
|
Provider: addrs.NewDefaultProvider("null"),
|
2020-03-10 20:21:19 -05:00
|
|
|
Module: addrs.RootModule,
|
2020-02-13 14:32:58 -06:00
|
|
|
},
|
terraform: Ugly huge change to weave in new State and Plan types
Due to how often the state and plan types are referenced throughout
Terraform, there isn't a great way to switch them out gradually. As a
consequence, this huge commit gets us from the old world to a _compilable_
new world, but still has a large number of known test failures due to
key functionality being stubbed out.
The stubs here are for anything that interacts with providers, since we
now need to do the follow-up work to similarly replace the old
terraform.ResourceProvider interface with its replacement in the new
"providers" package. That work, along with work to fix the remaining
failing tests, will follow in subsequent commits.
The aim here was to replace all references to terraform.State and its
downstream types with states.State, terraform.Plan with plans.Plan,
state.State with statemgr.State, and switch to the new implementations of
the state and plan file formats. However, due to the number of times those
types are used, this also ended up affecting numerous other parts of core
such as terraform.Hook, the backend.Backend interface, and most of the CLI
commands.
Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize
in advance to the person who inevitably just found this huge commit while
spelunking through the commit history.
2018-08-14 16:24:45 -05:00
|
|
|
)
|
|
|
|
})
|
2017-08-10 13:12:59 -05:00
|
|
|
|
|
|
|
ctx := testContext2(t, &ContextOpts{
|
2018-05-04 21:24:06 -05:00
|
|
|
Config: m,
|
2020-03-31 13:03:33 -05:00
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
addrs.NewDefaultProvider("null"): testProviderFuncFixed(p),
|
|
|
|
},
|
2017-08-10 13:12:59 -05:00
|
|
|
State: state,
|
|
|
|
UIInput: input,
|
|
|
|
})
|
|
|
|
|
2018-05-24 20:20:02 -05:00
|
|
|
if diags := ctx.Input(InputModeStd); diags.HasErrors() {
|
|
|
|
t.Fatalf("input errors: %s", diags.Err())
|
2017-08-10 13:12:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ensure that plan works after Refresh
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Refresh(); diags.HasErrors() {
|
|
|
|
t.Fatalf("refresh errors: %s", diags.Err())
|
2017-08-10 13:12:59 -05:00
|
|
|
}
|
2018-05-24 20:20:02 -05:00
|
|
|
if _, diags := ctx.Plan(); diags.HasErrors() {
|
|
|
|
t.Fatalf("plan errors: %s", diags.Err())
|
2017-08-10 13:12:59 -05:00
|
|
|
}
|
|
|
|
}
|