From e2a20ae13ef98738ebac0566e9ed25f570226e0a Mon Sep 17 00:00:00 2001 From: VenelinMartinov Date: Fri, 2 Feb 2024 16:33:05 +0000 Subject: [PATCH] Validate resources only during build time (#37) * validate resources only during build time * bump * address review * add back change --- helper/schema/provider.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/helper/schema/provider.go b/helper/schema/provider.go index 75e1a7c4..b1464c17 100644 --- a/helper/schema/provider.go +++ b/helper/schema/provider.go @@ -209,6 +209,12 @@ func (p *Provider) GetSchema(req *terraform.ProviderSchemaRequest) (*terraform.P }, nil } +// This controls if we should validate the provider schema when validating the config +// for the provider. This is useful for testing the provider schema itself. +// This should only be used during tfgen and for testing since +// the schema validation could take a long time for some resources. +var RunProviderInternalValidation bool + // Validate is called once at the beginning with the raw configuration // (no interpolation done) and can return diagnostics // @@ -219,15 +225,17 @@ func (p *Provider) GetSchema(req *terraform.ProviderSchemaRequest) (*terraform.P // The primary use case of this call is to check that required keys are // set. func (p *Provider) Validate(c *terraform.ResourceConfig) diag.Diagnostics { - if err := p.InternalValidate(); err != nil { - return []diag.Diagnostic{ - { - Severity: diag.Error, - Summary: "InternalValidate", - Detail: fmt.Sprintf("Internal validation of the provider failed! This is always a bug\n"+ - "with the provider itself, and not a user issue. Please report\n"+ - "this bug:\n\n%s", err), - }, + if RunProviderInternalValidation { + if err := p.InternalValidate(); err != nil { + return []diag.Diagnostic{ + { + Severity: diag.Error, + Summary: "InternalValidate", + Detail: fmt.Sprintf("Internal validation of the provider failed! This is always a bug\n"+ + "with the provider itself, and not a user issue. Please report\n"+ + "this bug:\n\n%s", err), + }, + } } }