diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index cec90d7ca..a1f9fb03e 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -693,8 +693,8 @@ func TestContext2Apply_providerWarning(t *testing.T) { p := testProvider("aws") p.ApplyFn = testApplyFn p.DiffFn = testDiffFn - p.ValidateFn = func(c *ResourceConfig) (ws []string, es []error) { - ws = append(ws, "Just a warning") + p.ValidateResourceTypeConfigFn = func(req providers.ValidateResourceTypeConfigRequest) (resp providers.ValidateResourceTypeConfigResponse) { + resp.Diagnostics = resp.Diagnostics.Append(tfdiags.SimpleWarning("just a warning")) return } ctx := testContext2(t, &ContextOpts{ diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 2e1dd269f..00208d571 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -60,9 +60,6 @@ func TestContext2Input_provider(t *testing.T) { actual = req.Config.GetAttr("foo").AsString() return } - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) - } if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) @@ -133,9 +130,6 @@ func TestContext2Input_providerMulti(t *testing.T) { var actual []interface{} var lock sync.Mutex - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) - } if diags := ctx.Input(InputModeStd); diags.HasErrors() { t.Fatalf("input errors: %s", diags.Err()) diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index b88e10d11..28172182b 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -150,6 +150,7 @@ func TestContext2Validate_computedVar(t *testing.T) { ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ + "id": {Type: cty.String, Computed: true}, "value": {Type: cty.String, Optional: true}, }, }, @@ -165,12 +166,13 @@ func TestContext2Validate_computedVar(t *testing.T) { }, }) - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - if !c.IsComputed("value") { - return nil, []error{fmt.Errorf("value isn't computed")} + p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { + val := req.Config.GetAttr("value") + if val.IsKnown() { + resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("value isn't computed")) } - return nil, c.CheckSet([]string{"value"}) + return } diags := c.Validate() @@ -463,8 +465,11 @@ func TestContext2Validate_moduleProviderVar(t *testing.T) { }, }) - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) + p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { + if req.Config.GetAttr("foo").IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null")) + } + return } diags := c.Validate() @@ -498,8 +503,11 @@ func TestContext2Validate_moduleProviderInheritUnused(t *testing.T) { }, }) - p.ValidateFn = func(c *ResourceConfig) ([]string, []error) { - return nil, c.CheckSet([]string{"foo"}) + p.PrepareProviderConfigFn = func(req providers.PrepareProviderConfigRequest) (resp providers.PrepareProviderConfigResponse) { + if req.Config.GetAttr("foo").IsNull() { + resp.Diagnostics = resp.Diagnostics.Append(errors.New("foo is null")) + } + return } diags := c.Validate() diff --git a/terraform/provider_mock.go b/terraform/provider_mock.go index c069ebbe9..b7c647c49 100644 --- a/terraform/provider_mock.go +++ b/terraform/provider_mock.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform/configs/hcl2shim" "github.com/hashicorp/terraform/providers" - "github.com/hashicorp/terraform/tfdiags" ) var _ providers.Interface = (*MockProvider)(nil) @@ -88,8 +87,6 @@ type MockProvider struct { CloseCalled bool CloseError error - ValidateFn func(c *ResourceConfig) (ws []string, es []error) - //ValidateFn func(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse DiffFn func(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse ApplyFn func(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse } @@ -149,19 +146,6 @@ func (p *MockProvider) ValidateResourceTypeConfig(r providers.ValidateResourceTy p.ValidateResourceTypeConfigCalled = true p.ValidateResourceTypeConfigRequest = r - if p.ValidateFn != nil { - resp := p.getSchema() - schema := resp.Provider.Block - rc := NewResourceConfigShimmed(r.Config, schema) - warns, errs := p.ValidateFn(rc) - ret := providers.ValidateResourceTypeConfigResponse{} - for _, warn := range warns { - ret.Diagnostics = ret.Diagnostics.Append(tfdiags.SimpleWarning(warn)) - } - for _, err := range errs { - ret.Diagnostics = ret.Diagnostics.Append(err) - } - } if p.ValidateResourceTypeConfigFn != nil { return p.ValidateResourceTypeConfigFn(r) } diff --git a/terraform/testdata/validate-computed-var/main.tf b/terraform/testdata/validate-computed-var/main.tf index 4a39bb546..81acf7cfa 100644 --- a/terraform/testdata/validate-computed-var/main.tf +++ b/terraform/testdata/validate-computed-var/main.tf @@ -1,5 +1,5 @@ provider "aws" { - value = "${test_instance.foo.value}" + value = test_instance.foo.id } resource "aws_instance" "bar" {} diff --git a/terraform/testdata/validate-module-pc-vars/child/main.tf b/terraform/testdata/validate-module-pc-vars/child/main.tf index 3b4e15483..380cd465a 100644 --- a/terraform/testdata/validate-module-pc-vars/child/main.tf +++ b/terraform/testdata/validate-module-pc-vars/child/main.tf @@ -1,7 +1,7 @@ variable "value" {} provider "aws" { - foo = "${var.value}" + foo = var.value } resource "aws_instance" "foo" {} diff --git a/terraform/testdata/validate-module-pc-vars/main.tf b/terraform/testdata/validate-module-pc-vars/main.tf index 7d2d03e14..5e239b406 100644 --- a/terraform/testdata/validate-module-pc-vars/main.tf +++ b/terraform/testdata/validate-module-pc-vars/main.tf @@ -3,5 +3,5 @@ variable "provider_var" {} module "child" { source = "./child" - value = "${var.provider_var}" + value = var.provider_var }