Skip to content

Commit

Permalink
feat: add integration types validation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
byashimov committed Dec 4, 2024
1 parent 1193c8a commit bdb5a54
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/schemautil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bdb5a54

Please sign in to comment.