From 5dea8cf99107dff3f539d4df5c0385534ccc467b Mon Sep 17 00:00:00 2001 From: Ivan Savciuc Date: Fri, 5 Jan 2024 13:01:24 +0200 Subject: [PATCH] feat(userconfig): integration endpoints support (#1509) --- .../resources/service_integration_endpoint.md | 2 +- internal/schemautil/service.go | 27 +++++++ .../service_integration_endpoint.go | 36 +++++----- .../integration_endpoint/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 ++++++++++ .../integration_endpoint/external_kafka.go | 71 ++++++++++++++++++ .../external_opensearch_logs.go | 46 ++++++++++++ .../external_postgresql.go | 54 ++++++++++++++ .../external_schema_registry.go | 44 ++++++++++++ .../integration_endpoint.go | 38 ++++++++++ .../integration_endpoint/jolokia.go | 32 +++++++++ .../integration_endpoint/prometheus.go | 32 +++++++++ .../integration_endpoint/rsyslog.go | 68 ++++++++++++++++++ main.go | 1 + ucgenerator/main.go | 14 +++- 19 files changed, 709 insertions(+), 23 deletions(-) create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/datadog.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_aws_cloudwatch_logs.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_aws_cloudwatch_metrics.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_elasticsearch_logs.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_google_cloud_bigquery.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_google_cloud_logging.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_kafka.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_opensearch_logs.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_postgresql.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/external_schema_registry.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/integration_endpoint.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/jolokia.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/prometheus.go create mode 100644 internal/sdkprovider/userconfig/integration_endpoint/rsyslog.go diff --git a/docs/resources/service_integration_endpoint.md b/docs/resources/service_integration_endpoint.md index e41ae8c7f..8e67565fd 100644 --- a/docs/resources/service_integration_endpoint.md +++ b/docs/resources/service_integration_endpoint.md @@ -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/schemautil/service.go b/internal/schemautil/service.go index 1deded1d9..7ee9163c3 100644 --- a/internal/schemautil/service.go +++ b/internal/schemautil/service.go @@ -16,6 +16,7 @@ import ( "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/integration_endpoint" "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/service" ) @@ -63,6 +64,20 @@ const ( ServiceIntegrationTypeExternalLogsAWS = "external_aws_cloudwatch_logs" ServiceIntegrationTypeExternalLogsOS = "external_opensearch_logs" ServiceIntegrationTypeExternalMetrics = "external_aws_cloudwatch_metrics" + + ServiceIntegrationEndpointTypeDatadog = "datadog" + ServiceIntegrationEndpointTypeExternalAwsCloudwatchLogs = "external_aws_cloudwatch_logs" + ServiceIntegrationEndpointTypeExternalAwsCloudwatchMetrics = "external_aws_cloudwatch_metrics" + ServiceIntegrationEndpointTypeExternalElasticsearchLogs = "external_elasticsearch_logs" + ServiceIntegrationEndpointTypeExternalGoogleCloudBigquery = "external_google_cloud_bigquery" + ServiceIntegrationEndpointTypeExternalGoogleCloudLogging = "external_google_cloud_logging" + ServiceIntegrationEndpointTypeExternalKafka = "external_kafka" + ServiceIntegrationEndpointTypeExternalOpensearchLogs = "external_opensearch_logs" + ServiceIntegrationEndpointTypeExternalPostgresql = "external_postgresql" + ServiceIntegrationEndpointTypeExternalSchemaRegistry = "external_schema_registry" + ServiceIntegrationEndpointTypeJolokia = "jolokia" + ServiceIntegrationEndpointTypePrometheus = "prometheus" + ServiceIntegrationEndpointTypeRsyslog = "rsyslog" ) func ServiceCommonSchema() map[string]*schema.Schema { @@ -863,6 +878,8 @@ func FlattenService(kind string, d *schema.ResourceData, dto map[string]any) ([] } func FlattenServiceIntegration(kind string, d *schema.ResourceData, dto map[string]any) ([]map[string]any, error) { + // Many service integration types have the empty user_config, and GetUserConfig returns panic for empty user_config's + // So we need to handle this case separately defer func() { if err := recover(); err != nil { log.Printf("[WARN] Recovered from panic in FlattenServiceIntegration: %v", err) @@ -872,6 +889,8 @@ func FlattenServiceIntegration(kind string, d *schema.ResourceData, dto map[stri } func ExpandServiceIntegration(kind string, d *schema.ResourceData) (map[string]any, error) { + // Many service integration types have the empty user_config, and GetUserConfig returns panic for empty user_config's + // So we need to handle this case separately defer func() { if err := recover(); err != nil { log.Printf("[WARN] Recovered from panic in ExpandServiceIntegration: %v", err) @@ -879,3 +898,11 @@ func ExpandServiceIntegration(kind string, d *schema.ResourceData) (map[string]a }() return converters.Expand(kind, integration.GetUserConfig(kind), d) } + +func FlattenServiceIntegrationEndpoint(kind string, d *schema.ResourceData, dto map[string]any) ([]map[string]any, error) { + return converters.Flatten(kind, integration_endpoint.GetUserConfig(kind), d, dto) +} + +func ExpandServiceIntegrationEndpoint(kind string, d *schema.ResourceData) (map[string]any, error) { + return converters.Expand(kind, integration_endpoint.GetUserConfig(kind), d) +} diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go index f2e720a5e..4a16a74c8 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_endpoint.go @@ -10,10 +10,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "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/integration_endpoint" ) var integrationEndpointTypes = []string{ @@ -59,19 +57,19 @@ var aivenServiceIntegrationEndpointSchema = map[string]*schema.Schema{ 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(), + "datadog_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeDatadog), + "prometheus_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypePrometheus), + "rsyslog_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeRsyslog), + "external_elasticsearch_logs_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalElasticsearchLogs), + "external_opensearch_logs_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalOpensearchLogs), + "external_aws_cloudwatch_logs_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalAwsCloudwatchLogs), + "external_google_cloud_logging_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalGoogleCloudLogging), + "external_kafka_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalKafka), + "jolokia_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeJolokia), + "external_schema_registry_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalSchemaRegistry), + "external_aws_cloudwatch_metrics_user_config": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalAwsCloudwatchMetrics), + "external_google_cloud_bigquery": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalGoogleCloudBigquery), + "external_postgresql": integration_endpoint.GetUserConfig(schemautil.ServiceIntegrationEndpointTypeExternalPostgresql), } func ResourceServiceIntegrationEndpoint() *schema.Resource { @@ -97,7 +95,7 @@ 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) + userConfig, err := schemautil.ExpandServiceIntegrationEndpoint(endpointType, d) if err != nil { return diag.FromErr(err) } @@ -152,7 +150,7 @@ func resourceServiceIntegrationEndpointUpdate(ctx context.Context, d *schema.Res endpointType := d.Get("endpoint_type").(string) - userConfig, err := apiconvert.ToAPI(userconfig.IntegrationEndpointTypes, endpointType, d) + userConfig, err := schemautil.ExpandServiceIntegrationEndpoint(endpointType, d) if err != nil { return diag.FromErr(err) } @@ -204,7 +202,7 @@ func copyServiceIntegrationEndpointPropertiesFromAPIResponseToTerraform( return err } - userConfig, err := apiconvert.FromAPI(userconfig.IntegrationEndpointTypes, endpointType, endpoint.UserConfig) + userConfig, err := schemautil.FlattenServiceIntegrationEndpoint(endpointType, d, endpoint.UserConfig) if err != nil { return err } diff --git a/internal/sdkprovider/userconfig/integration_endpoint/datadog.go b/internal/sdkprovider/userconfig/integration_endpoint/datadog.go new file mode 100644 index 000000000..0479c0cb3 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/datadog.go @@ -0,0 +1,72 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_aws_cloudwatch_logs.go b/internal/sdkprovider/userconfig/integration_endpoint/external_aws_cloudwatch_logs.go new file mode 100644 index 000000000..a81c60f8d --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_aws_cloudwatch_logs.go @@ -0,0 +1,41 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_aws_cloudwatch_metrics.go b/internal/sdkprovider/userconfig/integration_endpoint/external_aws_cloudwatch_metrics.go new file mode 100644 index 000000000..5ec59ea76 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_aws_cloudwatch_metrics.go @@ -0,0 +1,41 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_elasticsearch_logs.go b/internal/sdkprovider/userconfig/integration_endpoint/external_elasticsearch_logs.go new file mode 100644 index 000000000..b87dfcb26 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_elasticsearch_logs.go @@ -0,0 +1,46 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_google_cloud_bigquery.go b/internal/sdkprovider/userconfig/integration_endpoint/external_google_cloud_bigquery.go new file mode 100644 index 000000000..b35efc420 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_google_cloud_bigquery.go @@ -0,0 +1,31 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_google_cloud_logging.go b/internal/sdkprovider/userconfig/integration_endpoint/external_google_cloud_logging.go new file mode 100644 index 000000000..e8eb804e9 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_google_cloud_logging.go @@ -0,0 +1,36 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_kafka.go b/internal/sdkprovider/userconfig/integration_endpoint/external_kafka.go new file mode 100644 index 000000000..2c0aa84fe --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_kafka.go @@ -0,0 +1,71 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_opensearch_logs.go b/internal/sdkprovider/userconfig/integration_endpoint/external_opensearch_logs.go new file mode 100644 index 000000000..4685368eb --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_opensearch_logs.go @@ -0,0 +1,46 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/external_postgresql.go b/internal/sdkprovider/userconfig/integration_endpoint/external_postgresql.go new file mode 100644 index 000000000..c2994e9b6 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_postgresql.go @@ -0,0 +1,54 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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.", + Required: true, + Sensitive: true, + Type: schema.TypeString, + }, + "port": { + Description: "Port number of the server.", + Required: true, + Type: schema.TypeInt, + }, + "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/integration_endpoint/external_schema_registry.go b/internal/sdkprovider/userconfig/integration_endpoint/external_schema_registry.go new file mode 100644 index 000000000..88a3ef035 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/external_schema_registry.go @@ -0,0 +1,44 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/integration_endpoint.go b/internal/sdkprovider/userconfig/integration_endpoint/integration_endpoint.go new file mode 100644 index 000000000..770feec77 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/integration_endpoint.go @@ -0,0 +1,38 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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) + } +} diff --git a/internal/sdkprovider/userconfig/integration_endpoint/jolokia.go b/internal/sdkprovider/userconfig/integration_endpoint/jolokia.go new file mode 100644 index 000000000..9131f6282 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/jolokia.go @@ -0,0 +1,32 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/prometheus.go b/internal/sdkprovider/userconfig/integration_endpoint/prometheus.go new file mode 100644 index 000000000..67aef8ad6 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/prometheus.go @@ -0,0 +1,32 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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/integration_endpoint/rsyslog.go b/internal/sdkprovider/userconfig/integration_endpoint/rsyslog.go new file mode 100644 index 000000000..f18744477 --- /dev/null +++ b/internal/sdkprovider/userconfig/integration_endpoint/rsyslog.go @@ -0,0 +1,68 @@ +// Code generated by user config generator. DO NOT EDIT. + +package integration_endpoint + +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, + }, + "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/main.go b/main.go index 217c0797b..c6bf1a70d 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( //go:generate go test -tags userconfig ./internal/schemautil/userconfig //go:generate go run ./ucgenerator/... --services cassandra,clickhouse,flink,grafana,influxdb,kafka,kafka_connect,kafka_mirrormaker,m3aggregator,m3db,mysql,opensearch,pg,redis //go:generate go run ./ucgenerator/... --integrations clickhouse_kafka,clickhouse_postgresql,datadog,external_aws_cloudwatch_logs,external_aws_cloudwatch_metrics,external_elasticsearch_logs,external_opensearch_logs,kafka_connect,kafka_logs,kafka_mirrormaker,logs,metrics,prometheus +//go:generate go run ./ucgenerator/... --integration-endpoints 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 const registryPrefix = "registry.terraform.io/" // version is the version of the provider. diff --git a/ucgenerator/main.go b/ucgenerator/main.go index 3707392c0..55164ac88 100644 --- a/ucgenerator/main.go +++ b/ucgenerator/main.go @@ -26,13 +26,14 @@ const ( ) func main() { - var serviceList, integrationList string + var serviceList, integrationList, integrationEndpointList 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(&integrationEndpointList, "integration-endpoints", "", "Comma separated integration endpoints list of names to generate for") flag.Parse() - if serviceList+integrationList == "" { - log.Fatal("--service or --integrations must be provided") + if serviceList+integrationList+integrationEndpointList == "" { + log.Fatal("--service or --integrations or --integration-endpoints must be provided") } if serviceList != "" { @@ -48,6 +49,13 @@ func main() { log.Fatal(err) } } + + if integrationEndpointList != "" { + err := generate("integration_endpoint", dist.IntegrationEndpointTypes, strings.Split(integrationEndpointList, ",")) + if err != nil { + log.Fatal(err) + } + } } func generate(kind string, data []byte, keys []string) error {