From 2fcf7db50045d1d669554a5dbef084e79e1bef64 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Tue, 27 Feb 2024 10:27:18 +0100 Subject: [PATCH] refactor(aiven_service_integration_endpoint): new user configs --- CHANGELOG.md | 2 +- .../service_integration_endpoint.md | 2 +- .../resources/service_integration_endpoint.md | 4 +- .../serviceintegration/service_integration.go | 6 +- .../service_integration_endpoint.go | 158 +++++++++--------- ...ervice_integration_endpoint_data_source.go | 2 +- .../serviceintegrationendpoint/datadog.go | 72 ++++++++ .../external_aws_cloudwatch_logs.go | 41 +++++ .../external_aws_cloudwatch_metrics.go | 41 +++++ .../external_elasticsearch_logs.go | 46 +++++ .../external_google_cloud_bigquery.go | 31 ++++ .../external_google_cloud_logging.go | 36 ++++ .../external_kafka.go | 71 ++++++++ .../external_opensearch_logs.go | 46 +++++ .../external_postgresql.go | 64 +++++++ .../external_schema_registry.go | 44 +++++ .../serviceintegrationendpoint/jolokia.go | 32 ++++ .../serviceintegrationendpoint/prometheus.go | 32 ++++ .../serviceintegrationendpoint/rsyslog.go | 73 ++++++++ .../serviceintegrationendpoint.go | 41 +++++ ucgenerator/main.go | 8 +- 21 files changed, 764 insertions(+), 88 deletions(-) create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/datadog.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_logs.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_metrics.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_elasticsearch_logs.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_bigquery.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_logging.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_kafka.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_opensearch_logs.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_postgresql.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/external_schema_registry.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/jolokia.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/prometheus.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/rsyslog.go create mode 100644 internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 2895856c3..dc5697748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ nav_order: 1 -- Use new user config generator to generate service integration configs +- Use new user config generator to generate service integration and service integration endpoint configs - Fix `aiven_kafka_schema` version update - Add `external_aws_cloudwatch_logs`, `external_elasticsearch_logs_user_config`, `external_opensearch_logs_user_config`, `prometheus_user_config` service integration configs diff --git a/docs/data-sources/service_integration_endpoint.md b/docs/data-sources/service_integration_endpoint.md index a1ce5db11..c50610f97 100644 --- a/docs/data-sources/service_integration_endpoint.md +++ b/docs/data-sources/service_integration_endpoint.md @@ -31,7 +31,7 @@ data "aiven_service_integration_endpoint" "myendpoint" { - `datadog_user_config` (List of Object) Datadog user configurable settings (see [below for nested schema](#nestedatt--datadog_user_config)) - `endpoint_config` (Map of String) Integration endpoint specific backend configuration -- `endpoint_type` (String) Type of the service integration endpoint. Possible values: `datadog`, `prometheus`, `rsyslog`, `external_elasticsearch_logs`, `external_opensearch_logs`, `external_aws_cloudwatch_logs`, `external_google_cloud_logging`, `external_kafka`, `jolokia`, `external_schema_registry`, `external_aws_cloudwatch_metrics`, `external_google_cloud_bigquery`, `external_postgresql` +- `endpoint_type` (String) Type of the service integration endpoint. Possible values: `autoscaler`, `datadog`, `external_aws_cloudwatch_logs`, `external_aws_cloudwatch_metrics`, `external_aws_s3`, `external_clickhouse`, `external_elasticsearch_logs`, `external_google_cloud_bigquery`, `external_google_cloud_logging`, `external_kafka`, `external_mysql`, `external_opensearch_logs`, `external_postgresql`, `external_redis`, `external_schema_registry`, `jolokia`, `prometheus`, `rsyslog` - `external_aws_cloudwatch_logs_user_config` (List of Object) ExternalAwsCloudwatchLogs user configurable settings (see [below for nested schema](#nestedatt--external_aws_cloudwatch_logs_user_config)) - `external_aws_cloudwatch_metrics_user_config` (List of Object) ExternalAwsCloudwatchMetrics user configurable settings (see [below for nested schema](#nestedatt--external_aws_cloudwatch_metrics_user_config)) - `external_elasticsearch_logs_user_config` (List of Object) ExternalElasticsearchLogs user configurable settings (see [below for nested schema](#nestedatt--external_elasticsearch_logs_user_config)) diff --git a/docs/resources/service_integration_endpoint.md b/docs/resources/service_integration_endpoint.md index 1db753f42..cc6359419 100644 --- a/docs/resources/service_integration_endpoint.md +++ b/docs/resources/service_integration_endpoint.md @@ -18,7 +18,7 @@ The Service Integration Endpoint resource allows the creation and management of ### Required - `endpoint_name` (String) Name of the service integration endpoint -- `endpoint_type` (String) Type of the service integration endpoint. Possible values: `datadog`, `prometheus`, `rsyslog`, `external_elasticsearch_logs`, `external_opensearch_logs`, `external_aws_cloudwatch_logs`, `external_google_cloud_logging`, `external_kafka`, `jolokia`, `external_schema_registry`, `external_aws_cloudwatch_metrics`, `external_google_cloud_bigquery`, `external_postgresql` +- `endpoint_type` (String) Type of the service integration endpoint. Possible values: `autoscaler`, `datadog`, `external_aws_cloudwatch_logs`, `external_aws_cloudwatch_metrics`, `external_aws_s3`, `external_clickhouse`, `external_elasticsearch_logs`, `external_google_cloud_bigquery`, `external_google_cloud_logging`, `external_kafka`, `external_mysql`, `external_opensearch_logs`, `external_postgresql`, `external_redis`, `external_schema_registry`, `jolokia`, `prometheus`, `rsyslog` - `project` (String) Project the service integration endpoint belongs to ### Optional @@ -52,7 +52,7 @@ Required: Optional: -- `datadog_tags` (Block List, Max: 32) Custom tags provided by user. (see [below for nested schema](#nestedblock--datadog_user_config--datadog_tags)) +- `datadog_tags` (Block List, Max: 32) Custom tags provided by user (see [below for nested schema](#nestedblock--datadog_user_config--datadog_tags)) - `disable_consumer_stats` (Boolean) Disable consumer group metrics. - `kafka_consumer_check_instances` (Number) Number of separate instances to fetch kafka consumer statistics with. - `kafka_consumer_stats_timeout` (Number) Number of seconds that datadog will wait to get consumer statistics from brokers. diff --git a/internal/sdkprovider/service/serviceintegration/service_integration.go b/internal/sdkprovider/service/serviceintegration/service_integration.go index aca26c537..51d313a93 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration.go @@ -26,7 +26,7 @@ import ( const serviceIntegrationEndpointRegExp = "^[a-zA-Z0-9_-]*\\/{1}[a-zA-Z0-9_-]*$" -func hasConfig(kind string) bool { +func hasIntegrationConfig(kind string) bool { return slices.Contains(serviceintegration.UserConfigTypes(), kind) } @@ -143,7 +143,7 @@ func resourceServiceIntegrationCreate(ctx context.Context, d *schema.ResourceDat SourceService: schemautil.OptionalStringPointer(d, "source_service_name"), } - if hasConfig(integrationType) { + if hasIntegrationConfig(integrationType) { uc, err := converters.Expand(integrationType, serviceintegration.GetUserConfig(integrationType), d) if err != nil { return diag.FromErr(err) @@ -358,7 +358,7 @@ func resourceServiceIntegrationCopyAPIResponseToTerraform( return err } - if hasConfig(integrationType) { + if hasIntegrationConfig(integrationType) { userConfig, err := converters.Flatten(integrationType, serviceintegration.GetUserConfig(integrationType), d, res.UserConfig) if err != nil { return err diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go index a7ac30714..eee32f757 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go @@ -3,8 +3,10 @@ package serviceintegration import ( "context" "fmt" + "slices" "github.com/aiven/aiven-go-client/v2" + codegenintegrations "github.com/aiven/go-client-codegen/handler/serviceintegration" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" @@ -13,66 +15,59 @@ import ( "github.com/aiven/terraform-provider-aiven/internal/schemautil" "github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig" "github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig/apiconvert" - "github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig/dist" "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/serviceintegrationendpoint" ) -var integrationEndpointTypes = []string{ - "datadog", - "prometheus", - "rsyslog", - "external_elasticsearch_logs", - "external_opensearch_logs", - "external_aws_cloudwatch_logs", - "external_google_cloud_logging", - "external_kafka", - "jolokia", - "external_schema_registry", - "external_aws_cloudwatch_metrics", - "external_google_cloud_bigquery", - "external_postgresql", +func hasEndpointConfig(kind string) bool { + return slices.Contains(serviceintegrationendpoint.UserConfigTypes(), kind) } -var aivenServiceIntegrationEndpointSchema = map[string]*schema.Schema{ - "project": { - Description: "Project the service integration endpoint belongs to", - ForceNew: true, - Required: true, - Type: schema.TypeString, - }, - "endpoint_name": { - ForceNew: true, - Description: "Name of the service integration endpoint", - Required: true, - Type: schema.TypeString, - }, - "endpoint_type": { - Description: "Type of the service integration endpoint. Possible values: " + - schemautil.JoinQuoted(integrationEndpointTypes, ", ", "`"), - ForceNew: true, - Required: true, - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(integrationEndpointTypes, false), - }, - "endpoint_config": { - Description: "Integration endpoint specific backend configuration", - Computed: true, - Type: schema.TypeMap, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "datadog_user_config": dist.IntegrationEndpointTypeDatadog(), - "prometheus_user_config": dist.IntegrationEndpointTypePrometheus(), - "rsyslog_user_config": dist.IntegrationEndpointTypeRsyslog(), - "external_elasticsearch_logs_user_config": dist.IntegrationEndpointTypeExternalElasticsearchLogs(), - "external_opensearch_logs_user_config": dist.IntegrationEndpointTypeExternalOpensearchLogs(), - "external_aws_cloudwatch_logs_user_config": dist.IntegrationEndpointTypeExternalAwsCloudwatchLogs(), - "external_google_cloud_logging_user_config": dist.IntegrationEndpointTypeExternalGoogleCloudLogging(), - "external_kafka_user_config": dist.IntegrationEndpointTypeExternalKafka(), - "jolokia_user_config": dist.IntegrationEndpointTypeJolokia(), - "external_schema_registry_user_config": dist.IntegrationEndpointTypeExternalSchemaRegistry(), - "external_aws_cloudwatch_metrics_user_config": dist.IntegrationEndpointTypeExternalAwsCloudwatchMetrics(), - "external_google_cloud_bigquery": dist.IntegrationEndpointTypeExternalGoogleCloudBigquery(), - "external_postgresql": dist.IntegrationEndpointTypeExternalPostgresql(), +func endpointUserConfigKey(kind string) string { + switch kind { + case "external_google_cloud_bigquery", "external_postgresql": + // legacy fields + return kind + } + return kind + "_user_config" +} + +func aivenServiceIntegrationEndpointSchema() map[string]*schema.Schema { + s := map[string]*schema.Schema{ + "project": { + Description: "Project the service integration endpoint belongs to", + ForceNew: true, + Required: true, + Type: schema.TypeString, + }, + "endpoint_name": { + ForceNew: true, + Description: "Name of the service integration endpoint", + Required: true, + Type: schema.TypeString, + }, + "endpoint_type": { + Description: "Type of the service integration endpoint. Possible values: " + + schemautil.JoinQuoted(codegenintegrations.EndpointTypeChoices(), ", ", "`"), + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice(codegenintegrations.EndpointTypeChoices(), false), + }, + "endpoint_config": { + Description: "Integration endpoint specific backend configuration", + Computed: true, + Type: schema.TypeMap, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + } + + // Adds user configs + for _, k := range serviceintegrationendpoint.UserConfigTypes() { + s[endpointUserConfigKey(k)] = serviceintegrationendpoint.GetUserConfig(k) + } + return s } func ResourceServiceIntegrationEndpoint() *schema.Resource { @@ -87,7 +82,7 @@ func ResourceServiceIntegrationEndpoint() *schema.Resource { }, Timeouts: schemautil.DefaultResourceTimeouts(), - Schema: aivenServiceIntegrationEndpointSchema, + Schema: aivenServiceIntegrationEndpointSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.ServiceIntegrationEndpoint(), } @@ -98,20 +93,20 @@ func resourceServiceIntegrationEndpointCreate(ctx context.Context, d *schema.Res projectName := d.Get("project").(string) endpointType := d.Get("endpoint_type").(string) - userConfig, err := apiconvert.ToAPI(userconfig.IntegrationEndpointTypes, endpointType, d) - if err != nil { - return diag.FromErr(err) + req := aiven.CreateServiceIntegrationEndpointRequest{ + EndpointName: d.Get("endpoint_name").(string), + EndpointType: endpointType, } - endpoint, err := client.ServiceIntegrationEndpoints.Create( - ctx, - projectName, - aiven.CreateServiceIntegrationEndpointRequest{ - EndpointName: d.Get("endpoint_name").(string), - EndpointType: endpointType, - UserConfig: userConfig, - }, - ) + if hasEndpointConfig(endpointType) { + uc, err := converters.Expand(endpointType, serviceintegrationendpoint.GetUserConfig(endpointType), d) + if err != nil { + return diag.FromErr(err) + } + req.UserConfig = uc + } + + endpoint, err := client.ServiceIntegrationEndpoints.Create(ctx, projectName, req) if err != nil { return diag.FromErr(err) @@ -205,16 +200,6 @@ func copyServiceIntegrationEndpointPropertiesFromAPIResponseToTerraform( return err } - userConfig, err := apiconvert.FromAPI(userconfig.IntegrationEndpointTypes, endpointType, endpoint.UserConfig) - if err != nil { - return err - } - - if len(userConfig) > 0 { - if err := d.Set(endpointType+"_user_config", userConfig); err != nil { - return err - } - } // Must coerse all values into strings endpointConfig := map[string]string{} if len(endpoint.EndpointConfig) > 0 { @@ -223,5 +208,20 @@ func copyServiceIntegrationEndpointPropertiesFromAPIResponseToTerraform( } } - return d.Set("endpoint_config", endpointConfig) + if err := d.Set("endpoint_config", endpointConfig); err != nil { + return err + } + + if hasEndpointConfig(endpointType) { + userConfig, err := converters.Flatten(endpointType, serviceintegrationendpoint.GetUserConfig(endpointType), d, endpoint.UserConfig) + if err != nil { + return err + } + if len(userConfig) > 0 { + if err := d.Set(endpointUserConfigKey(endpointType), userConfig); err != nil { + return err + } + } + } + return nil } diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go index 479d74a48..fee48a421 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint_data_source.go @@ -14,7 +14,7 @@ func DatasourceServiceIntegrationEndpoint() *schema.Resource { return &schema.Resource{ ReadContext: datasourceServiceIntegrationEndpointRead, Description: "The Service Integration Endpoint data source provides information about the existing Aiven Service Integration Endpoint.", - Schema: schemautil.ResourceSchemaAsDatasourceSchema(aivenServiceIntegrationEndpointSchema, + Schema: schemautil.ResourceSchemaAsDatasourceSchema(aivenServiceIntegrationEndpointSchema(), "project", "endpoint_name"), } } diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/datadog.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/datadog.go new file mode 100644 index 000000000..6d99630bc --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/datadog.go @@ -0,0 +1,72 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func datadogUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "Datadog user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "datadog_api_key": { + Description: "Datadog API key.", + Required: true, + Sensitive: true, + Type: schema.TypeString, + }, + "datadog_tags": { + Description: "Custom tags provided by user", + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "comment": { + Description: "Optional tag explanation.", + Optional: true, + Type: schema.TypeString, + }, + "tag": { + Description: "Tag format and usage are described here: https://docs.datadoghq.com/getting_started/tagging. Tags with prefix 'aiven-' are reserved for Aiven.", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 32, + Optional: true, + Type: schema.TypeList, + }, + "disable_consumer_stats": { + Description: "Disable consumer group metrics.", + Optional: true, + Type: schema.TypeBool, + }, + "kafka_consumer_check_instances": { + Description: "Number of separate instances to fetch kafka consumer statistics with.", + Optional: true, + Type: schema.TypeInt, + }, + "kafka_consumer_stats_timeout": { + Description: "Number of seconds that datadog will wait to get consumer statistics from brokers.", + Optional: true, + Type: schema.TypeInt, + }, + "max_partition_contexts": { + Description: "Maximum number of partition contexts to send.", + Optional: true, + Type: schema.TypeInt, + }, + "site": { + Description: "Datadog intake site. Defaults to datadoghq.com.", + Optional: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"datadoghq.com", "datadoghq.eu", "us3.datadoghq.com", "us5.datadoghq.com", "ddog-gov.com"}, false), + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_logs.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_logs.go new file mode 100644 index 000000000..12a7be113 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_logs.go @@ -0,0 +1,41 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalAwsCloudwatchLogsUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalAwsCloudwatchLogs user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "access_key": { + Description: "AWS access key. Required permissions are logs:CreateLogGroup, logs:CreateLogStream, logs:PutLogEvents and logs:DescribeLogStreams.", + Required: true, + Type: schema.TypeString, + }, + "log_group_name": { + Description: "AWS CloudWatch log group name.", + Optional: true, + Type: schema.TypeString, + }, + "region": { + Description: "AWS region.", + Required: true, + Type: schema.TypeString, + }, + "secret_key": { + Description: "AWS secret key.", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_metrics.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_metrics.go new file mode 100644 index 000000000..b0e9b9cb1 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_aws_cloudwatch_metrics.go @@ -0,0 +1,41 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalAwsCloudwatchMetricsUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalAwsCloudwatchMetrics user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "access_key": { + Description: "AWS access key. Required permissions are cloudwatch:PutMetricData.", + Required: true, + Type: schema.TypeString, + }, + "namespace": { + Description: "AWS CloudWatch Metrics Namespace.", + Required: true, + Type: schema.TypeString, + }, + "region": { + Description: "AWS region.", + Required: true, + Type: schema.TypeString, + }, + "secret_key": { + Description: "AWS secret key.", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_elasticsearch_logs.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_elasticsearch_logs.go new file mode 100644 index 000000000..298c973d8 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_elasticsearch_logs.go @@ -0,0 +1,46 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalElasticsearchLogsUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalElasticsearchLogs user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "ca": { + Description: "PEM encoded CA certificate.", + Optional: true, + Type: schema.TypeString, + }, + "index_days_max": { + Description: "Maximum number of days of logs to keep. The default value is `3`.", + Optional: true, + Type: schema.TypeInt, + }, + "index_prefix": { + Description: "Elasticsearch index prefix. The default value is `logs`.", + Required: true, + Type: schema.TypeString, + }, + "timeout": { + Description: "Elasticsearch request timeout limit. The default value is `10.0`.", + Optional: true, + Type: schema.TypeFloat, + }, + "url": { + Description: "Elasticsearch connection URL.", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_bigquery.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_bigquery.go new file mode 100644 index 000000000..bbd06d935 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_bigquery.go @@ -0,0 +1,31 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalGoogleCloudBigqueryUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalGoogleCloudBigquery user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "project_id": { + Description: "GCP project id.", + Required: true, + Type: schema.TypeString, + }, + "service_account_credentials": { + Description: "This is a JSON object with the fields documented in https://cloud.google.com/iam/docs/creating-managing-service-account-keys .", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_logging.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_logging.go new file mode 100644 index 000000000..c1297acb1 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_google_cloud_logging.go @@ -0,0 +1,36 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalGoogleCloudLoggingUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalGoogleCloudLogging user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "log_id": { + Description: "Google Cloud Logging log id.", + Required: true, + Type: schema.TypeString, + }, + "project_id": { + Description: "GCP project id.", + Required: true, + Type: schema.TypeString, + }, + "service_account_credentials": { + Description: "This is a JSON object with the fields documented in https://cloud.google.com/iam/docs/creating-managing-service-account-keys .", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_kafka.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_kafka.go new file mode 100644 index 000000000..eccebdfe8 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_kafka.go @@ -0,0 +1,71 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalKafkaUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalKafka user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "bootstrap_servers": { + Description: "Bootstrap servers.", + Required: true, + Type: schema.TypeString, + }, + "sasl_mechanism": { + Description: "SASL mechanism used for connections to the Kafka server.", + Optional: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"PLAIN", "SCRAM-SHA-256", "SCRAM-SHA-512"}, false), + }, + "sasl_plain_password": { + Description: "Password for SASL PLAIN mechanism in the Kafka server.", + Optional: true, + Sensitive: true, + Type: schema.TypeString, + }, + "sasl_plain_username": { + Description: "Username for SASL PLAIN mechanism in the Kafka server.", + Optional: true, + Type: schema.TypeString, + }, + "security_protocol": { + Description: "Security protocol.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"PLAINTEXT", "SSL", "SASL_PLAINTEXT", "SASL_SSL"}, false), + }, + "ssl_ca_cert": { + Description: "PEM-encoded CA certificate.", + Optional: true, + Type: schema.TypeString, + }, + "ssl_client_cert": { + Description: "PEM-encoded client certificate.", + Optional: true, + Type: schema.TypeString, + }, + "ssl_client_key": { + Description: "PEM-encoded client key.", + Optional: true, + Type: schema.TypeString, + }, + "ssl_endpoint_identification_algorithm": { + Description: "The endpoint identification algorithm to validate server hostname using server certificate.", + Optional: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"https", ""}, false), + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_opensearch_logs.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_opensearch_logs.go new file mode 100644 index 000000000..9d2db6213 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_opensearch_logs.go @@ -0,0 +1,46 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalOpensearchLogsUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalOpensearchLogs user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "ca": { + Description: "PEM encoded CA certificate.", + Optional: true, + Type: schema.TypeString, + }, + "index_days_max": { + Description: "Maximum number of days of logs to keep. The default value is `3`.", + Optional: true, + Type: schema.TypeInt, + }, + "index_prefix": { + Description: "OpenSearch index prefix. The default value is `logs`.", + Required: true, + Type: schema.TypeString, + }, + "timeout": { + Description: "OpenSearch request timeout limit. The default value is `10.0`.", + Optional: true, + Type: schema.TypeFloat, + }, + "url": { + Description: "OpenSearch connection URL.", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_postgresql.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_postgresql.go new file mode 100644 index 000000000..c68080849 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_postgresql.go @@ -0,0 +1,64 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalPostgresqlUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalPostgresql user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "host": { + Description: "Hostname or IP address of the server.", + Required: true, + Type: schema.TypeString, + }, + "password": { + Description: "Password.", + Optional: true, + Sensitive: true, + Type: schema.TypeString, + }, + "port": { + Description: "Port number of the server.", + Required: true, + Type: schema.TypeInt, + }, + "ssl_client_certificate": { + Description: "Client certificate.", + Optional: true, + Type: schema.TypeString, + }, + "ssl_client_key": { + Description: "Client key.", + Optional: true, + Type: schema.TypeString, + }, + "ssl_mode": { + Description: "SSL Mode. The default value is `verify-full`.", + Optional: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"disable", "allow", "prefer", "require", "verify-ca", "verify-full"}, false), + }, + "ssl_root_cert": { + Description: "SSL Root Cert.", + Optional: true, + Type: schema.TypeString, + }, + "username": { + Description: "User name.", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_schema_registry.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_schema_registry.go new file mode 100644 index 000000000..8d73cad7c --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/external_schema_registry.go @@ -0,0 +1,44 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func externalSchemaRegistryUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "ExternalSchemaRegistry user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "authentication": { + Description: "Authentication method.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"none", "basic"}, false), + }, + "basic_auth_password": { + Description: "Basic authentication password.", + Optional: true, + Sensitive: true, + Type: schema.TypeString, + }, + "basic_auth_username": { + Description: "Basic authentication user name.", + Optional: true, + Type: schema.TypeString, + }, + "url": { + Description: "Schema Registry URL.", + Required: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/jolokia.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/jolokia.go new file mode 100644 index 000000000..0ae0a658c --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/jolokia.go @@ -0,0 +1,32 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func jolokiaUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "Jolokia user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "basic_auth_password": { + Description: "Jolokia basic authentication password.", + Optional: true, + Sensitive: true, + Type: schema.TypeString, + }, + "basic_auth_username": { + Description: "Jolokia basic authentication username.", + Optional: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/prometheus.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/prometheus.go new file mode 100644 index 000000000..91b28717c --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/prometheus.go @@ -0,0 +1,32 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func prometheusUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "Prometheus user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "basic_auth_password": { + Description: "Prometheus basic authentication password.", + Optional: true, + Sensitive: true, + Type: schema.TypeString, + }, + "basic_auth_username": { + Description: "Prometheus basic authentication username.", + Optional: true, + Type: schema.TypeString, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/rsyslog.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/rsyslog.go new file mode 100644 index 000000000..ff694ec5b --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/rsyslog.go @@ -0,0 +1,73 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + + "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/diff" +) + +func rsyslogUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "Rsyslog user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "ca": { + Description: "PEM encoded CA certificate.", + Optional: true, + Type: schema.TypeString, + }, + "cert": { + Description: "PEM encoded client certificate.", + Optional: true, + Type: schema.TypeString, + }, + "format": { + Description: "Message format. The default value is `rfc5424`.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"rfc5424", "rfc3164", "custom"}, false), + }, + "key": { + Description: "PEM encoded client key.", + Optional: true, + Type: schema.TypeString, + }, + "logline": { + Description: "Custom syslog message format.", + Optional: true, + Type: schema.TypeString, + }, + "max_message_size": { + Description: "Rsyslog max message size. The default value is `8192`.", + Optional: true, + Type: schema.TypeInt, + }, + "port": { + Description: "Rsyslog server port. The default value is `514`.", + Required: true, + Type: schema.TypeInt, + }, + "sd": { + Description: "Structured data block for log message.", + Optional: true, + Type: schema.TypeString, + }, + "server": { + Description: "Rsyslog server IP address or hostname.", + Required: true, + Type: schema.TypeString, + }, + "tls": { + Description: "Require TLS. The default value is `true`.", + Required: true, + Type: schema.TypeBool, + }, + }}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go new file mode 100644 index 000000000..c7d8635f9 --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go @@ -0,0 +1,41 @@ +// Code generated by user config generator. DO NOT EDIT. + +package serviceintegrationendpoint + +import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + +func GetUserConfig(kind string) *schema.Schema { + switch kind { + case "datadog": + return datadogUserConfig() + case "external_aws_cloudwatch_logs": + return externalAwsCloudwatchLogsUserConfig() + case "external_aws_cloudwatch_metrics": + return externalAwsCloudwatchMetricsUserConfig() + case "external_elasticsearch_logs": + return externalElasticsearchLogsUserConfig() + case "external_google_cloud_bigquery": + return externalGoogleCloudBigqueryUserConfig() + case "external_google_cloud_logging": + return externalGoogleCloudLoggingUserConfig() + case "external_kafka": + return externalKafkaUserConfig() + case "external_opensearch_logs": + return externalOpensearchLogsUserConfig() + case "external_postgresql": + return externalPostgresqlUserConfig() + case "external_schema_registry": + return externalSchemaRegistryUserConfig() + case "jolokia": + return jolokiaUserConfig() + case "prometheus": + return prometheusUserConfig() + case "rsyslog": + return rsyslogUserConfig() + default: + panic("unknown user config type: " + kind) + } +} +func UserConfigTypes() []string { + return []string{"datadog", "external_aws_cloudwatch_logs", "external_aws_cloudwatch_metrics", "external_elasticsearch_logs", "external_google_cloud_bigquery", "external_google_cloud_logging", "external_kafka", "external_opensearch_logs", "external_postgresql", "external_schema_registry", "jolokia", "prometheus", "rsyslog"} +} diff --git a/ucgenerator/main.go b/ucgenerator/main.go index 306106e58..15ea6a502 100644 --- a/ucgenerator/main.go +++ b/ucgenerator/main.go @@ -27,9 +27,10 @@ const ( ) func main() { - var serviceList, integrationList string + var serviceList, integrationList, endpointList string flag.StringVar(&serviceList, "excludeServices", "", "Comma separated list of names to exclude from generation") flag.StringVar(&integrationList, "excludeIntegrations", "", "Comma separated list of names to exclude from generation") + flag.StringVar(&endpointList, "excludeEndpoints", "", "Comma separated list of names to exclude from generation") flag.Parse() err := generate("service", dist.ServiceTypes, strings.Split(serviceList, ",")) @@ -41,6 +42,11 @@ func main() { if err != nil { log.Fatalf("generating integrations: %s", err) } + + err = generate("serviceintegrationendpoint", dist.IntegrationEndpointTypes, strings.Split(endpointList, ",")) + if err != nil { + log.Fatalf("generating integration endpoints: %s", err) + } } func generate(kind string, data []byte, exclude []string) error {