From 4eb44a856f25f3e7fd4d1976e17ae96bd5e033c2 Mon Sep 17 00:00:00 2001 From: Murad Biashimov Date: Thu, 5 Sep 2024 09:10:32 +0200 Subject: [PATCH] feat: use generated service get (#1823) --- CHANGELOG.md | 1 + docs/resources/opensearch.md | 2 +- docs/resources/pg.md | 2 +- docs/resources/thanos.md | 2 +- go.mod | 5 +- go.sum | 16 +- internal/common/client.go | 5 + internal/schemautil/helpers.go | 5 +- internal/schemautil/service.go | 223 +++++++++--------- .../service/opensearch/opensearch.go | 1 + internal/sdkprovider/service/pg/pg.go | 1 + internal/sdkprovider/service/thanos/thanos.go | 1 + .../sdkprovider/service/thanos/thanos_test.go | 4 - 13 files changed, 130 insertions(+), 138 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52ac2e81a..b9afc1e65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ nav_order: 1 - Add `prefix_path_depth` to `kafka_user_config.kafka_connect_secret_providers.vault` - Add `backup_hour` and `backup_minute` to `redis_user_config` and `valkey_user_config` - Add user configuration options for `external_s3`, `external_clickhouse` and `external_mysql` integration endpoint types +- Use `ServiceGet` from the code-generated client ## [4.24.0] - 2024-08-21 diff --git a/docs/resources/opensearch.md b/docs/resources/opensearch.md index af306874e..26bce839b 100644 --- a/docs/resources/opensearch.md +++ b/docs/resources/opensearch.md @@ -88,7 +88,7 @@ Optional: Read-Only: -- `kibana_uri` (String, Sensitive) URI for Kibana dashboard frontend +- `kibana_uri` (String, Sensitive, Deprecated) URI for Kibana dashboard frontend - `opensearch_dashboards_uri` (String, Sensitive) URI for OpenSearch dashboard frontend - `password` (String, Sensitive) OpenSearch password - `username` (String, Sensitive) OpenSearch username diff --git a/docs/resources/pg.md b/docs/resources/pg.md index 2e09a2314..cc4dee5ba 100644 --- a/docs/resources/pg.md +++ b/docs/resources/pg.md @@ -103,7 +103,7 @@ Optional: Read-Only: -- `bouncer` (String, Sensitive) PgBouncer connection details for [connection pooling](https://aiven.io/docs/products/postgresql/concepts/pg-connection-pooling). +- `bouncer` (String, Sensitive, Deprecated) PgBouncer connection details for [connection pooling](https://aiven.io/docs/products/postgresql/concepts/pg-connection-pooling). - `dbname` (String, Sensitive) Primary PostgreSQL database name. - `host` (String, Sensitive) PostgreSQL primary node host IP or name. - `max_connections` (Number, Sensitive) The [number of allowed connections](https://aiven.io/docs/products/postgresql/reference/pg-connection-limits). Varies based on the service plan. diff --git a/docs/resources/thanos.md b/docs/resources/thanos.md index 3c9be55e3..6c3ea6d9d 100644 --- a/docs/resources/thanos.md +++ b/docs/resources/thanos.md @@ -98,7 +98,7 @@ Read-Only: - `query_uri` (String, Sensitive) Query URI. - `receiver_ingesting_remote_write_uri` (String, Sensitive) Receiver ingesting remote write URI. - `receiver_remote_write_uri` (String, Sensitive) Receiver remote write URI. -- `store_uri` (String, Sensitive) Store URI. +- `store_uri` (String, Sensitive, Deprecated) Store URI. diff --git a/go.mod b/go.mod index 9a6690860..ddd54cab1 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22 require ( github.com/aiven/aiven-go-client/v2 v2.26.0 - github.com/aiven/go-client-codegen v0.19.0 + github.com/aiven/go-client-codegen v0.26.0 github.com/avast/retry-go v3.0.0+incompatible github.com/dave/jennifer v1.7.0 github.com/docker/go-units v0.5.0 @@ -39,9 +39,6 @@ require ( github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.7 // indirect - github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/spf13/cobra v1.8.1 // indirect - github.com/spf13/pflag v1.0.5 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect diff --git a/go.sum b/go.sum index 56ef58553..cd7457e3e 100644 --- a/go.sum +++ b/go.sum @@ -199,12 +199,10 @@ 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.26.0 h1:1dBlF0BULbPsRXEEmcKs71AE3VZ+AYt5zv05LO/b8O4= github.com/aiven/aiven-go-client/v2 v2.26.0/go.mod h1:KdHfLIlIRZIfCSEBd39j1Q81jlSb6Nd+oCQKqERfnuA= -github.com/aiven/go-api-schemas v1.83.0 h1:qqJgCfd2bAbAN7CJr+oBKLYggn0+0bDsBzitFCNlvzg= -github.com/aiven/go-api-schemas v1.83.0/go.mod h1:/F7Rr8UVErsRxhgGN7CSo+Ac/uAg/OiAVCEKCfm3VAo= github.com/aiven/go-api-schemas v1.85.0 h1:wpTCQWjTLKQvVQq184u6Ji0ZksDZkNPqS6f6zrZ+nGU= github.com/aiven/go-api-schemas v1.85.0/go.mod h1:/F7Rr8UVErsRxhgGN7CSo+Ac/uAg/OiAVCEKCfm3VAo= -github.com/aiven/go-client-codegen v0.19.0 h1:AL2jDa7iVLZw2M5r23nLoLCfiGt18qjc1LNdWZvrsJQ= -github.com/aiven/go-client-codegen v0.19.0/go.mod h1:Sajbdpjn1/m5g2D6EDfiSnxl9pj9hxe8+hpG1CkCkhs= +github.com/aiven/go-client-codegen v0.26.0 h1:GtOL+KYWsjY02pZr0rrjZaTeq3gkDrccKaNS33Ss2lI= +github.com/aiven/go-client-codegen v0.26.0/go.mod h1:6AHM+oM2tNc10eOfPeyiTWFObkVz2dZY2gqRkTPQoVo= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= @@ -242,7 +240,6 @@ github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/PB79y4KOPYVyFYdROxgaCwdTQ= github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= -github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= @@ -462,8 +459,6 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= -github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= @@ -539,7 +534,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/samber/lo v1.46.0 h1:w8G+oaCPgz1PoCJztqymCFaKwXt+5cCXn51uPxExFfQ= github.com/samber/lo v1.46.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= @@ -548,11 +542,7 @@ github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A= github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= -github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= -github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= -github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs= github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -639,8 +629,6 @@ 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-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= -golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 h1:kx6Ds3MlpiUHKj7syVnbp57++8WpuKPcR5yjLBjvLEA= golang.org/x/exp v0.0.0-20240823005443-9b4947da3948/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= diff --git a/internal/common/client.go b/internal/common/client.go index 0454be032..b7b0eb31e 100644 --- a/internal/common/client.go +++ b/internal/common/client.go @@ -73,6 +73,11 @@ func CacheGenAivenClient(token, tfVersion, buildVersion string) error { return nil } +// GenClient returns cached client. +func GenClient() avngen.Client { + return clientCache +} + type crudHandler func(context.Context, *schema.ResourceData, avngen.Client) error // WithGenClient wraps CRUD handlers and runs with avngen.Client diff --git a/internal/schemautil/helpers.go b/internal/schemautil/helpers.go index e1b87ab99..13cb17a72 100644 --- a/internal/schemautil/helpers.go +++ b/internal/schemautil/helpers.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/aiven/aiven-go-client/v2" + "github.com/aiven/go-client-codegen/handler/service" "github.com/docker/go-units" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) @@ -79,8 +80,8 @@ func ConvertToDiskSpaceMB(b string) int { return int(diskSizeMB / units.MiB) } -func GetServicePlanParametersFromServiceResponse(ctx context.Context, client *aiven.Client, project string, service *aiven.Service) (PlanParameters, error) { - return getServicePlanParametersInternal(ctx, client, project, service.Type, service.Plan) +func GetServicePlanParametersFromServiceResponse(ctx context.Context, client *aiven.Client, project string, s *service.ServiceGetOut) (PlanParameters, error) { + return getServicePlanParametersInternal(ctx, client, project, s.ServiceType, s.Plan) } func GetServicePlanParametersFromSchema(ctx context.Context, client *aiven.Client, d ResourceStateOrResourceDiff) (PlanParameters, error) { diff --git a/internal/schemautil/service.go b/internal/schemautil/service.go index 413030ca8..549bceafb 100644 --- a/internal/schemautil/service.go +++ b/internal/schemautil/service.go @@ -9,11 +9,13 @@ import ( "time" "github.com/aiven/aiven-go-client/v2" + "github.com/aiven/go-client-codegen/handler/service" "github.com/docker/go-units" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/common" "github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/converters" ) @@ -319,7 +321,8 @@ func ResourceServiceRead(ctx context.Context, d *schema.ResourceData, m interfac return diag.Errorf("error splitting service ID: %s", err) } - s, err := client.Services.Get(ctx, projectName, serviceName) + avnGen := common.GenClient() + s, err := avnGen.ServiceGet(ctx, projectName, serviceName, service.ServiceGetIncludeSecrets(true)) if err != nil { if err = ResourceReadHandleNotFound(err, d); err != nil { return diag.Errorf("unable to GET service %s: %s", d.Id(), err) @@ -554,14 +557,14 @@ func getDefaultDiskSpaceIfNotSet(ctx context.Context, d *schema.ResourceData, cl return diskSpace, nil } -func getTechnicalEmailsForTerraform(d *schema.ResourceData, field string, s *aiven.Service) *schema.Set { +func getTechnicalEmailsForTerraform(d *schema.ResourceData, field string, s *service.ServiceGetOut) *schema.Set { _, ok := d.GetOk(field) - if !ok && len(s.TechnicalEmails) == 0 { + if !ok && len(s.TechEmails) == 0 { return nil } - techEmails := make([]interface{}, len(s.TechnicalEmails)) - for i, e := range s.TechnicalEmails { + techEmails := make([]interface{}, len(s.TechEmails)) + for i, e := range s.TechEmails { techEmails[i] = map[string]interface{}{"email": e.Email} } @@ -590,19 +593,19 @@ func ResourceServiceDelete(ctx context.Context, d *schema.ResourceData, m interf func copyServicePropertiesFromAPIResponseToTerraform( d *schema.ResourceData, - s *aiven.Service, + s *service.ServiceGetOut, servicePlanParams PlanParameters, project string, ) error { serviceType := d.Get("service_type").(string) if _, ok := d.GetOk("service_type"); !ok { - serviceType = s.Type + serviceType = s.ServiceType } if err := d.Set("cloud_name", s.CloudName); err != nil { return err } - if err := d.Set("service_name", s.Name); err != nil { + if err := d.Set("service_name", s.ServiceName); err != nil { return err } if err := d.Set("state", s.State); err != nil { @@ -617,24 +620,30 @@ func copyServicePropertiesFromAPIResponseToTerraform( if err := d.Set("termination_protection", s.TerminationProtection); err != nil { return err } - if err := d.Set("maintenance_window_dow", s.MaintenanceWindow.DayOfWeek); err != nil { + if err := d.Set("maintenance_window_dow", s.Maintenance.Dow); err != nil { return err } - if err := d.Set("maintenance_window_time", s.MaintenanceWindow.TimeOfDay); err != nil { + if err := d.Set("maintenance_window_time", s.Maintenance.Time); err != nil { return err } - if _, ok := d.GetOk("disk_space"); ok && s.DiskSpaceMB != 0 { - if err := d.Set("disk_space", HumanReadableByteSize(s.DiskSpaceMB*units.MiB)); err != nil { + + diskSpace := 0 + if s.DiskSpaceMb != nil { + diskSpace = int(*s.DiskSpaceMb) + } + + if _, ok := d.GetOk("disk_space"); ok && diskSpace != 0 { + if err := d.Set("disk_space", HumanReadableByteSize(diskSpace*units.MiB)); err != nil { return err } } - if _, ok := d.GetOk("additional_disk_space"); ok && s.DiskSpaceMB != 0 { - if err := d.Set("additional_disk_space", HumanReadableByteSize((s.DiskSpaceMB-servicePlanParams.DiskSizeMBDefault)*units.MiB)); err != nil { + if _, ok := d.GetOk("additional_disk_space"); ok && diskSpace != 0 { + if err := d.Set("additional_disk_space", HumanReadableByteSize((diskSpace-servicePlanParams.DiskSizeMBDefault)*units.MiB)); err != nil { return err } } - if err := d.Set("disk_space_used", HumanReadableByteSize(s.DiskSpaceMB*units.MiB)); err != nil { + if err := d.Set("disk_space_used", HumanReadableByteSize(diskSpace*units.MiB)); err != nil { return err } if err := d.Set("disk_space_default", HumanReadableByteSize(servicePlanParams.DiskSizeMBDefault*units.MiB)); err != nil { @@ -646,7 +655,7 @@ func copyServicePropertiesFromAPIResponseToTerraform( if err := d.Set("disk_space_cap", HumanReadableByteSize(servicePlanParams.DiskSizeMBMax*units.MiB)); err != nil { return err } - if err := d.Set("service_uri", s.URI); err != nil { + if err := d.Set("service_uri", s.ServiceUri); err != nil { return err } if err := d.Set("project", project); err != nil { @@ -657,8 +666,8 @@ func copyServicePropertiesFromAPIResponseToTerraform( return err } - if s.ProjectVPCID != nil { - if err := d.Set("project_vpc_id", BuildResourceID(project, *s.ProjectVPCID)); err != nil { + if s.ProjectVpcId != "" { + if err := d.Set("project_vpc_id", BuildResourceID(project, s.ProjectVpcId)); err != nil { return err } } @@ -668,12 +677,12 @@ func copyServicePropertiesFromAPIResponseToTerraform( return err } - params := s.URIParams + params := s.ServiceUriParams if err := d.Set("service_host", params["host"]); err != nil { return err } - port, _ := strconv.ParseInt(params["port"], 10, 32) + port, _ := strconv.ParseInt(fmt.Sprintf("%v", params["port"]), 10, 32) if err := d.Set("service_port", port); err != nil { return err } @@ -712,7 +721,7 @@ func copyServicePropertiesFromAPIResponseToTerraform( return copyConnectionInfoFromAPIResponseToTerraform(d, serviceType, s.ConnectionInfo, s.Metadata) } -func FlattenServiceComponents(r *aiven.Service) []map[string]interface{} { +func FlattenServiceComponents(r *service.ServiceGetOut) []map[string]interface{} { components := make([]map[string]interface{}, len(r.Components)) for i, c := range r.Components { @@ -740,157 +749,149 @@ func FlattenServiceComponents(r *aiven.Service) []map[string]interface{} { func copyConnectionInfoFromAPIResponseToTerraform( d *schema.ResourceData, serviceType string, - connectionInfo aiven.ConnectionInfo, - metadata interface{}, + connectionInfo *service.ConnectionInfoOut, + metadata map[string]any, ) error { - props := make(map[string]interface{}) + props := make(map[string]any) switch serviceType { case ServiceTypeKafka: // KafkaHosts will be renamed to KafkaURIs in the next major version of the Go client. // That's why we name the props key `uris` here. - props["uris"] = connectionInfo.KafkaHosts - props["access_cert"] = connectionInfo.KafkaAccessCert - props["access_key"] = connectionInfo.KafkaAccessKey - props["connect_uri"] = connectionInfo.KafkaConnectURI - props["rest_uri"] = connectionInfo.KafkaRestURI - props["schema_registry_uri"] = connectionInfo.SchemaRegistryURI + props["uris"] = connectionInfo.Kafka + setProp(props, "access_cert", connectionInfo.KafkaAccessCert) + setProp(props, "access_key", connectionInfo.KafkaAccessKey) + setProp(props, "connect_uri", connectionInfo.KafkaConnectUri) + setProp(props, "rest_uri", connectionInfo.KafkaRestUri) + setProp(props, "schema_registry_uri", connectionInfo.SchemaRegistryUri) case ServiceTypePG: // For compatibility with the old schema, we only set the first URI. // TODO: Remove this block in the next major version. Keep `uris` key only, see below. - if connectionInfo.PostgresURIs != nil && len(connectionInfo.PostgresURIs) > 0 { - props["uri"] = connectionInfo.PostgresURIs[0] + if len(connectionInfo.Pg) > 0 { + props["uri"] = connectionInfo.Pg[0] } - props["uris"] = connectionInfo.PostgresURIs // Keep this instead of `uri` key. - props["bouncer"] = connectionInfo.PostgresBouncer - - // For compatibility with the old schema, we only set the first params. - // TODO: Remove this block in the next major version. Keep `params` key only, see below. - if connectionInfo.PostgresParams != nil && len(connectionInfo.PostgresParams) > 0 { - params := connectionInfo.PostgresParams[0] - - props["host"] = params.Host - - port, err := strconv.ParseInt(params.Port, 10, 32) - if err == nil { - props["port"] = int(port) - } - - props["sslmode"] = params.SSLMode - props["user"] = params.User - props["password"] = params.Password - props["dbname"] = params.DatabaseName - - } - - // Keep this instead of the above block. - params := make([]map[string]interface{}, len(connectionInfo.PostgresParams)) - for i, p := range connectionInfo.PostgresParams { + props["uris"] = connectionInfo.Pg + params := make([]map[string]any, len(connectionInfo.PgParams)) + for i, p := range connectionInfo.PgParams { port, err := strconv.ParseInt(p.Port, 10, 32) if err != nil { return err } - params[i] = map[string]interface{}{ + if i == 0 { + // For compatibility with the old schema, we only set the first params. + // TODO: Remove this block in the next major version. Keep `params` key only. + props["host"] = p.Host + props["port"] = port + props["sslmode"] = p.Sslmode + props["user"] = p.User + props["password"] = p.Password + props["dbname"] = p.Dbname + } + + params[i] = map[string]any{ "host": p.Host, "port": port, - "sslmode": p.SSLMode, + "sslmode": p.Sslmode, "user": p.User, "password": p.Password, - "database_name": p.DatabaseName, + "database_name": p.Dbname, } } props["params"] = params - props["replica_uri"] = connectionInfo.PostgresReplicaURI - props["standby_uris"] = connectionInfo.PostgresStandbyURIs - props["syncing_uris"] = connectionInfo.PostgresSyncingURIs + props["standby_uris"] = connectionInfo.PgStandby + props["syncing_uris"] = connectionInfo.PgSyncing + setProp(props, "replica_uri", connectionInfo.PgReplicaUri) // TODO: This isn't in the connection info, but it's in the metadata. // We should move this to the other part of the schema in the next major version. - props["max_connections"] = metadata.(map[string]interface{})["max_connections"] + props["max_connections"] = metadata["max_connections"] case ServiceTypeThanos: - props["uris"] = connectionInfo.ThanosURIs - props["query_frontend_uri"] = connectionInfo.QueryFrontendURI - props["query_uri"] = connectionInfo.QueryURI - props["receiver_ingesting_remote_write_uri"] = connectionInfo.ReceiverIngestingRemoteWriteURI - props["receiver_remote_write_uri"] = connectionInfo.ReceiverRemoteWriteURI - props["store_uri"] = connectionInfo.StoreURI + props["uris"] = connectionInfo.Thanos + setProp(props, "query_frontend_uri", connectionInfo.QueryFrontendUri) + setProp(props, "query_uri", connectionInfo.QueryUri) + setProp(props, "receiver_ingesting_remote_write_uri", connectionInfo.ReceiverIngestingRemoteWriteUri) + setProp(props, "receiver_remote_write_uri", connectionInfo.ReceiverRemoteWriteUri) case ServiceTypeMySQL: - props["uris"] = connectionInfo.MySQLURIs + props["uris"] = connectionInfo.Mysql - params := make([]map[string]interface{}, len(connectionInfo.MySQLParams)) - for i, p := range connectionInfo.MySQLParams { + params := make([]map[string]any, len(connectionInfo.MysqlParams)) + for i, p := range connectionInfo.MysqlParams { port, err := strconv.ParseInt(p.Port, 10, 32) if err != nil { return err } - params[i] = map[string]interface{}{ + params[i] = map[string]any{ "host": p.Host, "port": port, - "sslmode": p.SSLMode, + "sslmode": p.SslMode, "user": p.User, "password": p.Password, - "database_name": p.DatabaseName, + "database_name": p.Dbname, } } props["params"] = params - props["replica_uri"] = connectionInfo.MySQLReplicaURI - props["standby_uris"] = connectionInfo.MySQLStandbyURIs + props["standby_uris"] = connectionInfo.MysqlStandby + setProp(props, "replica_uri", connectionInfo.MysqlReplicaUri) case ServiceTypeOpenSearch: - props["uris"] = connectionInfo.OpensearchURIs + props["uris"] = connectionInfo.Opensearch // TODO: Remove `opensearch_` prefix in the next major version. - props["opensearch_dashboards_uri"] = connectionInfo.OpensearchDashboardsURI - - props["kibana_uri"] = connectionInfo.KibanaURI - props["username"] = connectionInfo.OpensearchUsername - props["password"] = connectionInfo.OpensearchPassword + setProp(props, "opensearch_dashboards_uri", connectionInfo.OpensearchDashboardsUri) + setProp(props, "username", connectionInfo.OpensearchUsername) + setProp(props, "password", connectionInfo.OpensearchPassword) case ServiceTypeCassandra: // CassandraHosts will be renamed to CassandraURIs in the next major version of the Go client. // That's why we name the props key `uris` here. - props["uris"] = connectionInfo.CassandraHosts + props["uris"] = connectionInfo.Cassandra case ServiceTypeRedis, ServiceTypeDragonfly: - props["uris"] = connectionInfo.RedisURIs - props["slave_uris"] = connectionInfo.RedisSlaveURIs - props["replica_uri"] = connectionInfo.RedisReplicaURI - props["password"] = connectionInfo.RedisPassword + props["uris"] = connectionInfo.Redis + props["slave_uris"] = connectionInfo.RedisSlave + setProp(props, "replica_uri", connectionInfo.RedisReplicaUri) + setProp(props, "password", connectionInfo.RedisPassword) case ServiceTypeValkey: - props["uris"] = connectionInfo.ValkeyURIs - props["slave_uris"] = connectionInfo.ValkeySlaveURIs - props["replica_uri"] = connectionInfo.ValkeyReplicaURI - props["password"] = connectionInfo.ValkeyPassword + props["uris"] = connectionInfo.Valkey + props["slave_uris"] = connectionInfo.ValkeySlave + setProp(props, "replica_uri", connectionInfo.ValkeyReplicaUri) + setProp(props, "password", connectionInfo.ValkeyPassword) case ServiceTypeInfluxDB: - props["uris"] = connectionInfo.InfluxDBURIs - props["username"] = connectionInfo.InfluxDBUsername - props["password"] = connectionInfo.InfluxDBPassword - props["database_name"] = connectionInfo.InfluxDBDatabaseName + props["uris"] = connectionInfo.Influxdb + setProp(props, "username", connectionInfo.InfluxdbUsername) + setProp(props, "password", connectionInfo.InfluxdbPassword) + setProp(props, "database_name", connectionInfo.InfluxdbDbname) case ServiceTypeGrafana: - props["uris"] = connectionInfo.GrafanaURIs + props["uris"] = connectionInfo.Grafana case ServiceTypeM3: - props["uris"] = connectionInfo.M3DBURIs - props["http_cluster_uri"] = connectionInfo.HTTPClusterURI - props["http_node_uri"] = connectionInfo.HTTPNodeURI - props["influxdb_uri"] = connectionInfo.InfluxDBURI - props["prometheus_remote_read_uri"] = connectionInfo.PrometheusRemoteReadURI - props["prometheus_remote_write_uri"] = connectionInfo.PrometheusRemoteWriteURI + props["uris"] = connectionInfo.M3Db + setProp(props, "http_cluster_uri", connectionInfo.HttpClusterUri) + setProp(props, "http_node_uri", connectionInfo.HttpNodeUri) + setProp(props, "influxdb_uri", connectionInfo.InfluxdbUri) + setProp(props, "prometheus_remote_read_uri", connectionInfo.PrometheusRemoteReadUri) + setProp(props, "prometheus_remote_write_uri", connectionInfo.PrometheusRemoteWriteUri) case ServiceTypeM3Aggregator: - props["uris"] = connectionInfo.M3AggregatorURIs - props["aggregator_http_uri"] = connectionInfo.AggregatorHTTPURI + props["uris"] = connectionInfo.M3Aggregator + setProp(props, "aggregator_http_uri", connectionInfo.AggregatorHttpUri) case ServiceTypeClickhouse: - props["uris"] = connectionInfo.ClickHouseURIs + props["uris"] = connectionInfo.Clickhouse case ServiceTypeFlink: // TODO: Rename `host_ports` to `uris` in the next major version. - props["host_ports"] = connectionInfo.FlinkHostPorts + props["host_ports"] = connectionInfo.Flink default: // Doesn't have connection info return nil } - return d.Set(serviceType, []map[string]interface{}{props}) + return d.Set(serviceType, []map[string]any{props}) +} + +func setProp[T comparable](m map[string]any, k string, v *T) { + if v != nil { + m[k] = *v + } } // IsUnknownRole checks if the database returned an error because of an unknown role @@ -925,8 +926,8 @@ func DatasourceServiceRead(ctx context.Context, d *schema.ResourceData, m interf return diag.Errorf("error getting a list of services: %s", err) } - for _, service := range services { - if service.Name == serviceName { + for _, s := range services { + if s.Name == serviceName { return ResourceServiceRead(ctx, d, m) } } diff --git a/internal/sdkprovider/service/opensearch/opensearch.go b/internal/sdkprovider/service/opensearch/opensearch.go index d066efba1..6260fe301 100644 --- a/internal/sdkprovider/service/opensearch/opensearch.go +++ b/internal/sdkprovider/service/opensearch/opensearch.go @@ -41,6 +41,7 @@ func opensearchSchema() map[string]*schema.Schema { Computed: true, Sensitive: true, Description: "URI for Kibana dashboard frontend", + Deprecated: "This field was added by mistake and has never worked. It will be removed in future versions.", }, "username": { Type: schema.TypeString, diff --git a/internal/sdkprovider/service/pg/pg.go b/internal/sdkprovider/service/pg/pg.go index b59519b05..a0a144b40 100644 --- a/internal/sdkprovider/service/pg/pg.go +++ b/internal/sdkprovider/service/pg/pg.go @@ -51,6 +51,7 @@ func aivenPGSchema() map[string]*schema.Schema { Computed: true, Sensitive: true, Description: "PgBouncer connection details for [connection pooling](https://aiven.io/docs/products/postgresql/concepts/pg-connection-pooling).", + Deprecated: "This field was added by mistake and has never worked. It will be removed in future versions.", }, // TODO: Remove `host` in the next major version. "host": { diff --git a/internal/sdkprovider/service/thanos/thanos.go b/internal/sdkprovider/service/thanos/thanos.go index b33486591..8c20abb5c 100644 --- a/internal/sdkprovider/service/thanos/thanos.go +++ b/internal/sdkprovider/service/thanos/thanos.go @@ -58,6 +58,7 @@ func thanosSchema() map[string]*schema.Schema { Computed: true, Description: "Store URI.", Sensitive: true, + Deprecated: "This field was added by mistake and has never worked. It will be removed in future versions.", }, }, }, diff --git a/internal/sdkprovider/service/thanos/thanos_test.go b/internal/sdkprovider/service/thanos/thanos_test.go index 4ede18e54..0b4014787 100644 --- a/internal/sdkprovider/service/thanos/thanos_test.go +++ b/internal/sdkprovider/service/thanos/thanos_test.go @@ -324,10 +324,6 @@ func testAccCheckAivenServiceThanosAttributes(n string) resource.TestCheckFunc { return fmt.Errorf("expected to get correct receiver_remote_write_uri from Aiven") } - if a["thanos.0.store_uri"] == "" { - return fmt.Errorf("expected to get correct store_uri from Aiven") - } - return nil } }