diff --git a/internal/fwserver/schema_validation.go b/internal/fwserver/schema_validation.go index 41af356e0..2830d1196 100644 --- a/internal/fwserver/schema_validation.go +++ b/internal/fwserver/schema_validation.go @@ -41,13 +41,13 @@ func SchemaValidate(ctx context.Context, s fwschema.Schema, req ValidateSchemaRe AttributePathExpression: path.MatchRoot(name), Config: req.Config, } - attributeResp := &ValidateAttributeResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + attributeResp := &ValidateAttributeResponse{} AttributeValidate(ctx, attribute, attributeReq, attributeResp) - resp.Diagnostics = attributeResp.Diagnostics + resp.Diagnostics.Append(attributeResp.Diagnostics...) } for name, block := range s.GetBlocks() { @@ -56,13 +56,13 @@ func SchemaValidate(ctx context.Context, s fwschema.Schema, req ValidateSchemaRe AttributePathExpression: path.MatchRoot(name), Config: req.Config, } - attributeResp := &ValidateAttributeResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + attributeResp := &ValidateAttributeResponse{} BlockValidate(ctx, block, attributeReq, attributeResp) - resp.Diagnostics = attributeResp.Diagnostics + resp.Diagnostics.Append(attributeResp.Diagnostics...) } if s.GetDeprecationMessage() != "" { diff --git a/internal/fwserver/server_validatedatasourceconfig.go b/internal/fwserver/server_validatedatasourceconfig.go index 03b496d1d..34b51d2d1 100644 --- a/internal/fwserver/server_validatedatasourceconfig.go +++ b/internal/fwserver/server_validatedatasourceconfig.go @@ -55,9 +55,9 @@ func (s *Server) ValidateDataSourceConfig(ctx context.Context, req *ValidateData logging.FrameworkTrace(ctx, "DataSource implements DataSourceWithConfigValidators") for _, configValidator := range dataSource.ConfigValidators(ctx) { - vdscResp := &datasource.ValidateConfigResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + vdscResp := &datasource.ValidateConfigResponse{} logging.FrameworkDebug( ctx, @@ -75,32 +75,32 @@ func (s *Server) ValidateDataSourceConfig(ctx context.Context, req *ValidateData }, ) - resp.Diagnostics = vdscResp.Diagnostics + resp.Diagnostics.Append(vdscResp.Diagnostics...) } } if dataSource, ok := req.DataSource.(datasource.DataSourceWithValidateConfig); ok { logging.FrameworkTrace(ctx, "DataSource implements DataSourceWithValidateConfig") - vdscResp := &datasource.ValidateConfigResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + vdscResp := &datasource.ValidateConfigResponse{} logging.FrameworkDebug(ctx, "Calling provider defined DataSource ValidateConfig") dataSource.ValidateConfig(ctx, vdscReq, vdscResp) logging.FrameworkDebug(ctx, "Called provider defined DataSource ValidateConfig") - resp.Diagnostics = vdscResp.Diagnostics + resp.Diagnostics.Append(vdscResp.Diagnostics...) } validateSchemaReq := ValidateSchemaRequest{ Config: *req.Config, } - validateSchemaResp := ValidateSchemaResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + validateSchemaResp := ValidateSchemaResponse{} SchemaValidate(ctx, req.Config.Schema, validateSchemaReq, &validateSchemaResp) - resp.Diagnostics = validateSchemaResp.Diagnostics + resp.Diagnostics.Append(validateSchemaResp.Diagnostics...) } diff --git a/internal/fwserver/server_validateproviderconfig.go b/internal/fwserver/server_validateproviderconfig.go index fb40f1e16..abc760252 100644 --- a/internal/fwserver/server_validateproviderconfig.go +++ b/internal/fwserver/server_validateproviderconfig.go @@ -36,9 +36,9 @@ func (s *Server) ValidateProviderConfig(ctx context.Context, req *ValidateProvid logging.FrameworkTrace(ctx, "Provider implements ProviderWithConfigValidators") for _, configValidator := range providerWithConfigValidators.ConfigValidators(ctx) { - vpcRes := &provider.ValidateConfigResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + vpcRes := &provider.ValidateConfigResponse{} logging.FrameworkDebug( ctx, @@ -56,34 +56,34 @@ func (s *Server) ValidateProviderConfig(ctx context.Context, req *ValidateProvid }, ) - resp.Diagnostics = vpcRes.Diagnostics + resp.Diagnostics.Append(vpcRes.Diagnostics...) } } if providerWithValidateConfig, ok := s.Provider.(provider.ProviderWithValidateConfig); ok { logging.FrameworkTrace(ctx, "Provider implements ProviderWithValidateConfig") - vpcRes := &provider.ValidateConfigResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + vpcRes := &provider.ValidateConfigResponse{} logging.FrameworkDebug(ctx, "Calling provider defined Provider ValidateConfig") providerWithValidateConfig.ValidateConfig(ctx, vpcReq, vpcRes) logging.FrameworkDebug(ctx, "Called provider defined Provider ValidateConfig") - resp.Diagnostics = vpcRes.Diagnostics + resp.Diagnostics.Append(vpcRes.Diagnostics...) } validateSchemaReq := ValidateSchemaRequest{ Config: *req.Config, } - validateSchemaResp := ValidateSchemaResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + validateSchemaResp := ValidateSchemaResponse{} SchemaValidate(ctx, req.Config.Schema, validateSchemaReq, &validateSchemaResp) - resp.Diagnostics = validateSchemaResp.Diagnostics + resp.Diagnostics.Append(validateSchemaResp.Diagnostics...) // This RPC allows a modified configuration to be returned. This was // previously used to allow a "required" provider attribute (as defined diff --git a/internal/fwserver/server_validateresourceconfig.go b/internal/fwserver/server_validateresourceconfig.go index 1c057f83a..0dfb28bf1 100644 --- a/internal/fwserver/server_validateresourceconfig.go +++ b/internal/fwserver/server_validateresourceconfig.go @@ -55,9 +55,9 @@ func (s *Server) ValidateResourceConfig(ctx context.Context, req *ValidateResour logging.FrameworkTrace(ctx, "Resource implements ResourceWithConfigValidators") for _, configValidator := range resourceWithConfigValidators.ConfigValidators(ctx) { - vdscResp := &resource.ValidateConfigResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + vdscResp := &resource.ValidateConfigResponse{} logging.FrameworkDebug( ctx, @@ -75,32 +75,32 @@ func (s *Server) ValidateResourceConfig(ctx context.Context, req *ValidateResour }, ) - resp.Diagnostics = vdscResp.Diagnostics + resp.Diagnostics.Append(vdscResp.Diagnostics...) } } if resourceWithValidateConfig, ok := req.Resource.(resource.ResourceWithValidateConfig); ok { logging.FrameworkTrace(ctx, "Resource implements ResourceWithValidateConfig") - vdscResp := &resource.ValidateConfigResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + vdscResp := &resource.ValidateConfigResponse{} logging.FrameworkDebug(ctx, "Calling provider defined Resource ValidateConfig") resourceWithValidateConfig.ValidateConfig(ctx, vdscReq, vdscResp) logging.FrameworkDebug(ctx, "Called provider defined Resource ValidateConfig") - resp.Diagnostics = vdscResp.Diagnostics + resp.Diagnostics.Append(vdscResp.Diagnostics...) } validateSchemaReq := ValidateSchemaRequest{ Config: *req.Config, } - validateSchemaResp := ValidateSchemaResponse{ - Diagnostics: resp.Diagnostics, - } + // Instantiate a new response for each request to prevent validators + // from modifying or removing diagnostics. + validateSchemaResp := ValidateSchemaResponse{} SchemaValidate(ctx, req.Config.Schema, validateSchemaReq, &validateSchemaResp) - resp.Diagnostics = validateSchemaResp.Diagnostics + resp.Diagnostics.Append(validateSchemaResp.Diagnostics...) }