diff --git a/internal/sdkprovider/service/serviceintegration/service_integration.go b/internal/sdkprovider/service/serviceintegration/service_integration.go index ba3e6e04a..a5d6a6c27 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "golang.org/x/exp/maps" "golang.org/x/exp/slices" "github.com/aiven/terraform-provider-aiven/internal/common" @@ -21,50 +20,50 @@ import ( "github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig/apiconvert" "github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig/stateupgrader" "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/converters" - "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/integration" + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/serviceintegration" ) const serviceIntegrationEndpointRegExp = "^[a-zA-Z0-9_-]*\\/{1}[a-zA-Z0-9_-]*$" -// typesList integration type name as a key, and value is whether it has a config -func typesList() map[string]bool { - return map[string]bool{ - "alertmanager": false, - "cassandra_cross_service_cluster": false, - "clickhouse_kafka": true, - "clickhouse_postgresql": true, - "dashboard": false, - "datadog": true, - "datasource": false, - "external_aws_cloudwatch_logs": false, - "external_aws_cloudwatch_metrics": true, - "external_elasticsearch_logs": false, - "external_google_cloud_logging": false, - "external_opensearch_logs": false, - "flink": false, - "internal_connectivity": false, - "jolokia": false, - "kafka_connect": true, - "kafka_logs": true, - "kafka_mirrormaker": true, - "logs": true, - "m3aggregator": false, - "m3coordinator": false, - "metrics": true, - "opensearch_cross_cluster_replication": false, - "opensearch_cross_cluster_search": false, - "prometheus": false, - "read_replica": false, - "rsyslog": false, - "schema_registry_proxy": false, +func hasConfig(kind string) bool { + return slices.Contains(serviceintegration.UserConfigTypes(), kind) +} + +// typesList integration type list +func typesList() []string { + return []string{ + "alertmanager", + "cassandra_cross_service_cluster", + "clickhouse_kafka", + "clickhouse_postgresql", + "dashboard", + "datadog", + "datasource", + "external_aws_cloudwatch_logs", + "external_aws_cloudwatch_metrics", + "external_elasticsearch_logs", + "external_google_cloud_logging", + "external_opensearch_logs", + "flink", + "internal_connectivity", + "jolokia", + "kafka_connect", + "kafka_logs", + "kafka_mirrormaker", + "logs", + "m3aggregator", + "m3coordinator", + "metrics", + "opensearch_cross_cluster_replication", + "opensearch_cross_cluster_search", + "prometheus", + "read_replica", + "rsyslog", + "schema_registry_proxy", } } func aivenServiceIntegrationSchema() map[string]*schema.Schema { - types := typesList() - sortedTypes := maps.Keys(types) - slices.Sort(sortedTypes) - s := map[string]*schema.Schema{ "integration_id": { Description: "Service Integration Id at aiven", @@ -86,11 +85,11 @@ func aivenServiceIntegrationSchema() map[string]*schema.Schema { Type: schema.TypeString, }, "integration_type": { - Description: "Type of the service integration. Possible values: " + schemautil.JoinQuoted(sortedTypes, ", ", "`"), + Description: "Type of the service integration. Possible values: " + schemautil.JoinQuoted(typesList(), ", ", "`"), ForceNew: true, Required: true, Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(sortedTypes, false), + ValidateFunc: validation.StringInSlice(typesList(), false), }, "project": { Description: "Project the integration belongs to", @@ -115,10 +114,8 @@ func aivenServiceIntegrationSchema() map[string]*schema.Schema { } // Adds user configs - for _, k := range sortedTypes { - if types[k] { - s[k+"_user_config"] = integration.GetUserConfig(k) - } + for _, k := range serviceintegration.UserConfigTypes() { + s[k+"_user_config"] = serviceintegration.GetUserConfig(k) } return s } @@ -179,8 +176,8 @@ func resourceServiceIntegrationCreate(ctx context.Context, d *schema.ResourceDat SourceService: schemautil.OptionalStringPointer(d, "source_service_name"), } - if typesList()[integrationType] { - uc, err := converters.Expand(integrationType, integration.GetUserConfig(integrationType), d) + if hasConfig(integrationType) { + uc, err := converters.Expand(integrationType, serviceintegration.GetUserConfig(integrationType), d) if err != nil { return diag.FromErr(err) } @@ -394,8 +391,8 @@ func resourceServiceIntegrationCopyAPIResponseToTerraform( return err } - if typesList()[integrationType] { - userConfig, err := converters.Flatten(integrationType, integration.GetUserConfig(integrationType), d, res.UserConfig) + if hasConfig(integrationType) { + userConfig, err := converters.Flatten(integrationType, serviceintegration.GetUserConfig(integrationType), d, res.UserConfig) if err != nil { return err } diff --git a/internal/sdkprovider/userconfig/service/service.go b/internal/sdkprovider/userconfig/service/service.go index 65b7766ae..a77b9c3fd 100644 --- a/internal/sdkprovider/userconfig/service/service.go +++ b/internal/sdkprovider/userconfig/service/service.go @@ -38,3 +38,6 @@ func GetUserConfig(kind string) *schema.Schema { panic("unknown user config type: " + kind) } } +func UserConfigTypes() []string { + return []string{"cassandra", "clickhouse", "flink", "grafana", "influxdb", "kafka", "kafka_connect", "kafka_mirrormaker", "m3aggregator", "m3db", "mysql", "opensearch", "pg", "redis"} +} diff --git a/internal/sdkprovider/userconfig/integration/clickhouse_kafka.go b/internal/sdkprovider/userconfig/serviceintegration/clickhouse_kafka.go similarity index 99% rename from internal/sdkprovider/userconfig/integration/clickhouse_kafka.go rename to internal/sdkprovider/userconfig/serviceintegration/clickhouse_kafka.go index de12d5a9b..051b9d8dc 100644 --- a/internal/sdkprovider/userconfig/integration/clickhouse_kafka.go +++ b/internal/sdkprovider/userconfig/serviceintegration/clickhouse_kafka.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/clickhouse_postgresql.go b/internal/sdkprovider/userconfig/serviceintegration/clickhouse_postgresql.go similarity index 97% rename from internal/sdkprovider/userconfig/integration/clickhouse_postgresql.go rename to internal/sdkprovider/userconfig/serviceintegration/clickhouse_postgresql.go index 6dd04f28b..eb5282387 100644 --- a/internal/sdkprovider/userconfig/integration/clickhouse_postgresql.go +++ b/internal/sdkprovider/userconfig/serviceintegration/clickhouse_postgresql.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/datadog.go b/internal/sdkprovider/userconfig/serviceintegration/datadog.go similarity index 99% rename from internal/sdkprovider/userconfig/integration/datadog.go rename to internal/sdkprovider/userconfig/serviceintegration/datadog.go index 91dc2b589..28f9127f8 100644 --- a/internal/sdkprovider/userconfig/integration/datadog.go +++ b/internal/sdkprovider/userconfig/serviceintegration/datadog.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/external_aws_cloudwatch_metrics.go b/internal/sdkprovider/userconfig/serviceintegration/external_aws_cloudwatch_metrics.go similarity index 98% rename from internal/sdkprovider/userconfig/integration/external_aws_cloudwatch_metrics.go rename to internal/sdkprovider/userconfig/serviceintegration/external_aws_cloudwatch_metrics.go index a1bb043a0..a8c4aeba3 100644 --- a/internal/sdkprovider/userconfig/integration/external_aws_cloudwatch_metrics.go +++ b/internal/sdkprovider/userconfig/serviceintegration/external_aws_cloudwatch_metrics.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/kafka_connect.go b/internal/sdkprovider/userconfig/serviceintegration/kafka_connect.go similarity index 98% rename from internal/sdkprovider/userconfig/integration/kafka_connect.go rename to internal/sdkprovider/userconfig/serviceintegration/kafka_connect.go index e793f8efc..0e4ba56da 100644 --- a/internal/sdkprovider/userconfig/integration/kafka_connect.go +++ b/internal/sdkprovider/userconfig/serviceintegration/kafka_connect.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/kafka_logs.go b/internal/sdkprovider/userconfig/serviceintegration/kafka_logs.go similarity index 97% rename from internal/sdkprovider/userconfig/integration/kafka_logs.go rename to internal/sdkprovider/userconfig/serviceintegration/kafka_logs.go index b536a20b7..88fe47547 100644 --- a/internal/sdkprovider/userconfig/integration/kafka_logs.go +++ b/internal/sdkprovider/userconfig/serviceintegration/kafka_logs.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/kafka_mirrormaker.go b/internal/sdkprovider/userconfig/serviceintegration/kafka_mirrormaker.go similarity index 98% rename from internal/sdkprovider/userconfig/integration/kafka_mirrormaker.go rename to internal/sdkprovider/userconfig/serviceintegration/kafka_mirrormaker.go index 724405c73..65084e21b 100644 --- a/internal/sdkprovider/userconfig/integration/kafka_mirrormaker.go +++ b/internal/sdkprovider/userconfig/serviceintegration/kafka_mirrormaker.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/logs.go b/internal/sdkprovider/userconfig/serviceintegration/logs.go similarity index 98% rename from internal/sdkprovider/userconfig/integration/logs.go rename to internal/sdkprovider/userconfig/serviceintegration/logs.go index dea19056f..037f8487b 100644 --- a/internal/sdkprovider/userconfig/integration/logs.go +++ b/internal/sdkprovider/userconfig/serviceintegration/logs.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/metrics.go b/internal/sdkprovider/userconfig/serviceintegration/metrics.go similarity index 99% rename from internal/sdkprovider/userconfig/integration/metrics.go rename to internal/sdkprovider/userconfig/serviceintegration/metrics.go index 6e2a6b389..019b68651 100644 --- a/internal/sdkprovider/userconfig/integration/metrics.go +++ b/internal/sdkprovider/userconfig/serviceintegration/metrics.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/internal/sdkprovider/userconfig/integration/integration.go b/internal/sdkprovider/userconfig/serviceintegration/serviceintegration.go similarity index 76% rename from internal/sdkprovider/userconfig/integration/integration.go rename to internal/sdkprovider/userconfig/serviceintegration/serviceintegration.go index 6effef62f..a831ab9b3 100644 --- a/internal/sdkprovider/userconfig/integration/integration.go +++ b/internal/sdkprovider/userconfig/serviceintegration/serviceintegration.go @@ -1,6 +1,6 @@ // Code generated by user config generator. DO NOT EDIT. -package integration +package serviceintegration import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -28,3 +28,6 @@ func GetUserConfig(kind string) *schema.Schema { panic("unknown user config type: " + kind) } } +func UserConfigTypes() []string { + return []string{"clickhouse_kafka", "clickhouse_postgresql", "datadog", "external_aws_cloudwatch_metrics", "kafka_connect", "kafka_logs", "kafka_mirrormaker", "logs", "metrics"} +} diff --git a/ucgenerator/main.go b/ucgenerator/main.go index 617e63740..8361903e9 100644 --- a/ucgenerator/main.go +++ b/ucgenerator/main.go @@ -27,12 +27,12 @@ const ( func main() { var serviceList, integrationList string - flag.StringVar(&serviceList, "services", "", "Comma separated service list of names to generate for") - flag.StringVar(&integrationList, "integrations", "", "Comma separated integrations list of names to generate for") + flag.StringVar(&serviceList, "services", "", "Comma separated service list of names") + flag.StringVar(&integrationList, "integrations", "", "Comma separated integrations list of names") flag.Parse() if serviceList+integrationList == "" { - log.Fatal("--service or --integrations must be provided") + log.Fatal("--services or --integrations must be provided") } if serviceList != "" { @@ -43,7 +43,7 @@ func main() { } if integrationList != "" { - err := generate("integration", dist.IntegrationTypes, strings.Split(integrationList, ",")) + err := generate("serviceintegration", dist.IntegrationTypes, strings.Split(integrationList, ",")) if err != nil { log.Fatal(err) } @@ -51,7 +51,9 @@ func main() { } func generate(kind string, data []byte, keys []string) error { - slices.Sort(keys) + // Fixes imports order + imports.LocalPrefix = localPrefix + var root map[string]*object err := yaml.Unmarshal(data, &root) @@ -65,9 +67,7 @@ func generate(kind string, data []byte, keys []string) error { return err } - // Fixes imports order - imports.LocalPrefix = localPrefix - + slices.Sort(keys) doneKeys := make([]string, 0, len(keys)) doneNames := make([]string, 0, len(keys)) @@ -122,6 +122,14 @@ func generate(kind string, data []byte, keys []string) error { f.Func().Id("GetUserConfig").Params(jen.Id("kind").String()).Op("*").Qual(importSchema, "Schema").Block( jen.Switch(jen.Id("kind")).Block(cases...), ) + + configTypes := make([]jen.Code, 0) + for _, v := range keys { + configTypes = append(configTypes, jen.Lit(v)) + } + f.Func().Id("UserConfigTypes").Params().Index().String().Block( + jen.Return(jen.Index().String().Values(configTypes...)), + ) return f.Save(filepath.Join(dirPath, kind+".go")) }