Skip to content

Commit

Permalink
feat(service_integration): add source and destination project names
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Dec 13, 2024
1 parent 08c8a97 commit 59a1699
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/service_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

<a id="nestedatt--clickhouse_kafka_user_config"></a>
### Nested Schema for `clickhouse_kafka_user_config`
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/service_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 59a1699

Please sign in to comment.