From 59a16996b63ee20187fbb84cb7bfa941abfcfab0 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Wed, 11 Dec 2024 15:59:05 +0100 Subject: [PATCH] feat(service_integration): add source and destination project names --- CHANGELOG.md | 4 + docs/data-sources/service_integration.md | 2 + docs/resources/service_integration.md | 2 + .../serviceintegration/service_integration.go | 24 +++++ .../service_integration_test.go | 100 ++++++++++++++++++ 5 files changed, 132 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50018cda8..bfadc5a9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ nav_order: 1 - Add `alloydbomni` BETA resource and datasource - Add `aiven_alloydbomni_user` BETA resource and datasource - Add `aiven_alloydbomni_database` BETA resource and datasource +- Add `aiven_service_integration` resource field `destination_service_project`: Destination service project name +- Add `aiven_service_integration` resource field `source_service_project`: Source service project name +- Add `aiven_service_integration` datasource field `destination_service_project`: Destination service project name +- Add `aiven_service_integration` datasource field `source_service_project`: Source service project name ## [4.30.0] - 2024-12-05 diff --git a/docs/data-sources/service_integration.md b/docs/data-sources/service_integration.md index b1afebde3..58325c1ed 100644 --- a/docs/data-sources/service_integration.md +++ b/docs/data-sources/service_integration.md @@ -37,6 +37,7 @@ data "aiven_service_integration" "example_integration" { - `clickhouse_postgresql_user_config` (List of Object) ClickhousePostgresql user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedatt--clickhouse_postgresql_user_config)) - `datadog_user_config` (List of Object) Datadog user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedatt--datadog_user_config)) - `destination_endpoint_id` (String) Destination endpoint for the integration. +- `destination_service_project` (String) Destination service project name - `external_aws_cloudwatch_logs_user_config` (List of Object) ExternalAwsCloudwatchLogs user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (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. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedatt--external_aws_cloudwatch_metrics_user_config)) - `external_elasticsearch_logs_user_config` (List of Object) ExternalElasticsearchLogs user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedatt--external_elasticsearch_logs_user_config)) @@ -51,6 +52,7 @@ data "aiven_service_integration" "example_integration" { - `metrics_user_config` (List of Object) Metrics user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedatt--metrics_user_config)) - `prometheus_user_config` (List of Object) Prometheus user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedatt--prometheus_user_config)) - `source_endpoint_id` (String) Source endpoint for the integration. +- `source_service_project` (String) Source service project name ### Nested Schema for `clickhouse_kafka_user_config` diff --git a/docs/resources/service_integration.md b/docs/resources/service_integration.md index e397a9157..bbe6cdb4f 100644 --- a/docs/resources/service_integration.md +++ b/docs/resources/service_integration.md @@ -68,6 +68,7 @@ resource "aiven_service_integration" "autoscaler_integration" { - `datadog_user_config` (Block List, Max: 1) Datadog user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedblock--datadog_user_config)) - `destination_endpoint_id` (String) Destination endpoint for the integration. - `destination_service_name` (String) Destination service for the integration. +- `destination_service_project` (String) Destination service project name - `external_aws_cloudwatch_logs_user_config` (Block List, Max: 1) ExternalAwsCloudwatchLogs user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedblock--external_aws_cloudwatch_logs_user_config)) - `external_aws_cloudwatch_metrics_user_config` (Block List, Max: 1) ExternalAwsCloudwatchMetrics user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedblock--external_aws_cloudwatch_metrics_user_config)) - `external_elasticsearch_logs_user_config` (Block List, Max: 1) ExternalElasticsearchLogs user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedblock--external_elasticsearch_logs_user_config)) @@ -81,6 +82,7 @@ resource "aiven_service_integration" "autoscaler_integration" { - `prometheus_user_config` (Block List, Max: 1) Prometheus user configurable settings. **Warning:** There's no way to reset advanced configuration options to default. Options that you add cannot be removed later (see [below for nested schema](#nestedblock--prometheus_user_config)) - `source_endpoint_id` (String) Source endpoint for the integration. - `source_service_name` (String) Source service for the integration (if any) +- `source_service_project` (String) Source service project name - `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts)) ### Read-Only diff --git a/internal/sdkprovider/service/serviceintegration/service_integration.go b/internal/sdkprovider/service/serviceintegration/service_integration.go index f85cfabdf..007f6ca59 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration.go @@ -44,6 +44,13 @@ func aivenServiceIntegrationSchema() map[string]*schema.Schema { Optional: true, Type: schema.TypeString, }, + "destination_service_project": { + Description: "Destination service project name", + ForceNew: true, + Optional: true, + Computed: true, + Type: schema.TypeString, + }, "integration_type": { Description: userconfig.Desc("Type of the service integration").PossibleValuesString(service.IntegrationTypeChoices()...).Build(), ForceNew: true, @@ -69,6 +76,14 @@ func aivenServiceIntegrationSchema() map[string]*schema.Schema { Description: "Source service for the integration (if any)", ForceNew: true, Optional: true, + Computed: true, + Type: schema.TypeString, + }, + "source_service_project": { + Description: "Source service project name", + ForceNew: true, + Optional: true, + Computed: true, Type: schema.TypeString, }, } @@ -132,6 +147,8 @@ func resourceServiceIntegrationCreate(ctx context.Context, d *schema.ResourceDat IntegrationType: service.IntegrationType(integrationType), SourceEndpointId: plainEndpointID(schemautil.OptionalStringPointer(d, "source_endpoint_id")), SourceService: schemautil.OptionalStringPointer(d, "source_service_name"), + DestProject: schemautil.OptionalStringPointer(d, "destination_service_project"), + SourceProject: schemautil.OptionalStringPointer(d, "source_service_project"), } uc, err := converters.Expand(converters.ServiceIntegrationUserConfig, integrationType, d) @@ -336,5 +353,12 @@ func resourceServiceIntegrationCopyAPIResponseToTerraform( return err } + if err := d.Set("destination_service_project", res.DestProject); err != nil { + return err + } + if err := d.Set("source_service_project", res.SourceProject); err != nil { + return err + } + return converters.Flatten(converters.ServiceIntegrationUserConfig, string(integrationType), d, res.UserConfig) } diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_test.go b/internal/sdkprovider/service/serviceintegration/service_integration_test.go index a52deb6fa..ee607193a 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_test.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_test.go @@ -761,3 +761,103 @@ func TestAccAivenServiceIntegration_autoscaler(t *testing.T) { }, }) } + +func TestAccAivenServiceIntegration_destination_service_name(t *testing.T) { + projectMetrics := os.Getenv("AIVEN_PROJECT_NAME") + projectServices := os.Getenv("AIVEN_PROJECT_NAME_SECONDARY") + if projectServices == "" { + t.Skip("AIVEN_PROJECT_NAME_SECONDARY is not set") + } + + thanosToGrafanaName := "aiven_service_integration.thanos_to_grafana" + kafkaToThanosName := "aiven_service_integration.kafka_to_thanos" + resource.ParallelTest(t, resource.TestCase{ + ProtoV6ProviderFactories: acc.TestProtoV6ProviderFactories, + CheckDestroy: testAccCheckAivenServiceIntegrationResourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAivenServiceIntegrationDestinationServiceName(projectMetrics, projectServices), + Check: resource.ComposeTestCheckFunc( + // Same source and destination project names + resource.TestCheckResourceAttr(thanosToGrafanaName, "integration_type", "dashboard"), + resource.TestCheckResourceAttr(thanosToGrafanaName, "source_service_project", projectMetrics), + resource.TestCheckResourceAttr(thanosToGrafanaName, "destination_service_project", projectMetrics), + + // Different source and destination project names + resource.TestCheckResourceAttr(kafkaToThanosName, "integration_type", "metrics"), + resource.TestCheckResourceAttr(kafkaToThanosName, "source_service_project", projectServices), + resource.TestCheckResourceAttr(kafkaToThanosName, "destination_service_project", projectMetrics), + ), + }, + }, + }) +} + +func testAccAivenServiceIntegrationDestinationServiceName(projectMetrics, projectService string) string { + return fmt.Sprintf(` +data "aiven_project" "metrics" { + project = %[1]q +} + +data "aiven_project" "services" { + project = %[2]q +} + +resource "aiven_grafana" "grafana" { + project = data.aiven_project.metrics.project + cloud_name = "google-europe-west1" + plan = "startup-1" + service_name = "test-acc-grafana-%[3]s" + maintenance_window_dow = "sunday" + maintenance_window_time = "10:00:00" + + grafana_user_config { + alerting_enabled = true + } +} + +resource "aiven_thanos" "thanos" { + project = data.aiven_project.metrics.project + cloud_name = "google-europe-west1" + plan = "startup-4" + service_name = "test-acc-thanos-%[3]s" + maintenance_window_dow = "sunday" + maintenance_window_time = "10:00:00" +} + +resource "aiven_kafka" "kafka_service" { + project = data.aiven_project.services.project + cloud_name = "google-europe-west1" + plan = "business-4" + service_name = "test-acc-kafka-%[3]s" + maintenance_window_dow = "sunday" + maintenance_window_time = "10:00:00" + + kafka_user_config { + schema_registry = true + kafka_rest = true + + kafka { + group_max_session_timeout_ms = 70000 + log_retention_bytes = 1000000000 + } + } +} + +resource "aiven_service_integration" "thanos_to_grafana" { + project = data.aiven_project.metrics.project + integration_type = "dashboard" + source_service_name = aiven_grafana.grafana.service_name // project "metrics" + destination_service_name = aiven_thanos.thanos.service_name // project "metrics" + destination_service_project = aiven_thanos.thanos.project +} + +resource "aiven_service_integration" "kafka_to_thanos" { + project = data.aiven_project.services.project + integration_type = "metrics" + source_service_name = aiven_kafka.kafka_service.service_name // project "services" + destination_service_name = aiven_thanos.thanos.service_name // project "metrics" + destination_service_project = aiven_thanos.thanos.project +} + `, projectMetrics, projectService, acc.RandStr()) +}