diff --git a/CHANGELOG.md b/CHANGELOG.md index 12447df47..7ccb9df5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ nav_order: 1 # Changelog - +## [MAJOR.MINOR.PATCH] - YYYY-MM-DD + +- Add support for `autoscaler` service integration ## [4.28.0] - 2024-10-21 diff --git a/docs/data-sources/service_integration_endpoint.md b/docs/data-sources/service_integration_endpoint.md index 1129eb506..e7259e931 100644 --- a/docs/data-sources/service_integration_endpoint.md +++ b/docs/data-sources/service_integration_endpoint.md @@ -29,6 +29,7 @@ data "aiven_service_integration_endpoint" "myendpoint" { ### Read-Only +- `autoscaler_user_config` (List of Object) Autoscaler user configurable settings (see [below for nested schema](#nestedatt--autoscaler_user_config)) - `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. The possible values are `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_prometheus`, `external_redis`, `external_schema_registry`, `external_sumologic_logs`, `jolokia`, `prometheus` and `rsyslog`. @@ -50,6 +51,23 @@ data "aiven_service_integration_endpoint" "myendpoint" { - `prometheus_user_config` (List of Object) Prometheus user configurable settings (see [below for nested schema](#nestedatt--prometheus_user_config)) - `rsyslog_user_config` (List of Object) Rsyslog user configurable settings (see [below for nested schema](#nestedatt--rsyslog_user_config)) + +### Nested Schema for `autoscaler_user_config` + +Read-Only: + +- `autoscaling` (List of Object) (see [below for nested schema](#nestedobjatt--autoscaler_user_config--autoscaling)) + + +### Nested Schema for `autoscaler_user_config.autoscaling` + +Read-Only: + +- `cap_gb` (Number) +- `type` (String) + + + ### Nested Schema for `datadog_user_config` diff --git a/docs/resources/service_integration_endpoint.md b/docs/resources/service_integration_endpoint.md index e107e5dc2..8984e4814 100644 --- a/docs/resources/service_integration_endpoint.md +++ b/docs/resources/service_integration_endpoint.md @@ -23,6 +23,7 @@ The Service Integration Endpoint resource allows the creation and management of ### Optional +- `autoscaler_user_config` (Block List, Max: 1) Autoscaler user configurable settings (see [below for nested schema](#nestedblock--autoscaler_user_config)) - `datadog_user_config` (Block List, Max: 1) Datadog user configurable settings (see [below for nested schema](#nestedblock--datadog_user_config)) - `external_aws_cloudwatch_logs_user_config` (Block List, Max: 1) ExternalAwsCloudwatchLogs user configurable settings (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 (see [below for nested schema](#nestedblock--external_aws_cloudwatch_metrics_user_config)) @@ -47,6 +48,23 @@ The Service Integration Endpoint resource allows the creation and management of - `endpoint_config` (Map of String) Integration endpoint specific backend configuration - `id` (String) The ID of this resource. + +### Nested Schema for `autoscaler_user_config` + +Required: + +- `autoscaling` (Block List, Min: 1, Max: 64) Configure autoscaling thresholds for a service (see [below for nested schema](#nestedblock--autoscaler_user_config--autoscaling)) + + +### Nested Schema for `autoscaler_user_config.autoscaling` + +Required: + +- `cap_gb` (Number) The maximum total disk size (in gb) to allow autoscaler to scale up to. Example: `300`. +- `type` (String) Enum: `autoscale_disk`. Type of autoscale event. + + + ### Nested Schema for `datadog_user_config` diff --git a/go.mod b/go.mod index 861825761..d68d96cad 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/samber/lo v1.47.0 github.com/stoewer/go-strcase v1.3.0 github.com/stretchr/testify v1.9.0 - golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 + golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c golang.org/x/tools v0.26.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -59,7 +59,7 @@ require ( cloud.google.com/go v0.112.0 // indirect cloud.google.com/go/storage v1.36.0 // indirect github.com/agext/levenshtein v1.2.3 // indirect - github.com/aiven/go-api-schemas v1.94.0 + github.com/aiven/go-api-schemas v1.95.0 github.com/aws/aws-sdk-go v1.44.122 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 28d19cc1f..900741130 100644 --- a/go.sum +++ b/go.sum @@ -197,8 +197,8 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/aiven/aiven-go-client/v2 v2.30.0 h1:dj1nRuO1XglnwH2IwKmqEl3SGaqKebDoxnd+SRjxQRg= github.com/aiven/aiven-go-client/v2 v2.30.0/go.mod h1:Eyxa+fNgayObmUBW94uJuEkyOe1646cEpjFzhm/NETY= -github.com/aiven/go-api-schemas v1.94.0 h1:kbszL56VLORPZ2jXmQBP6FJpihcmiLGdH051G8zBRd0= -github.com/aiven/go-api-schemas v1.94.0/go.mod h1:qS3E/3R+aKQbHsqXzNHqlXATY1kbVNzhiJvk2IDmADI= +github.com/aiven/go-api-schemas v1.95.0 h1:3xGqlX1dwixNDZkUEpm4sn+qjwq8yb0usKubCx3icVA= +github.com/aiven/go-api-schemas v1.95.0/go.mod h1:ATdCq7aRp+URkFI4W4mVZaNZgoN5FRicXKH3c2fpgW4= github.com/aiven/go-client-codegen v0.45.0 h1:5+5eCN42Qb0QegJSYDw7WCi3z1IHemFyRxzJBN2TnaQ= github.com/aiven/go-client-codegen v0.45.0/go.mod h1:FfbH32Xb+Hx5zeKTIug1Y8SfMeB+AKNRzxgrzkts2oA= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -639,8 +639,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 h1:1wqE9dj9NpSm04INVsJhhEUzhuDVjbcyKH91sVyPATw= -golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8= +golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY= +golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/internal/schemautil/custom_diff.go b/internal/schemautil/custom_diff.go index 24f637912..ebf616d9c 100644 --- a/internal/schemautil/custom_diff.go +++ b/internal/schemautil/custom_diff.go @@ -2,26 +2,63 @@ package schemautil import ( "context" + "errors" "fmt" "strings" "github.com/aiven/aiven-go-client/v2" + avngen "github.com/aiven/go-client-codegen" + "github.com/aiven/go-client-codegen/handler/service" "github.com/docker/go-units" "github.com/hashicorp/go-cty/cty" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "golang.org/x/exp/slices" -) -func ServiceIntegrationShouldNotBeEmpty(_ context.Context, _, new, _ interface{}) bool { - return len(new.([]interface{})) != 0 -} + "github.com/aiven/terraform-provider-aiven/internal/common" +) -func DiskSpaceShouldNotBeEmpty(_ context.Context, _, new, _ interface{}) bool { - return new.(string) != "" +func CustomizeDiffGenericService(serviceType string) schema.CustomizeDiffFunc { + return customdiff.Sequence( + SetServiceTypeIfEmpty(serviceType), + CustomizeDiffDisallowMultipleManyToOneKeys, + customdiff.IfValueChange("tag", + ShouldNotBeEmpty, + CustomizeDiffCheckUniqueTag, + ), + customdiff.IfValueChange("disk_space", + ShouldNotBeEmpty, + CustomizeDiffCheckDiskSpace, + ), + customdiff.IfValueChange("additional_disk_space", + ShouldNotBeEmpty, + customdiff.Sequence( + CustomizeDiffCheckDiskSpace, + CustomizeDiffAdditionalDiskSpace, + ), + ), + customdiff.IfValueChange("service_integrations", + ShouldNotBeEmpty, + CustomizeDiffServiceIntegrationAfterCreation, + ), + customdiff.Sequence( + CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, + CustomizeDiffCheckStaticIPDisassociation, + ), + ) } -func TagsShouldNotBeEmpty(_ context.Context, _, new, _ interface{}) bool { - return len(new.(*schema.Set).List()) != 0 +func ShouldNotBeEmpty(_ context.Context, _, new, _ interface{}) bool { + switch t := new.(type) { + case string: + return t != "" + case []interface{}: + return len(t) != 0 + case *schema.Set: + return t.Len() != 0 + default: + panic(fmt.Sprintf("unexpected type: %T", t)) + } } func CustomizeDiffServiceIntegrationAfterCreation(_ context.Context, d *schema.ResourceDiff, _ interface{}) error { @@ -225,3 +262,61 @@ func checkForMultipleValues(v cty.Value) error { return nil } + +var ErrAutoscalerConflict = errors.New("autoscaler integration is enabled, additional_disk_space cannot be set") + +// CustomizeDiffAdditionalDiskSpace +// 1. checks that additional_disk_space is not set if autoscaler is enabled +// 2. outputs a diff for a computed field, which otherwise would be suppressed when removed +func CustomizeDiffAdditionalDiskSpace(ctx context.Context, diff *schema.ResourceDiff, _ interface{}) error { + client, err := common.GenClient() + if err != nil { + return err + } + + s, err := client.ServiceGet(ctx, diff.Get("project").(string), diff.Get("service_name").(string)) + if avngen.IsNotFound(err) { + // The service does not exist, so we cannot check if autoscaler is enabled + return nil + } + + if err != nil { + return err + } + + isAutoscalerEnabled := false + for _, i := range s.ServiceIntegrations { + if i.IntegrationType == service.IntegrationTypeAutoscaler { + isAutoscalerEnabled = true + break + } + } + + k := "additional_disk_space" + + // There are three possible sources of additional_disk_space value: + // 1. It is explicitly set in config file + // 2. Computed: disk_space - plan.disk_space = additional_disk_space + // 3. Computed: autoscaler is enabled, so additional_disk_space is managed by the autoscaler + if HasConfigValue(diff, k) || HasConfigValue(diff, "disk_space") { + if isAutoscalerEnabled { + // Autoscaler is enabled, so we cannot set additional_disk_space + return ErrAutoscalerConflict + } + + // It is in the config file, lets TF handle it + return nil + } + + if isAutoscalerEnabled { + // If the autoscaler is enabled, we don't need to manage the field, + // it will change its value automatically + return nil + } + + // It is not set but has a value (ShouldNotBeEmpty proves it has). + // That means the value is being removed. + // We must output a diff for the computed field, + // which otherwise will be suppressed by TF + return diff.SetNew(k, "0B") +} diff --git a/internal/schemautil/helpers.go b/internal/schemautil/helpers.go index ed903351d..8bc93a794 100644 --- a/internal/schemautil/helpers.go +++ b/internal/schemautil/helpers.go @@ -8,15 +8,22 @@ import ( "github.com/aiven/aiven-go-client/v2" "github.com/aiven/go-client-codegen/handler/service" "github.com/docker/go-units" + "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) // ResourceStateOrResourceDiff either *schema.ResourceState or *schema.ResourceDiff type ResourceStateOrResourceDiff interface { + GetRawConfig() cty.Value GetOk(key string) (interface{}, bool) Get(key string) interface{} } +func HasConfigValue(d ResourceStateOrResourceDiff, key string) bool { + c := d.GetRawConfig() + return !(c.IsNull() || c.AsValueMap()[key].IsNull()) +} + // PlanParameters service plan aparameters type PlanParameters struct { DiskSizeMBDefault int diff --git a/internal/schemautil/service.go b/internal/schemautil/service.go index 0d00fa544..6a2bf8bd7 100644 --- a/internal/schemautil/service.go +++ b/internal/schemautil/service.go @@ -158,6 +158,7 @@ func ServiceCommonSchema() map[string]*schema.Schema { "additional_disk_space": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "Add [disk storage](https://aiven.io/docs/platform/howto/add-storage-space) in increments of 30 GiB to scale your service. The maximum value depends on the service type and cloud provider. Removing additional storage causes the service nodes to go through a rolling restart and there might be a short downtime for services with no HA capabilities.", ValidateFunc: ValidateHumanByteSizeString, ConflictsWith: []string{"disk_space"}, @@ -471,13 +472,6 @@ func ResourceServiceUpdate(ctx context.Context, d *schema.ResourceData, m interf } } - // On service update, we send a default disc space value for a common - // if the TF user does not specify it - diskSpace, err := getDiskSpaceFromStateOrDiff(ctx, d, client) - if err != nil { - return diag.Errorf("error getting default disc space: %s", err) - } - projectName, serviceName, err := SplitResourceID2(d.Id()) if err != nil { return diag.Errorf("error splitting service id (%s): %s", d.Id(), err) @@ -518,10 +512,24 @@ func ResourceServiceUpdate(ctx context.Context, d *schema.ResourceData, m interf powered := true terminationProtection := d.Get("termination_protection").(bool) + // Sends disk size only when there is no autoscaler enabled var diskSpaceMb *int - if diskSpace > 0 { - diskSpaceMb = &diskSpace + s, err := avnGen.ServiceGet(ctx, projectName, serviceName) + if err != nil { + return nil + } + + if len(getIntegrationsForTerraform(s.ServiceIntegrations, service.IntegrationTypeAutoscaler)) == 0 { + diskSpace, err := getDiskSpaceFromStateOrDiff(ctx, d, client) + if err != nil { + return diag.Errorf("error getting default disc space: %s", err) + } + + if diskSpace > 0 { + diskSpaceMb = &diskSpace + } } + serviceUpdate := &service.ServiceUpdateIn{ Cloud: &cloud, Plan: &plan, @@ -564,11 +572,17 @@ func ResourceServiceUpdate(ctx context.Context, d *schema.ResourceData, m interf return ResourceServiceRead(ctx, d, m) } +// getDiskSpaceFromStateOrDiff three cases: +// 1. disk_space is set +// 2. plan disk space +// 3. plan disk space + additional_disk_space func getDiskSpaceFromStateOrDiff(ctx context.Context, d ResourceStateOrResourceDiff, client *aiven.Client) (int, error) { - var diskSpace int + if v, ok := d.GetOk("disk_space"); ok { + return ConvertToDiskSpaceMB(v.(string)), nil + } // Get service plan specific defaults - servicePlanParams, err := GetServicePlanParametersFromSchema(ctx, client, d) + plan, err := GetServicePlanParametersFromSchema(ctx, client, d) if err != nil { if aiven.IsNotFound(err) { return 0, nil @@ -576,15 +590,10 @@ func getDiskSpaceFromStateOrDiff(ctx context.Context, d ResourceStateOrResourceD return 0, fmt.Errorf("unable to get service plan parameters: %w", err) } - // Use `additional_disk_space` if set - if ads, ok := d.GetOk("additional_disk_space"); ok { - diskSpace = servicePlanParams.DiskSizeMBDefault + ConvertToDiskSpaceMB(ads.(string)) - } else if ds, ok := d.GetOk("disk_space"); ok { - // Use `disk_space` if set... - diskSpace = ConvertToDiskSpaceMB(ds.(string)) - } else { - // ... otherwise, use the default disk space - diskSpace = servicePlanParams.DiskSizeMBDefault + // Adds additional_disk_space only if it is in the config + diskSpace := plan.DiskSizeMBDefault + if HasConfigValue(d, "additional_disk_space") { + diskSpace += ConvertToDiskSpaceMB(d.Get("additional_disk_space").(string)) } return diskSpace, nil @@ -603,18 +612,18 @@ func getTechnicalEmailsForTerraform(s *service.ServiceGetOut) *schema.Set { return schema.NewSet(schema.HashResource(TechEmailsResourceSchema), techEmails) } -func getReadReplicaIntegrationsForTerraform(integrations []service.ServiceIntegrationOut) ([]map[string]interface{}, error) { - var readReplicaIntegrations []map[string]interface{} +func getIntegrationsForTerraform(integrations []service.ServiceIntegrationOut, integrationType service.IntegrationType) []map[string]interface{} { + var filteredIntegrations []map[string]interface{} for _, integration := range integrations { - if integration.IntegrationType == "read_replica" { + if integration.IntegrationType == integrationType { integrationMap := map[string]interface{}{ "integration_type": integration.IntegrationType, "source_service_name": integration.SourceService, } - readReplicaIntegrations = append(readReplicaIntegrations, integrationMap) + filteredIntegrations = append(filteredIntegrations, integrationMap) } } - return readReplicaIntegrations, nil + return filteredIntegrations } func ResourceServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { @@ -677,31 +686,17 @@ func copyServicePropertiesFromAPIResponseToTerraform( if s.DiskSpaceMb != nil { diskSpace = *s.DiskSpaceMb } - additionalDiskSpace := diskSpace - servicePlanParams.DiskSizeMBDefault - - _, isAdditionalDiskSpaceSet := d.GetOk("additional_disk_space") - _, isDiskSpaceSet := d.GetOk("disk_space") - // Handles two different cases: - // - // 1. During import when neither `additional_disk_space` nor `disk_space` are set - // 2. During create / update when `additional_disk_space` is set - if additionalDiskSpace > 0 && (!isDiskSpaceSet || isAdditionalDiskSpaceSet) { - if err := d.Set("additional_disk_space", HumanReadableByteSize(additionalDiskSpace*units.MiB)); err != nil { - return err - } - if err := d.Set("disk_space", nil); err != nil { - return err - } + additionalDiskSpace := diskSpace - servicePlanParams.DiskSizeMBDefault + if err := d.Set("additional_disk_space", HumanReadableByteSize(additionalDiskSpace*units.MiB)); err != nil { + return err } + _, isDiskSpaceSet := d.GetOk("disk_space") if isDiskSpaceSet && diskSpace > 0 { if err := d.Set("disk_space", HumanReadableByteSize(diskSpace*units.MiB)); err != nil { return err } - if err := d.Set("additional_disk_space", nil); err != nil { - return err - } } if err := d.Set("disk_space_used", HumanReadableByteSize(diskSpace*units.MiB)); err != nil { @@ -780,10 +775,7 @@ func copyServicePropertiesFromAPIResponseToTerraform( } // Handle read_replica service integrations - readReplicaIntegrations, err := getReadReplicaIntegrationsForTerraform(s.ServiceIntegrations) - if err != nil { - return err - } + readReplicaIntegrations := getIntegrationsForTerraform(s.ServiceIntegrations, service.IntegrationTypeReadReplica) if err := d.Set("service_integrations", readReplicaIntegrations); err != nil { return err } diff --git a/internal/schemautil/userconfig/stateupgrader/v0/cassandra/cassandra.go b/internal/schemautil/userconfig/stateupgrader/v0/cassandra/cassandra.go index 97855584d..15e1d700c 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/cassandra/cassandra.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/cassandra/cassandra.go @@ -39,19 +39,19 @@ func ResourceCassandra() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeCassandra), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/flink/flink.go b/internal/schemautil/userconfig/stateupgrader/v0/flink/flink.go index f8d2f20c1..624d34eba 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/flink/flink.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/flink/flink.go @@ -50,19 +50,19 @@ func ResourceFlink() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeFlink), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/grafana/grafana.go b/internal/schemautil/userconfig/stateupgrader/v0/grafana/grafana.go index acaa58c63..04cd43b62 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/grafana/grafana.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/grafana/grafana.go @@ -38,19 +38,19 @@ func ResourceGrafana() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeGrafana), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/influxdb/influxdb.go b/internal/schemautil/userconfig/stateupgrader/v0/influxdb/influxdb.go index f42374ed8..baa687796 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/influxdb/influxdb.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/influxdb/influxdb.go @@ -45,19 +45,19 @@ func ResourceInfluxDB() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeInfluxDB), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go index c95f017c0..bd164205a 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka.go @@ -98,19 +98,19 @@ func ResourceKafka() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeKafka), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_connect.go b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_connect.go index c5053d73f..8c2f6d3f4 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_connect.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_connect.go @@ -39,15 +39,15 @@ func ResourceKafkaConnect() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeKafkaConnect), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_mirrormaker.go b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_mirrormaker.go index eaab93bf6..9601af93c 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_mirrormaker.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/kafka/kafka_mirrormaker.go @@ -39,15 +39,15 @@ func ResourceKafkaMirrormaker() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeKafkaMirrormaker), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/m3/m3aggregator.go b/internal/schemautil/userconfig/stateupgrader/v0/m3/m3aggregator.go index 20ec96733..ac02fdbcc 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/m3/m3aggregator.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/m3/m3aggregator.go @@ -38,15 +38,15 @@ func ResourceM3Aggregator() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeM3Aggregator), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/m3/m3db.go b/internal/schemautil/userconfig/stateupgrader/v0/m3/m3db.go index fd096c77e..0c22b30ce 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/m3/m3db.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/m3/m3db.go @@ -39,19 +39,19 @@ func ResourceM3DBResource() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeM3), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/mysql/mysql.go b/internal/schemautil/userconfig/stateupgrader/v0/mysql/mysql.go index fe76a25df..cabd45f0c 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/mysql/mysql.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/mysql/mysql.go @@ -39,19 +39,19 @@ func ResourceMySQLResource() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeMySQL), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/opensearch/opensearch.go b/internal/schemautil/userconfig/stateupgrader/v0/opensearch/opensearch.go index 37623db98..bf41c3611 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/opensearch/opensearch.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/opensearch/opensearch.go @@ -46,19 +46,19 @@ func ResourceOpenSearch() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeOpenSearch), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/pg/pg.go b/internal/schemautil/userconfig/stateupgrader/v0/pg/pg.go index 1c4e2d17a..265b78bea 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/pg/pg.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/pg/pg.go @@ -89,19 +89,19 @@ func ResourcePG() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypePG), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/schemautil/userconfig/stateupgrader/v0/redis/redis.go b/internal/schemautil/userconfig/stateupgrader/v0/redis/redis.go index 7209bf2d1..380409d86 100644 --- a/internal/schemautil/userconfig/stateupgrader/v0/redis/redis.go +++ b/internal/schemautil/userconfig/stateupgrader/v0/redis/redis.go @@ -39,19 +39,19 @@ func ResourceRedis() *schema.Resource { schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeRedis), schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckDiskSpace, ), customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffServiceIntegrationAfterCreation, ), customdiff.Sequence( diff --git a/internal/sdkprovider/service/cassandra/cassandra.go b/internal/sdkprovider/service/cassandra/cassandra.go index 3199a493e..03cc41768 100644 --- a/internal/sdkprovider/service/cassandra/cassandra.go +++ b/internal/sdkprovider/service/cassandra/cassandra.go @@ -1,7 +1,6 @@ package cassandra import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -43,30 +42,7 @@ func ResourceCassandra() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeCassandra), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeCassandra), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, diff --git a/internal/sdkprovider/service/clickhouse/clickhouse.go b/internal/sdkprovider/service/clickhouse/clickhouse.go index 48661fd88..1c8fca371 100644 --- a/internal/sdkprovider/service/clickhouse/clickhouse.go +++ b/internal/sdkprovider/service/clickhouse/clickhouse.go @@ -1,7 +1,6 @@ package clickhouse import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -62,35 +61,11 @@ func ResourceClickhouse() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeClickhouse), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeClickhouse), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, Timeouts: schemautil.DefaultResourceTimeouts(), - - Schema: clickhouseSchema(), + Schema: clickhouseSchema(), } } diff --git a/internal/sdkprovider/service/dragonfly/dragonfly.go b/internal/sdkprovider/service/dragonfly/dragonfly.go index f8869f829..3e149ff03 100644 --- a/internal/sdkprovider/service/dragonfly/dragonfly.go +++ b/internal/sdkprovider/service/dragonfly/dragonfly.go @@ -1,7 +1,6 @@ package dragonfly import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -65,35 +64,11 @@ func ResourceDragonfly() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeDragonfly), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckStaticIPDisassociation, - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeDragonfly), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, Timeouts: schemautil.DefaultResourceTimeouts(), - - Schema: dragonflySchema(), + Schema: dragonflySchema(), } } diff --git a/internal/sdkprovider/service/flink/flink.go b/internal/sdkprovider/service/flink/flink.go index 4a683d800..a734689cd 100644 --- a/internal/sdkprovider/service/flink/flink.go +++ b/internal/sdkprovider/service/flink/flink.go @@ -5,7 +5,6 @@ import ( "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -48,35 +47,11 @@ func ResourceFlink() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: FlinkServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeFlink), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeFlink), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: aivenFlinkSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.Flink(), diff --git a/internal/sdkprovider/service/grafana/grafana.go b/internal/sdkprovider/service/grafana/grafana.go index 858c460a9..42b93dfc6 100644 --- a/internal/sdkprovider/service/grafana/grafana.go +++ b/internal/sdkprovider/service/grafana/grafana.go @@ -1,7 +1,6 @@ package grafana import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -43,35 +42,11 @@ func ResourceGrafana() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeGrafana), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeGrafana), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: grafanaSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.Grafana(), diff --git a/internal/sdkprovider/service/influxdb/influxdb.go b/internal/sdkprovider/service/influxdb/influxdb.go index c4fd32772..4b66f086f 100644 --- a/internal/sdkprovider/service/influxdb/influxdb.go +++ b/internal/sdkprovider/service/influxdb/influxdb.go @@ -1,7 +1,6 @@ package influxdb import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -61,35 +60,11 @@ func ResourceInfluxDB() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeInfluxDB), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeInfluxDB), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: influxDBSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.InfluxDB(), diff --git a/internal/sdkprovider/service/kafka/kafka.go b/internal/sdkprovider/service/kafka/kafka.go index fb9d22f6f..aa1b176dc 100644 --- a/internal/sdkprovider/service/kafka/kafka.go +++ b/internal/sdkprovider/service/kafka/kafka.go @@ -101,28 +101,7 @@ func ResourceKafka() *schema.Resource { Schema: aivenKafkaSchema(), CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeKafka), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), + schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeKafka), // if a kafka_version is >= 3.0 then this schema field is not applicable customdiff.ComputedIf("karapace", func(ctx context.Context, d *schema.ResourceDiff, m interface{}) bool { diff --git a/internal/sdkprovider/service/kafka/kafka_connect.go b/internal/sdkprovider/service/kafka/kafka_connect.go index c52c851ad..f31e82806 100644 --- a/internal/sdkprovider/service/kafka/kafka_connect.go +++ b/internal/sdkprovider/service/kafka/kafka_connect.go @@ -1,7 +1,6 @@ package kafka import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -29,26 +28,7 @@ To set up and integrate Kafka Connect: ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeKafkaConnect), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeKafkaConnect), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, diff --git a/internal/sdkprovider/service/kafka/kafka_mirrormaker.go b/internal/sdkprovider/service/kafka/kafka_mirrormaker.go index 83ee7c804..5653b3e2f 100644 --- a/internal/sdkprovider/service/kafka/kafka_mirrormaker.go +++ b/internal/sdkprovider/service/kafka/kafka_mirrormaker.go @@ -1,7 +1,6 @@ package kafka import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -18,31 +17,11 @@ func ResourceKafkaMirrormaker() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeKafkaMirrormaker), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeKafkaMirrormaker), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: aivenKafkaMirrormakerSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.KafkaMirrormaker(), diff --git a/internal/sdkprovider/service/m3db/m3aggregator.go b/internal/sdkprovider/service/m3db/m3aggregator.go index 318b41ce2..27b6a18be 100644 --- a/internal/sdkprovider/service/m3db/m3aggregator.go +++ b/internal/sdkprovider/service/m3db/m3aggregator.go @@ -1,7 +1,6 @@ package m3db import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -48,31 +47,11 @@ func ResourceM3Aggregator() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeM3Aggregator), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeM3Aggregator), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: aivenM3AggregatorSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.M3Aggregator(), diff --git a/internal/sdkprovider/service/m3db/m3db.go b/internal/sdkprovider/service/m3db/m3db.go index ff80390eb..539cb9498 100644 --- a/internal/sdkprovider/service/m3db/m3db.go +++ b/internal/sdkprovider/service/m3db/m3db.go @@ -1,7 +1,6 @@ package m3db import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -72,35 +71,11 @@ func ResourceM3DB() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeM3), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeM3), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: aivenM3DBSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.M3DB(), diff --git a/internal/sdkprovider/service/mysql/mysql.go b/internal/sdkprovider/service/mysql/mysql.go index ecb334e2b..4cf47835a 100644 --- a/internal/sdkprovider/service/mysql/mysql.go +++ b/internal/sdkprovider/service/mysql/mysql.go @@ -1,7 +1,6 @@ package mysql import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -117,35 +116,11 @@ func ResourceMySQL() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeMySQL), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeMySQL), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: aivenMySQLSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.MySQL(), diff --git a/internal/sdkprovider/service/opensearch/opensearch.go b/internal/sdkprovider/service/opensearch/opensearch.go index 6260fe301..96afe2572 100644 --- a/internal/sdkprovider/service/opensearch/opensearch.go +++ b/internal/sdkprovider/service/opensearch/opensearch.go @@ -1,7 +1,6 @@ package opensearch import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -68,35 +67,11 @@ func ResourceOpenSearch() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeOpenSearch), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - schemautil.CustomizeDiffCheckStaticIPDisassociation, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeOpenSearch), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: opensearchSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.OpenSearch(), diff --git a/internal/sdkprovider/service/pg/pg.go b/internal/sdkprovider/service/pg/pg.go index a0a144b40..41fa67378 100644 --- a/internal/sdkprovider/service/pg/pg.go +++ b/internal/sdkprovider/service/pg/pg.go @@ -7,7 +7,6 @@ import ( "github.com/aiven/aiven-go-client/v2" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -191,35 +190,11 @@ func ResourcePG() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: resourceServicePGUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypePG), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckStaticIPDisassociation, - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypePG), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: aivenPGSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.PG(), diff --git a/internal/sdkprovider/service/project/project.go b/internal/sdkprovider/service/project/project.go index cce4798e8..411753c00 100644 --- a/internal/sdkprovider/service/project/project.go +++ b/internal/sdkprovider/service/project/project.go @@ -139,7 +139,7 @@ func ResourceProject() *schema.Resource { Schema: aivenProjectSchema, CustomizeDiff: customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, + schemautil.ShouldNotBeEmpty, schemautil.CustomizeDiffCheckUniqueTag, ), } diff --git a/internal/sdkprovider/service/redis/redis.go b/internal/sdkprovider/service/redis/redis.go index e164eba07..70eb08473 100644 --- a/internal/sdkprovider/service/redis/redis.go +++ b/internal/sdkprovider/service/redis/redis.go @@ -1,7 +1,6 @@ package redis import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -66,35 +65,11 @@ func ResourceRedis() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeRedis), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckStaticIPDisassociation, - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeRedis), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - Timeouts: schemautil.DefaultResourceTimeouts(), - + Timeouts: schemautil.DefaultResourceTimeouts(), Schema: redisSchema(), SchemaVersion: 1, StateUpgraders: stateupgrader.Redis(), diff --git a/internal/sdkprovider/service/serviceintegration/service_integration_test.go b/internal/sdkprovider/service/serviceintegration/service_integration_test.go index 120992219..a52deb6fa 100644 --- a/internal/sdkprovider/service/serviceintegration/service_integration_test.go +++ b/internal/sdkprovider/service/serviceintegration/service_integration_test.go @@ -455,7 +455,6 @@ resource "aiven_service_integration" "bar" { cluster_alias = "source" } }` - } func testAccCheckAivenServiceIntegrationResourceDestroy(s *terraform.State) error { @@ -690,3 +689,75 @@ func TestAccAivenServiceIntegration_clickhouse_postgres_user_config_creates(t *t }, }) } + +func testAccServiceIntegrationAutoscaler(prefix string, includeDiskSpace bool) string { + additionalDiskSpace := "" + if includeDiskSpace { + additionalDiskSpace = `additional_disk_space = "30GiB"` + } + + return fmt.Sprintf(` +data "aiven_project" "project" { + project = %[1]q +} + +resource "aiven_pg" "test_pg" { + project = data.aiven_project.project.project + cloud_name = "google-europe-north1" + service_name = "%[2]s-pg" + plan = "startup-4" + %[3]s +} + +resource "aiven_service_integration_endpoint" "test_endpoint" { + project = data.aiven_project.project.project + endpoint_name = "%[2]s-autoscaler" + endpoint_type = "autoscaler" + + autoscaler_user_config { + autoscaling { + cap_gb = 200 + type = "autoscale_disk" + } + } +} + +resource "aiven_service_integration" "test_autoscaler" { + project = data.aiven_project.project.project + integration_type = "autoscaler" + source_service_name = aiven_pg.test_pg.service_name + destination_endpoint_id = aiven_service_integration_endpoint.test_endpoint.id +} +`, os.Getenv("AIVEN_PROJECT_NAME"), prefix, additionalDiskSpace) +} + +func TestAccAivenServiceIntegration_autoscaler(t *testing.T) { + project := os.Getenv("AIVEN_PROJECT_NAME") + prefix := "test-acc-" + acctest.RandString(7) + resourceName := "aiven_service_integration.test_autoscaler" + endpointResourceName := "aiven_service_integration_endpoint.test_endpoint" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { /* Add necessary pre-checks here */ }, + ProtoV6ProviderFactories: acc.TestProtoV6ProviderFactories, + CheckDestroy: testAccCheckAivenServiceIntegrationResourceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccServiceIntegrationAutoscaler(prefix, false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "integration_type", "autoscaler"), + resource.TestCheckResourceAttr(resourceName, "project", project), + resource.TestCheckResourceAttr(resourceName, "source_service_name", fmt.Sprintf("%s-pg", prefix)), + resource.TestCheckResourceAttrSet(resourceName, "destination_endpoint_id"), + resource.TestCheckResourceAttr(endpointResourceName, "project", project), + resource.TestCheckResourceAttr(endpointResourceName, "endpoint_name", fmt.Sprintf("%s-autoscaler", prefix)), + resource.TestCheckResourceAttr(endpointResourceName, "endpoint_type", "autoscaler"), + resource.TestCheckResourceAttr(endpointResourceName, "autoscaler_user_config.0.autoscaling.0.cap_gb", "200"), + ), + }, + { + Config: testAccServiceIntegrationAutoscaler(prefix, true), + ExpectError: regexp.MustCompile(schemautil.ErrAutoscalerConflict.Error()), + }, + }, + }) +} diff --git a/internal/sdkprovider/service/thanos/thanos.go b/internal/sdkprovider/service/thanos/thanos.go index 95333924e..3ba992df9 100644 --- a/internal/sdkprovider/service/thanos/thanos.go +++ b/internal/sdkprovider/service/thanos/thanos.go @@ -1,7 +1,6 @@ package thanos import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -60,35 +59,11 @@ func ResourceThanos() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeThanos), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckStaticIPDisassociation, - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeThanos), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, Timeouts: schemautil.DefaultResourceTimeouts(), - - Schema: thanosSchema(), + Schema: thanosSchema(), } } diff --git a/internal/sdkprovider/service/valkey/valkey.go b/internal/sdkprovider/service/valkey/valkey.go index 1c2cf06e2..7682eb952 100644 --- a/internal/sdkprovider/service/valkey/valkey.go +++ b/internal/sdkprovider/service/valkey/valkey.go @@ -1,7 +1,6 @@ package valkey import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/aiven/terraform-provider-aiven/internal/schemautil" @@ -65,35 +64,11 @@ func ResourceValkey() *schema.Resource { ReadContext: schemautil.ResourceServiceRead, UpdateContext: schemautil.ResourceServiceUpdate, DeleteContext: schemautil.ResourceServiceDelete, - CustomizeDiff: customdiff.Sequence( - schemautil.SetServiceTypeIfEmpty(schemautil.ServiceTypeValkey), - schemautil.CustomizeDiffDisallowMultipleManyToOneKeys, - customdiff.IfValueChange("tag", - schemautil.TagsShouldNotBeEmpty, - schemautil.CustomizeDiffCheckUniqueTag, - ), - customdiff.IfValueChange("disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("additional_disk_space", - schemautil.DiskSpaceShouldNotBeEmpty, - schemautil.CustomizeDiffCheckDiskSpace, - ), - customdiff.IfValueChange("service_integrations", - schemautil.ServiceIntegrationShouldNotBeEmpty, - schemautil.CustomizeDiffServiceIntegrationAfterCreation, - ), - customdiff.Sequence( - schemautil.CustomizeDiffCheckStaticIPDisassociation, - schemautil.CustomizeDiffCheckPlanAndStaticIpsCannotBeModifiedTogether, - ), - ), + CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeValkey), Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, Timeouts: schemautil.DefaultResourceTimeouts(), - - Schema: valkeySchema(), + Schema: valkeySchema(), } } diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/autoscaler.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/autoscaler.go new file mode 100644 index 000000000..b9423f9ea --- /dev/null +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/autoscaler.go @@ -0,0 +1,39 @@ +// 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 autoscalerUserConfig() *schema.Schema { + return &schema.Schema{ + Description: "Autoscaler user configurable settings", + DiffSuppressFunc: diff.SuppressUnchanged, + Elem: &schema.Resource{Schema: map[string]*schema.Schema{"autoscaling": { + Description: "Configure autoscaling thresholds for a service", + Elem: &schema.Resource{Schema: map[string]*schema.Schema{ + "cap_gb": { + Description: "The maximum total disk size (in gb) to allow autoscaler to scale up to. Example: `300`.", + Required: true, + Type: schema.TypeInt, + }, + "type": { + Description: "Enum: `autoscale_disk`. Type of autoscale event.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"autoscale_disk"}, false), + }, + }}, + MaxItems: 64, + Required: true, + Type: schema.TypeList, + }}}, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + } +} diff --git a/internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go b/internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go index f2c18f706..917c6885e 100644 --- a/internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go +++ b/internal/sdkprovider/userconfig/serviceintegrationendpoint/serviceintegrationendpoint.go @@ -6,6 +6,8 @@ import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" func GetUserConfig(kind string) *schema.Schema { switch kind { + case "autoscaler": + return autoscalerUserConfig() case "datadog": return datadogUserConfig() case "external_aws_cloudwatch_logs": @@ -50,5 +52,5 @@ func GetFieldMapping(kind string) map[string]string { return map[string]map[string]string{}[kind] } func UserConfigTypes() []string { - return []string{"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_prometheus", "external_schema_registry", "jolokia", "prometheus", "rsyslog"} + return []string{"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_prometheus", "external_schema_registry", "jolokia", "prometheus", "rsyslog"} } diff --git a/main.go b/main.go index 3371916a0..88dac20fb 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( "github.com/aiven/terraform-provider-aiven/internal/server" ) -//go:generate go run ./ucgenerator/... --excludeServices elasticsearch,alloydbomni --excludeEndpoints autoscaler +//go:generate go run ./ucgenerator/... --excludeServices elasticsearch,alloydbomni // registryPrefix is the registry prefix for the provider. const registryPrefix = "registry.terraform.io/"