From bdb5a54541563049939fa970cb664a3a4e70de91 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Wed, 4 Dec 2024 17:52:49 +0100 Subject: [PATCH] feat: add integration types validation Service integrations field gets only allowed integration types (from the API), like `read_replica` or `disaster_recovery`. Most of service types just do not support those integrations, hence, it shouldn't be even possible to set them. --- internal/schemautil/service.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/schemautil/service.go b/internal/schemautil/service.go index 015f5f366..b4f1f36ce 100644 --- a/internal/schemautil/service.go +++ b/internal/schemautil/service.go @@ -76,9 +76,16 @@ func ServiceCommonSchemaWithUserConfig(kind string) map[string]*schema.Schema { // Assigns the integration types that are allowed to be set when creating a service integrations := getBootstrapIntegrationTypes(kind) - if len(integrations) > 0 { + switch len(integrations) { + case 0: + // Disables the service integrations field if there are no integrations supported + s[serviceIntegrationsKey].ValidateFunc = func(v any, _ string) ([]string, []error) { + return nil, []error{fmt.Errorf("service integration %s can't be specified here", v)} + } + default: r := s[serviceIntegrationsKey].Elem.(*schema.Resource) r.Schema["integration_type"].Description = userconfig.Desc(r.Schema["integration_type"].Description).PossibleValuesString(FlattenToString(integrations)...).Build() + r.Schema["integration_type"].ValidateFunc = validation.StringInSlice(FlattenToString(integrations), false) } return s