Skip to content

Commit

Permalink
feat(userconfig): integration endpoints support (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-savciuc authored Jan 5, 2024
1 parent 9501ff7 commit 5dea8cf
Show file tree
Hide file tree
Showing 19 changed files with 709 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/resources/service_integration_endpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions internal/schemautil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -872,10 +889,20 @@ 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)
}
}()
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
72 changes: 72 additions & 0 deletions internal/sdkprovider/userconfig/integration_endpoint/datadog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5dea8cf

Please sign in to comment.