diff --git a/go.mod b/go.mod index 216ba909d9..84a44ac9fd 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/zclconf/go-cty v1.14.1 go.mongodb.org/atlas v0.36.0 go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0 - go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0 + go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 go.mongodb.org/realm v0.1.0 golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 ) diff --git a/go.sum b/go.sum index 0c40f01eaf..0bbcb169fc 100644 --- a/go.sum +++ b/go.sum @@ -761,8 +761,8 @@ go.mongodb.org/atlas v0.36.0 h1:m05S3AO7zkl+bcG1qaNsEKBnAqnKx2FDwLooHpIG3j4= go.mongodb.org/atlas v0.36.0/go.mod h1:nfPldE9dSama6G2IbIzmEza02Ly7yFZjMMVscaM0uEc= go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0 h1:h1X2CGKyN1UFvNs69vp7xpufbbreq6p7bbrg5uJ1sxw= go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0/go.mod h1:4TAUPaWPFNSbi8c1hbQLr1wAdkmqi48O7zvyXjBM+a8= -go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0 h1:x6nnq2pUIP9mN4WLD4/EseBzV88OmSgexxYchPilgno= -go.mongodb.org/atlas-sdk/v20231115002 v20231115002.1.0/go.mod h1:el7cm23kEiiw72HAYimhNweKqp/ubHsNJk+Mk30yJhM= +go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0 h1:31Li8Xb1THAzYfAVDR9hhAn4z9IhmFs/+AbGqADsyt8= +go.mongodb.org/atlas-sdk/v20231115003 v20231115003.1.0/go.mod h1:tXE5JorXFSauhnw9Xu+/tNrRh90rTX8rYs9y0i2Jy+c= go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M= go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= diff --git a/internal/common/conversion/type_conversion.go b/internal/common/conversion/type_conversion.go index 539dbea6b5..cedd7a392d 100644 --- a/internal/common/conversion/type_conversion.go +++ b/internal/common/conversion/type_conversion.go @@ -56,3 +56,11 @@ func IsStringPresent(strPtr *string) bool { func MongoDBRegionToAWSRegion(region string) string { return strings.ReplaceAll(strings.ToLower(region), "_", "-") } + +// NonEmptyToPtr accepts an array or slice and returns a pointer to it, except if it's empty, in that case it returns nil. +func NonEmptyToPtr[T any](v []T) *[]T { + if len(v) == 0 { + return nil + } + return &v +} diff --git a/internal/common/conversion/type_conversion_test.go b/internal/common/conversion/type_conversion_test.go index cb0cfa0995..d5da040ede 100644 --- a/internal/common/conversion/type_conversion_test.go +++ b/internal/common/conversion/type_conversion_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/stretchr/testify/assert" ) func TestTimeToStringWithoutNanos(t *testing.T) { @@ -67,3 +68,25 @@ func TestMongoDBRegionToAWSRegion(t *testing.T) { } } } + +func TestNonEmptyToPtr(t *testing.T) { + var ( + nilSlice []string + emptyNonNilSlice = []string{} + ) + tests := []struct { + name string + expected *[]string + given []string + }{ + {"nil pointer", nil, nil}, + {"nil slice", nil, nilSlice}, + {"empty non-nil slice", nil, emptyNonNilSlice}, + {"slice with content", &[]string{"hello", "there"}, []string{"hello", "there"}}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.expected, conversion.NonEmptyToPtr(tc.given)) + }) + } +} diff --git a/internal/config/client.go b/internal/config/client.go index 7731f50cc2..040a3ad858 100644 --- a/internal/config/client.go +++ b/internal/config/client.go @@ -12,8 +12,8 @@ import ( "github.com/mongodb-forks/digest" "github.com/mongodb/terraform-provider-mongodbatlas/version" "github.com/spf13/cast" - oldAtlasSDK "go.mongodb.org/atlas-sdk/v20231001002/admin" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" matlasClient "go.mongodb.org/atlas/mongodbatlas" realmAuth "go.mongodb.org/realm/auth" "go.mongodb.org/realm/realm" @@ -29,10 +29,10 @@ var ( // MongoDBClient contains the mongodbatlas clients and configurations type MongoDBClient struct { - Atlas *matlasClient.Client - AtlasV2 *atlasSDK.APIClient - OldAtlasV2 *oldAtlasSDK.APIClient // Needed to avoid sudden breaking changes in federated_settings_identity_provider resource. Will be removed in terraform-provider-1.16.0 - Config *Config + Atlas *matlasClient.Client + AtlasV2 *admin.APIClient + Atlas20231001002 *admin20231001002.APIClient // Needed to avoid breaking changes in federated_settings_identity_provider and online_archive resources. + Config *Config } // Config contains the configurations needed to use SDKs @@ -89,30 +89,30 @@ func (c *Config) NewClient(ctx context.Context) (any, error) { if err != nil { return nil, err } - sdkOldV2Client, err := c.newOldSDKV2Client(client) + sdk20231001002Client, err := c.newSDK20231001002Client(client) if err != nil { return nil, err } clients := &MongoDBClient{ - Atlas: atlasClient, - AtlasV2: sdkV2Client, - OldAtlasV2: sdkOldV2Client, - Config: c, + Atlas: atlasClient, + AtlasV2: sdkV2Client, + Atlas20231001002: sdk20231001002Client, + Config: c, } return clients, nil } -func (c *Config) newSDKV2Client(client *http.Client) (*atlasSDK.APIClient, error) { - opts := []atlasSDK.ClientModifier{ - atlasSDK.UseHTTPClient(client), - atlasSDK.UseUserAgent(userAgent), - atlasSDK.UseBaseURL(c.BaseURL), - atlasSDK.UseDebug(false)} +func (c *Config) newSDKV2Client(client *http.Client) (*admin.APIClient, error) { + opts := []admin.ClientModifier{ + admin.UseHTTPClient(client), + admin.UseUserAgent(userAgent), + admin.UseBaseURL(c.BaseURL), + admin.UseDebug(false)} // Initialize the MongoDB Versioned Atlas Client. - sdkv2, err := atlasSDK.NewClient(opts...) + sdkv2, err := admin.NewClient(opts...) if err != nil { return nil, err } @@ -120,15 +120,15 @@ func (c *Config) newSDKV2Client(client *http.Client) (*atlasSDK.APIClient, error return sdkv2, nil } -func (c *Config) newOldSDKV2Client(client *http.Client) (*oldAtlasSDK.APIClient, error) { - opts := []oldAtlasSDK.ClientModifier{ - oldAtlasSDK.UseHTTPClient(client), - oldAtlasSDK.UseUserAgent(userAgent), - oldAtlasSDK.UseBaseURL(c.BaseURL), - oldAtlasSDK.UseDebug(false)} +func (c *Config) newSDK20231001002Client(client *http.Client) (*admin20231001002.APIClient, error) { + opts := []admin20231001002.ClientModifier{ + admin20231001002.UseHTTPClient(client), + admin20231001002.UseUserAgent(userAgent), + admin20231001002.UseBaseURL(c.BaseURL), + admin20231001002.UseDebug(false)} // Initialize the MongoDB Versioned Atlas Client. - sdkv2, err := oldAtlasSDK.NewClient(opts...) + sdkv2, err := admin20231001002.NewClient(opts...) if err != nil { return nil, err } diff --git a/internal/provider/provider_authentication_test.go b/internal/provider/provider_authentication_test.go index 3938db2b39..3935fecf0a 100644 --- a/internal/provider/provider_authentication_test.go +++ b/internal/provider/provider_authentication_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccSTSAssumeRole_basic(t *testing.T) { diff --git a/internal/service/alertconfiguration/data_source_alert_configuration.go b/internal/service/alertconfiguration/data_source_alert_configuration.go index 95956d2041..dafac342cc 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration.go @@ -14,7 +14,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/zclconf/go-cty/cty" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var _ datasource.DataSource = &alertConfigurationDS{} @@ -319,7 +319,7 @@ func outputAlertConfigurationResourceHcl(label string, alert *admin.GroupAlertsC resource.SetAttributeValue("enabled", cty.BoolVal(*alert.Enabled)) } - for _, matcher := range alert.Matchers { + for _, matcher := range alert.GetMatchers() { appendBlockWithCtyValues(resource, "matcher", []string{}, convertMatcherToCtyValues(matcher)) } @@ -331,8 +331,9 @@ func outputAlertConfigurationResourceHcl(label string, alert *admin.GroupAlertsC appendBlockWithCtyValues(resource, "threshold_config", []string{}, convertThresholdToCtyValues(alert.Threshold)) } - for i := 0; i < len(alert.Notifications); i++ { - appendBlockWithCtyValues(resource, "notification", []string{}, convertNotificationToCtyValues(&alert.Notifications[i])) + notifications := alert.GetNotifications() + for i := 0; i < len(notifications); i++ { + appendBlockWithCtyValues(resource, "notification", []string{}, convertNotificationToCtyValues(¬ifications[i])) } return string(f.Bytes()) @@ -438,16 +439,14 @@ func convertNotificationToCtyValues(notification *admin.AlertsNotificationRootFo values["sms_enabled"] = cty.BoolVal(*notification.SmsEnabled) } - if len(notification.Roles) > 0 { - roles := make([]cty.Value, 0) - - for _, r := range notification.Roles { + if roles := notification.GetRoles(); len(roles) > 0 { + roleList := make([]cty.Value, 0, len(roles)) + for _, r := range roles { if r != "" { - roles = append(roles, cty.StringVal(r)) + roleList = append(roleList, cty.StringVal(r)) } } - - values["roles"] = cty.TupleVal(roles) + values["roles"] = cty.TupleVal(roleList) } return values diff --git a/internal/service/alertconfiguration/data_source_alert_configuration_test.go b/internal/service/alertconfiguration/data_source_alert_configuration_test.go index 667554eebb..96b1f407b3 100644 --- a/internal/service/alertconfiguration/data_source_alert_configuration_test.go +++ b/internal/service/alertconfiguration/data_source_alert_configuration_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSAlertConfiguration_basic(t *testing.T) { diff --git a/internal/service/alertconfiguration/data_source_alert_configurations.go b/internal/service/alertconfiguration/data_source_alert_configurations.go index 1560be961c..46d7e2faa0 100644 --- a/internal/service/alertconfiguration/data_source_alert_configurations.go +++ b/internal/service/alertconfiguration/data_source_alert_configurations.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const alertConfigurationsDataSourceName = "alert_configurations" @@ -143,7 +143,7 @@ func (d *AlertConfigurationsDS) Read(ctx context.Context, req datasource.ReadReq alertConfigurationsConfig.ID = types.StringValue(conversion.EncodeStateID(map[string]string{ "project_id": projectID, })) - alertConfigurationsConfig.Results = NewTFAlertConfigurationDSModelList(alerts.Results, projectID, alertConfigurationsConfig.OutputType) + alertConfigurationsConfig.Results = NewTFAlertConfigurationDSModelList(alerts.GetResults(), projectID, alertConfigurationsConfig.OutputType) if *params.IncludeCount { alertConfigurationsConfig.TotalCount = types.Int64Value(int64(*alerts.TotalCount)) } diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index 1574c22983..01b3d7b04a 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewNotificationList(tfNotificationSlice []TfNotificationModel) ([]admin.AlertsNotificationRootForGroup, error) { @@ -43,7 +43,7 @@ func NewNotificationList(tfNotificationSlice []TfNotificationModel) ([]admin.Ale Username: n.Username.ValueStringPointer(), VictorOpsApiKey: n.VictorOpsAPIKey.ValueStringPointer(), VictorOpsRoutingKey: n.VictorOpsRoutingKey.ValueStringPointer(), - Roles: n.Roles, + Roles: conversion.NonEmptyToPtr(n.Roles), MicrosoftTeamsWebhookUrl: n.MicrosoftTeamsWebhookURL.ValueStringPointer(), WebhookSecret: n.WebhookSecret.ValueStringPointer(), WebhookUrl: n.WebhookURL.ValueStringPointer(), @@ -108,8 +108,8 @@ func NewTFAlertConfigurationModel(apiRespConfig *admin.GroupAlertsConfig, currSt Enabled: types.BoolPointerValue(apiRespConfig.Enabled), MetricThresholdConfig: NewTFMetricThresholdConfigModel(apiRespConfig.MetricThreshold, currState.MetricThresholdConfig), ThresholdConfig: NewTFThresholdConfigModel(apiRespConfig.Threshold, currState.ThresholdConfig), - Notification: NewTFNotificationModelList(apiRespConfig.Notifications, currState.Notification), - Matcher: NewTFMatcherModelList(apiRespConfig.Matchers, currState.Matcher), + Notification: NewTFNotificationModelList(apiRespConfig.GetNotifications(), currState.Notification), + Matcher: NewTFMatcherModelList(apiRespConfig.GetMatchers(), currState.Matcher), } } @@ -121,7 +121,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt value := n[i] notifications[i] = TfNotificationModel{ TeamName: conversion.StringPtrNullIfEmpty(value.TeamName), - Roles: value.Roles, + Roles: value.GetRoles(), ChannelName: conversion.StringPtrNullIfEmpty(value.ChannelName), DatadogRegion: conversion.StringPtrNullIfEmpty(value.DatadogRegion), DelayMin: types.Int64PointerValue(conversion.IntPtrToInt64Ptr(value.DelayMin)), @@ -145,7 +145,7 @@ func NewTFNotificationModelList(n []admin.AlertsNotificationRootForGroup, currSt currState := currStateNotifications[i] newState := TfNotificationModel{ TeamName: conversion.StringPtrNullIfEmpty(value.TeamName), - Roles: value.Roles, + Roles: value.GetRoles(), // sentive attributes do not use value returned from API APIToken: conversion.StringNullIfEmpty(currState.APIToken.ValueString()), DatadogAPIKey: conversion.StringNullIfEmpty(currState.DatadogAPIKey.ValueString()), @@ -303,8 +303,8 @@ func NewTfAlertConfigurationDSModel(apiRespConfig *admin.GroupAlertsConfig, proj Enabled: types.BoolPointerValue(apiRespConfig.Enabled), MetricThresholdConfig: NewTFMetricThresholdConfigModel(apiRespConfig.MetricThreshold, []TfMetricThresholdConfigModel{}), ThresholdConfig: NewTFThresholdConfigModel(apiRespConfig.Threshold, []TfThresholdConfigModel{}), - Notification: NewTFNotificationModelList(apiRespConfig.Notifications, []TfNotificationModel{}), - Matcher: NewTFMatcherModelList(apiRespConfig.Matchers, []TfMatcherModel{}), + Notification: NewTFNotificationModelList(apiRespConfig.GetNotifications(), []TfNotificationModel{}), + Matcher: NewTFMatcherModelList(apiRespConfig.GetMatchers(), []TfMatcherModel{}), } } diff --git a/internal/service/alertconfiguration/model_alert_configuration_test.go b/internal/service/alertconfiguration/model_alert_configuration_test.go index cc00599378..e8cd0ae4eb 100644 --- a/internal/service/alertconfiguration/model_alert_configuration_test.go +++ b/internal/service/alertconfiguration/model_alert_configuration_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -45,7 +45,7 @@ func TestNotificationSDKToTFModel(t *testing.T) { SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), ChannelName: admin.PtrString("#channel"), - Roles: roles, + Roles: conversion.NonEmptyToPtr(roles), ApiToken: admin.PtrString("newApiToken"), }, }, @@ -290,7 +290,7 @@ func TestNotificationTFModelToSDK(t *testing.T) { DelayMin: admin.PtrInt(delayMin), SmsEnabled: admin.PtrBool(disabled), EmailEnabled: admin.PtrBool(enabled), - Roles: roles, + Roles: conversion.NonEmptyToPtr(roles), }, }, }, diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index 14670d111b..fae08ed5ac 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -21,7 +21,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -380,7 +380,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe apiReq := &admin.GroupAlertsConfig{ EventTypeName: alertConfigPlan.EventType.ValueStringPointer(), Enabled: alertConfigPlan.Enabled.ValueBoolPointer(), - Matchers: NewMatcherList(alertConfigPlan.Matcher), + Matchers: conversion.NonEmptyToPtr(NewMatcherList(alertConfigPlan.Matcher)), MetricThreshold: NewMetricThreshold(alertConfigPlan.MetricThresholdConfig), Threshold: NewThreshold(alertConfigPlan.ThresholdConfig), } @@ -390,7 +390,7 @@ func (r *alertConfigurationRS) Create(ctx context.Context, req resource.CreateRe resp.Diagnostics.AddError(errorCreateAlertConf, err.Error()) return } - apiReq.Notifications = notifications + apiReq.Notifications = conversion.NonEmptyToPtr(notifications) apiResp, _, err := connV2.AlertConfigurationsApi.CreateAlertConfiguration(ctx, projectID, apiReq).Execute() if err != nil { @@ -482,7 +482,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe } if !reflect.DeepEqual(alertConfigPlan.Matcher, alertConfigState.Matcher) { - apiReq.Matchers = NewMatcherList(alertConfigPlan.Matcher) + apiReq.Matchers = conversion.NonEmptyToPtr(NewMatcherList(alertConfigPlan.Matcher)) } // Always refresh structure to handle service keys being obfuscated coming back from read API call @@ -491,7 +491,7 @@ func (r *alertConfigurationRS) Update(ctx context.Context, req resource.UpdateRe resp.Diagnostics.AddError(errorUpdateAlertConf, err.Error()) return } - apiReq.Notifications = notifications + apiReq.Notifications = conversion.NonEmptyToPtr(notifications) var updatedAlertConfigResp *admin.GroupAlertsConfig diff --git a/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go b/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go index eb74dfca5b..99a7c89c2d 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go +++ b/internal/service/alertconfiguration/resource_alert_configuration_migration_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" diff --git a/internal/service/alertconfiguration/resource_alert_configuration_test.go b/internal/service/alertconfiguration/resource_alert_configuration_test.go index bc0d1294b5..1d0d8c39f5 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration_test.go +++ b/internal/service/alertconfiguration/resource_alert_configuration_test.go @@ -14,7 +14,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigRSAlertConfiguration_basic(t *testing.T) { diff --git a/internal/service/atlasuser/data_source_atlas_user.go b/internal/service/atlasuser/data_source_atlas_user.go index 6246dba48c..8ac9db790f 100644 --- a/internal/service/atlasuser/data_source_atlas_user.go +++ b/internal/service/atlasuser/data_source_atlas_user.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -189,9 +189,9 @@ func newTFAtlasUserDSModel(user *admin.CloudAppUser) tfAtlasUserDSModel { LastAuth: types.StringPointerValue(conversion.TimePtrToStringPtr(user.LastAuth)), LastName: types.StringValue(user.LastName), MobileNumber: types.StringValue(user.MobileNumber), - TeamIDs: user.TeamIds, - Links: newTFLinksList(user.Links), - Roles: newTFRolesList(user.Roles), + TeamIDs: user.GetTeamIds(), + Links: newTFLinksList(user.GetLinks()), + Roles: newTFRolesList(user.GetRoles()), } } diff --git a/internal/service/atlasuser/data_source_atlas_user_test.go b/internal/service/atlasuser/data_source_atlas_user_test.go index 5a19a64a41..ad37cc608e 100644 --- a/internal/service/atlasuser/data_source_atlas_user_test.go +++ b/internal/service/atlasuser/data_source_atlas_user_test.go @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSAtlasUser_ByUserID(t *testing.T) { @@ -66,8 +66,8 @@ func dataSourceChecksForUser(dataSourceName, attrPrefix string, user *admin.Clou resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%smobile_number", attrPrefix), user.MobileNumber), resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%scountry", attrPrefix), user.Country), resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%screated_at", attrPrefix), *conversion.TimePtrToStringPtr(user.CreatedAt)), - resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%steam_ids.#", attrPrefix), fmt.Sprintf("%d", len(user.TeamIds))), - resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%slinks.#", attrPrefix), fmt.Sprintf("%d", len(user.Links))), + resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%steam_ids.#", attrPrefix), fmt.Sprintf("%d", len(*user.TeamIds))), + resource.TestCheckResourceAttr(dataSourceName, fmt.Sprintf("%slinks.#", attrPrefix), fmt.Sprintf("%d", len(*user.Links))), // for assertion of roles the values of `user.Roles` must not be used as it has the risk of flaky executions. CLOUDP-220377 resource.TestCheckResourceAttrWith(dataSourceName, fmt.Sprintf("%sroles.#", attrPrefix), acc.IntGreatThan(0)), resource.TestCheckResourceAttrSet(dataSourceName, fmt.Sprintf("%sroles.0.role_name", attrPrefix)), diff --git a/internal/service/atlasuser/data_source_atlas_users.go b/internal/service/atlasuser/data_source_atlas_users.go index 62dd95db88..0abd48d984 100644 --- a/internal/service/atlasuser/data_source_atlas_users.go +++ b/internal/service/atlasuser/data_source_atlas_users.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -191,7 +191,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "project", projectID, err.Error())) return } - users = apiResp.Results + users = apiResp.GetResults() totalCount = *apiResp.TotalCount case !atlasUsersConfig.TeamID.IsNull() && !atlasUsersConfig.OrgID.IsNull(): teamID := atlasUsersConfig.TeamID.ValueString() @@ -205,7 +205,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "team", teamID, err.Error())) return } - users = apiResp.Results + users = apiResp.GetResults() totalCount = *apiResp.TotalCount default: // only org_id is defined orgID := atlasUsersConfig.OrgID.ValueString() @@ -218,7 +218,7 @@ func (d *atlasUsersDS) Read(ctx context.Context, req datasource.ReadRequest, res resp.Diagnostics.AddError("error when getting users from Atlas", fmt.Sprintf(errorUsersRead, "org", orgID, err.Error())) return } - users = apiResp.Results + users = apiResp.GetResults() totalCount = *apiResp.TotalCount } diff --git a/internal/service/atlasuser/data_source_atlas_users_test.go b/internal/service/atlasuser/data_source_atlas_users_test.go index 0dd2b01dcb..dbd0aaf26a 100644 --- a/internal/service/atlasuser/data_source_atlas_users_test.go +++ b/internal/service/atlasuser/data_source_atlas_users_test.go @@ -13,7 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/atlasuser" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSAtlasUsers_ByOrgID(t *testing.T) { @@ -223,10 +223,10 @@ func dataSourceChecksForUsers(dataSourceName, orgID string, users *admin.Paginat resource.TestCheckResourceAttr(dataSourceName, "org_id", orgID), resource.TestCheckResourceAttr(dataSourceName, "total_count", fmt.Sprintf("%d", totalCountValue)), } - for i := range users.Results { - checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &users.Results[i])...) + results := users.GetResults() + for i := range results { + checks = append(checks, dataSourceChecksForUser(dataSourceName, fmt.Sprintf("results.%d.", i), &results[i])...) } - return checks } diff --git a/internal/service/databaseuser/data_source_database_user_test.go b/internal/service/databaseuser/data_source_database_user_test.go index 00191ab397..1374bb1532 100644 --- a/internal/service/databaseuser/data_source_database_user_test.go +++ b/internal/service/databaseuser/data_source_database_user_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigDSDatabaseUser_basic(t *testing.T) { diff --git a/internal/service/databaseuser/model_database_user.go b/internal/service/databaseuser/model_database_user.go index b32f8911a5..47cc14bb09 100644 --- a/internal/service/databaseuser/model_database_user.go +++ b/internal/service/databaseuser/model_database_user.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserModel) (*admin.CloudDatabaseUser, diag.Diagnostics) { @@ -40,24 +40,24 @@ func NewMongoDBDatabaseUser(ctx context.Context, dbUserModel *TfDatabaseUserMode OidcAuthType: dbUserModel.OIDCAuthType.ValueStringPointer(), LdapAuthType: dbUserModel.LDAPAuthType.ValueStringPointer(), DatabaseName: dbUserModel.AuthDatabaseName.ValueString(), - Roles: NewMongoDBAtlasRoles(rolesModel), - Labels: NewMongoDBAtlasLabels(labelsModel), - Scopes: NewMongoDBAtlasScopes(scopesModel), + Roles: conversion.NonEmptyToPtr(NewMongoDBAtlasRoles(rolesModel)), + Labels: conversion.NonEmptyToPtr(NewMongoDBAtlasLabels(labelsModel)), + Scopes: conversion.NonEmptyToPtr(NewMongoDBAtlasScopes(scopesModel)), }, nil } func NewTfDatabaseUserModel(ctx context.Context, model *TfDatabaseUserModel, dbUser *admin.CloudDatabaseUser) (*TfDatabaseUserModel, diag.Diagnostics) { - rolesSet, diagnostic := types.SetValueFrom(ctx, RoleObjectType, NewTFRolesModel(dbUser.Roles)) + rolesSet, diagnostic := types.SetValueFrom(ctx, RoleObjectType, NewTFRolesModel(dbUser.GetRoles())) if diagnostic.HasError() { return nil, diagnostic } - labelsSet, diagnostic := types.SetValueFrom(ctx, LabelObjectType, NewTFLabelsModel(dbUser.Labels)) + labelsSet, diagnostic := types.SetValueFrom(ctx, LabelObjectType, NewTFLabelsModel(dbUser.GetLabels())) if diagnostic.HasError() { return nil, diagnostic } - scopesSet, diagnostic := types.SetValueFrom(ctx, ScopeObjectType, NewTFScopesModel(dbUser.Scopes)) + scopesSet, diagnostic := types.SetValueFrom(ctx, ScopeObjectType, NewTFScopesModel(dbUser.GetScopes())) if diagnostic.HasError() { return nil, diagnostic } @@ -102,9 +102,9 @@ func NewTFDatabaseDSUserModel(ctx context.Context, dbUser *admin.CloudDatabaseUs OIDCAuthType: types.StringValue(dbUser.GetOidcAuthType()), LDAPAuthType: types.StringValue(dbUser.GetLdapAuthType()), AWSIAMType: types.StringValue(dbUser.GetAwsIAMType()), - Roles: NewTFRolesModel(dbUser.Roles), - Labels: NewTFLabelsModel(dbUser.Labels), - Scopes: NewTFScopesModel(dbUser.Scopes), + Roles: NewTFRolesModel(dbUser.GetRoles()), + Labels: NewTFLabelsModel(dbUser.GetLabels()), + Scopes: NewTFScopesModel(dbUser.GetScopes()), } return databaseUserModel, nil diff --git a/internal/service/databaseuser/model_database_user_test.go b/internal/service/databaseuser/model_database_user_test.go index 3a6fc2590f..ebae7a0f3f 100644 --- a/internal/service/databaseuser/model_database_user_test.go +++ b/internal/service/databaseuser/model_database_user_test.go @@ -9,7 +9,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( @@ -69,9 +69,9 @@ var ( OidcAuthType: &oidCAuthType, LdapAuthType: &ldapAuthType, AwsIAMType: &awsIAMType, - Roles: []admin.DatabaseUserRole{sdkRole}, - Labels: []admin.ComponentLabel{sdkLabel}, - Scopes: []admin.UserScope{sdkScope}, + Roles: &[]admin.DatabaseUserRole{sdkRole}, + Labels: &[]admin.ComponentLabel{sdkLabel}, + Scopes: &[]admin.UserScope{sdkScope}, } ) diff --git a/internal/service/databaseuser/resource_database_user_migration_test.go b/internal/service/databaseuser/resource_database_user_migration_test.go index e32ccb2e37..86e2bf597b 100644 --- a/internal/service/databaseuser/resource_database_user_migration_test.go +++ b/internal/service/databaseuser/resource_database_user_migration_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" diff --git a/internal/service/databaseuser/resource_database_user_test.go b/internal/service/databaseuser/resource_database_user_test.go index 2050cf539f..4b48a299d7 100644 --- a/internal/service/databaseuser/resource_database_user_test.go +++ b/internal/service/databaseuser/resource_database_user_test.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccConfigRSDatabaseUser_basic(t *testing.T) { diff --git a/internal/service/encryptionatrest/model_encryption_at_rest.go b/internal/service/encryptionatrest/model_encryption_at_rest.go index 484518b885..d222a9c8fc 100644 --- a/internal/service/encryptionatrest/model_encryption_at_rest.go +++ b/internal/service/encryptionatrest/model_encryption_at_rest.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewTfEncryptionAtRestRSModel(ctx context.Context, projectID string, encryptionResp *admin.EncryptionAtRest) *TfEncryptionAtRestRSModel { diff --git a/internal/service/encryptionatrest/model_encryption_at_rest_test.go b/internal/service/encryptionatrest/model_encryption_at_rest_test.go index 997c5bd763..0adc2616ca 100644 --- a/internal/service/encryptionatrest/model_encryption_at_rest_test.go +++ b/internal/service/encryptionatrest/model_encryption_at_rest_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/encryptionatrest" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( diff --git a/internal/service/encryptionatrest/resource_encryption_at_rest.go b/internal/service/encryptionatrest/resource_encryption_at_rest.go index 190d55d648..79da5c665f 100644 --- a/internal/service/encryptionatrest/resource_encryption_at_rest.go +++ b/internal/service/encryptionatrest/resource_encryption_at_rest.go @@ -24,7 +24,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go b/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go index 4c41b7319c..c8d191b54e 100644 --- a/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go +++ b/internal/service/encryptionatrest/resource_encryption_at_rest_migration_test.go @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccMigrationAdvRS_EncryptionAtRest_basicAWS(t *testing.T) { diff --git a/internal/service/encryptionatrest/resource_encryption_at_rest_test.go b/internal/service/encryptionatrest/resource_encryption_at_rest_test.go index b623d250e4..0e13849f96 100644 --- a/internal/service/encryptionatrest/resource_encryption_at_rest_test.go +++ b/internal/service/encryptionatrest/resource_encryption_at_rest_test.go @@ -20,7 +20,7 @@ import ( "github.com/mwielbut/pointy" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/encryptionatrest/service_encryption_at_rest.go b/internal/service/encryptionatrest/service_encryption_at_rest.go index 9528f0a0f9..d6334627a6 100644 --- a/internal/service/encryptionatrest/service_encryption_at_rest.go +++ b/internal/service/encryptionatrest/service_encryption_at_rest.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type EarService interface { diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go index 6aa8c171f2..630443434e 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance.go @@ -347,13 +347,13 @@ func dataSourceMongoDBAtlasFederatedDatabaseInstanceRead(ctx context.Context, d return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "data_process_region", name, err)) } - if storageDatabaseField := flattenDataFederationDatabase(dataFederationInstance.Storage.Databases); storageDatabaseField != nil { + if storageDatabaseField := flattenDataFederationDatabase(dataFederationInstance.Storage.GetDatabases()); storageDatabaseField != nil { if err := d.Set("storage_databases", storageDatabaseField); err != nil { return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_databases", name, err)) } } - if err := d.Set("storage_stores", flattenDataFederationStores(dataFederationInstance.Storage.Stores)); err != nil { + if err := d.Set("storage_stores", flattenDataFederationStores(dataFederationInstance.Storage.GetStores())); err != nil { return diag.FromErr(fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_stores", name, err)) } diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go index b50557501d..b0d76c8c11 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instance_test.go @@ -13,7 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccDataSourceFederatedDatabaseInstance_basic(t *testing.T) { diff --git a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go index 9cb193728f..00eddfa75f 100644 --- a/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go +++ b/internal/service/federateddatabaseinstance/data_source_federated_database_instances.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -146,8 +146,8 @@ func flattenFederatedDatabaseInstances(d *schema.ResourceData, projectID string, "hostnames": federatedDatabaseInstances[i].GetHostnames(), "cloud_provider_config": flattenCloudProviderConfig(d, federatedDatabaseInstances[i].CloudProviderConfig), "data_process_region": flattenDataProcessRegion(federatedDatabaseInstances[i].DataProcessRegion), - "storage_databases": flattenDataFederationDatabase(federatedDatabaseInstances[i].Storage.Databases), - "storage_stores": flattenDataFederationStores(federatedDatabaseInstances[i].Storage.Stores), + "storage_databases": flattenDataFederationDatabase(federatedDatabaseInstances[i].Storage.GetDatabases()), + "storage_stores": flattenDataFederationStores(federatedDatabaseInstances[i].Storage.GetStores()), } } } diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index e7053d9b26..1b26ea220d 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -7,7 +7,7 @@ import ( "net/http" "strings" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -496,7 +496,7 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex if storage, ok := dataFederationInstance.GetStorageOk(); ok { if databases, ok := storage.GetDatabasesOk(); ok { - if storageDatabaseField := flattenDataFederationDatabase(databases); storageDatabaseField != nil { + if storageDatabaseField := flattenDataFederationDatabase(*databases); storageDatabaseField != nil { if err := d.Set("storage_databases", storageDatabaseField); err != nil { return nil, fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_databases", name, err) } @@ -504,7 +504,7 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex } if stores, ok := storage.GetStoresOk(); ok { - if err := d.Set("storage_stores", flattenDataFederationStores(stores)); err != nil { + if err := d.Set("storage_stores", flattenDataFederationStores(*stores)); err != nil { return nil, fmt.Errorf(errorFederatedDatabaseInstanceSetting, "storage_stores", name, err) } } @@ -528,8 +528,8 @@ func resourceMongoDBAtlasFederatedDatabaseInstanceImportState(ctx context.Contex func newDataFederationStorage(d *schema.ResourceData) *admin.DataLakeStorage { return &admin.DataLakeStorage{ - Databases: newDataFederationDatabase(d), - Stores: newStores(d), + Databases: conversion.NonEmptyToPtr(newDataFederationDatabase(d)), + Stores: conversion.NonEmptyToPtr(newStores(d)), } } @@ -552,7 +552,7 @@ func newStores(d *schema.ResourceData) []admin.DataLakeStoreSettings { Prefix: conversion.StringPtr(storeFromConfMap["prefix"].(string)), Delimiter: conversion.StringPtr(storeFromConfMap["delimiter"].(string)), IncludeTags: conversion.Pointer(storeFromConfMap["include_tags"].(bool)), - AdditionalStorageClasses: newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any)), + AdditionalStorageClasses: conversion.NonEmptyToPtr(newAdditionalStorageClasses(storeFromConfMap["additional_storage_classes"].([]any))), ReadPreference: newReadPreference(storeFromConfMap), } } @@ -582,7 +582,7 @@ func newReadPreference(storeFromConfMap map[string]any) *admin.DataLakeAtlasStor return &admin.DataLakeAtlasStoreReadPreference{ Mode: conversion.StringPtr(readPreferenceFromConfMap["mode"].(string)), MaxStalenessSeconds: conversion.IntPtr(readPreferenceFromConfMap["max_staleness_seconds"].(int)), - TagSets: newTagSets(readPreferenceFromConfMap), + TagSets: conversion.NonEmptyToPtr(newTagSets(readPreferenceFromConfMap)), } } @@ -626,7 +626,7 @@ func newDataFederationDatabase(d *schema.ResourceData) []admin.DataLakeDatabaseI dbs[i] = admin.DataLakeDatabaseInstance{ Name: conversion.StringPtr(storageDBFromConfMap["name"].(string)), MaxWildcardCollections: conversion.IntPtr(storageDBFromConfMap["max_wildcard_collections"].(int)), - Collections: newDataFederationCollections(storageDBFromConfMap), + Collections: conversion.NonEmptyToPtr(newDataFederationCollections(storageDBFromConfMap)), } } @@ -643,7 +643,7 @@ func newDataFederationCollections(storageDBFromConfMap map[string]any) []admin.D for i, collectionFromConf := range collectionsFromConf { collections[i] = admin.DataLakeDatabaseCollection{ Name: conversion.StringPtr(collectionFromConf.(map[string]any)["name"].(string)), - DataSources: newDataFederationDataSource(collectionFromConf.(map[string]any)), + DataSources: conversion.NonEmptyToPtr(newDataFederationDataSource(collectionFromConf.(map[string]any))), } } @@ -670,7 +670,7 @@ func newDataFederationDataSource(collectionFromConf map[string]any) []admin.Data ProvenanceFieldName: conversion.StringPtr(dataSourceFromConfMap["provenance_field_name"].(string)), StoreName: conversion.StringPtr(dataSourceFromConfMap["store_name"].(string)), DatasetName: conversion.StringPtr(dataSourceFromConfMap["dataset_name"].(string)), - Urls: newUrls(dataSourceFromConfMap["urls"].([]any)), + Urls: conversion.NonEmptyToPtr(newUrls(dataSourceFromConfMap["urls"].([]any))), } } @@ -777,8 +777,8 @@ func flattenDataFederationDatabase(atlasDatabases []admin.DataLakeDatabaseInstan dbs[i] = map[string]any{ "name": atlasDatabase.GetName(), "max_wildcard_collections": atlasDatabase.GetMaxWildcardCollections(), - "collections": flattenDataFederationCollections(atlasDatabase.Collections), - "views": flattenDataFederationDatabaseViews(atlasDatabase.Views), + "collections": flattenDataFederationCollections(atlasDatabase.GetCollections()), + "views": flattenDataFederationDatabaseViews(atlasDatabase.GetViews()), } } @@ -805,7 +805,7 @@ func flattenDataFederationCollections(atlasCollections []admin.DataLakeDatabaseC for i, atlasCollection := range atlasCollections { colls[i] = map[string]any{ "name": atlasCollection.GetName(), - "data_sources": flattenDataFederationDataSources(atlasCollection.DataSources), + "data_sources": flattenDataFederationDataSources(atlasCollection.GetDataSources()), } } @@ -869,7 +869,7 @@ func newReadPreferenceField(atlasReadPreference *admin.DataLakeAtlasStoreReadPre { "mode": atlasReadPreference.GetMode(), "max_staleness_seconds": atlasReadPreference.GetMaxStalenessSeconds(), - "tag_sets": flattenReadPreferenceTagSets(atlasReadPreference.TagSets), + "tag_sets": flattenReadPreferenceTagSets(atlasReadPreference.GetTagSets()), }, } } diff --git a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go index 37b89142ed..4142a45091 100644 --- a/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/data_source_federated_settings_identity_provider.go @@ -7,12 +7,11 @@ import ( "sort" "strings" - oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" ) func DataSource() *schema.Resource { @@ -242,7 +241,7 @@ func dataSourceMongoDBAtlasFederatedSettingsIdentityProviderRead(ctx context.Con return diag.FromErr(fmt.Errorf("error setting `associated_domains` for federatedSettings IdentityProviders: %s", err)) } - if err := d.Set("associated_orgs", FlattenAssociatedOrgs(federatedSettingsIdentityProvider.AssociatedOrgs)); err != nil { + if err := d.Set("associated_orgs", FlattenAssociatedOrgs(federatedSettingsIdentityProvider.GetAssociatedOrgs())); err != nil { return diag.FromErr(fmt.Errorf("error setting `associated_orgs` for federatedSettings IdentityProviders: %s", err)) } @@ -292,8 +291,8 @@ func dataSourceMongoDBAtlasFederatedSettingsIdentityProviderRead(ctx context.Con } func oldSDKDSRead(ctx context.Context, federationSettingsID, idpID string, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - federatedSettingsIdentityProvider, _, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(ctx, federationSettingsID, idpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + federatedSettingsIdentityProvider, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(ctx, federationSettingsID, idpID).Execute() if err != nil { return diag.Errorf("error getting federatedSettings IdentityProviders assigned (%s): %s", federationSettingsID, err) } @@ -351,7 +350,7 @@ func oldSDKDSRead(ctx context.Context, federationSettingsID, idpID string, d *sc return nil } -func oldSDKFlattenAssociatedOrgs(associatedOrgs []oldAdmin.ConnectedOrgConfig) []map[string]any { +func oldSDKFlattenAssociatedOrgs(associatedOrgs []admin20231001002.ConnectedOrgConfig) []map[string]any { var associatedOrgsMap []map[string]any if len(associatedOrgs) == 0 { @@ -386,7 +385,7 @@ func oldSDKFlattenAssociatedOrgs(associatedOrgs []oldAdmin.ConnectedOrgConfig) [ return associatedOrgsMap } -func oldSDKFlattenFederatedUser(federatedUsers []oldAdmin.FederatedUser) []map[string]any { +func oldSDKFlattenFederatedUser(federatedUsers []admin20231001002.FederatedUser) []map[string]any { var userConflictsMap []map[string]any if len(federatedUsers) == 0 { @@ -407,7 +406,7 @@ func oldSDKFlattenFederatedUser(federatedUsers []oldAdmin.FederatedUser) []map[s return userConflictsMap } -type oldSDKAuthFederationoleMappingsByGroupName []oldAdmin.AuthFederationRoleMapping +type oldSDKAuthFederationoleMappingsByGroupName []admin20231001002.AuthFederationRoleMapping func (ra oldSDKAuthFederationoleMappingsByGroupName) Len() int { return len(ra) } func (ra oldSDKAuthFederationoleMappingsByGroupName) Swap(i, j int) { ra[i], ra[j] = ra[j], ra[i] } @@ -416,7 +415,7 @@ func (ra oldSDKAuthFederationoleMappingsByGroupName) Less(i, j int) bool { return ra[i].ExternalGroupName < ra[j].ExternalGroupName } -func oldSDKFlattenAuthFederationRoleMapping(roleMappings []oldAdmin.AuthFederationRoleMapping) []map[string]any { +func oldSDKFlattenAuthFederationRoleMapping(roleMappings []admin20231001002.AuthFederationRoleMapping) []map[string]any { sort.Sort(oldSDKAuthFederationoleMappingsByGroupName(roleMappings)) var roleMappingsMap []map[string]any @@ -436,7 +435,7 @@ func oldSDKFlattenAuthFederationRoleMapping(roleMappings []oldAdmin.AuthFederati return roleMappingsMap } -type mRoleAssignmentOldV2 []oldAdmin.RoleAssignment +type mRoleAssignmentOldV2 []admin20231001002.RoleAssignment func (ra mRoleAssignmentOldV2) Len() int { return len(ra) } func (ra mRoleAssignmentOldV2) Swap(i, j int) { ra[i], ra[j] = ra[j], ra[i] } @@ -456,7 +455,7 @@ func (ra mRoleAssignmentOldV2) Less(i, j int) bool { return *ra[i].Role < *ra[j].Role } -func oldSDKFlattenRoleAssignmentsV2(roleAssignments []oldAdmin.RoleAssignment) []map[string]any { +func oldSDKFlattenRoleAssignmentsV2(roleAssignments []admin20231001002.RoleAssignment) []map[string]any { sort.Sort(mRoleAssignmentOldV2(roleAssignments)) var roleAssignmentsMap []map[string]any @@ -476,7 +475,7 @@ func oldSDKFlattenRoleAssignmentsV2(roleAssignments []oldAdmin.RoleAssignment) [ return roleAssignmentsMap } -func oldSDKFlattenPemFileInfo(pemFileInfo oldAdmin.PemFileInfo) []map[string]any { +func oldSDKFlattenPemFileInfo(pemFileInfo admin20231001002.PemFileInfo) []map[string]any { var pemFileInfoMap []map[string]any if len(pemFileInfo.Certificates) > 0 { @@ -491,7 +490,7 @@ func oldSDKFlattenPemFileInfo(pemFileInfo oldAdmin.PemFileInfo) []map[string]any return pemFileInfoMap } -func oldSDKFlattenFederatedSettingsCertificates(certificates []oldAdmin.X509Certificate) []map[string]any { +func oldSDKFlattenFederatedSettingsCertificates(certificates []admin20231001002.X509Certificate) []map[string]any { var certificatesMap []map[string]any if len(certificates) > 0 { diff --git a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go index be0e892da8..782c9250bb 100644 --- a/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/model_federated_settings_identity_provider.go @@ -5,7 +5,7 @@ import ( "strings" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" matlas "go.mongodb.org/atlas/mongodbatlas" ) @@ -19,7 +19,7 @@ func FlattenFederatedSettingsIdentityProvider(federatedSettingsIdentityProvider federatedSettingsIdentityProviderMap[i] = map[string]any{ "acs_url": federatedSettingsIdentityProvider[i].AcsUrl, "associated_domains": federatedSettingsIdentityProvider[i].AssociatedDomains, - "associated_orgs": FlattenAssociatedOrgs(federatedSettingsIdentityProvider[i].AssociatedOrgs), + "associated_orgs": FlattenAssociatedOrgs(federatedSettingsIdentityProvider[i].GetAssociatedOrgs()), "audience_uri": federatedSettingsIdentityProvider[i].AudienceUri, "display_name": federatedSettingsIdentityProvider[i].DisplayName, "issuer_uri": federatedSettingsIdentityProvider[i].IssuerUri, @@ -53,7 +53,7 @@ func FlattenAssociatedOrgs(associatedOrgs []admin.ConnectedOrgConfig) []map[stri "identity_provider_id": associatedOrgs[i].IdentityProviderId, "org_id": associatedOrgs[i].OrgId, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].RoleMappings), + "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].GetRoleMappings()), "user_conflicts": nil, } } else { @@ -63,8 +63,8 @@ func FlattenAssociatedOrgs(associatedOrgs []admin.ConnectedOrgConfig) []map[stri "identity_provider_id": associatedOrgs[i].IdentityProviderId, "org_id": associatedOrgs[i].OrgId, "post_auth_role_grants": associatedOrgs[i].PostAuthRoleGrants, - "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].RoleMappings), - "user_conflicts": FlattenFederatedUser(associatedOrgs[i].UserConflicts), + "role_mappings": FlattenAuthFederationRoleMapping(associatedOrgs[i].GetRoleMappings()), + "user_conflicts": FlattenFederatedUser(associatedOrgs[i].GetUserConflicts()), } } } @@ -154,7 +154,7 @@ func FlattenAuthFederationRoleMapping(roleMappings []admin.AuthFederationRoleMap roleMappingsMap[i] = map[string]any{ "external_group_name": roleMappings[i].ExternalGroupName, "id": roleMappings[i].Id, - "role_assignments": FlattenRoleAssignmentsV2(roleMappings[i].RoleAssignments), + "role_assignments": FlattenRoleAssignmentsV2(roleMappings[i].GetRoleAssignments()), } } } @@ -165,11 +165,11 @@ func FlattenAuthFederationRoleMapping(roleMappings []admin.AuthFederationRoleMap func FlattenPemFileInfo(pemFileInfo admin.PemFileInfo) []map[string]any { var pemFileInfoMap []map[string]any - if len(pemFileInfo.Certificates) > 0 { + if certificates := pemFileInfo.GetCertificates(); len(certificates) > 0 { pemFileInfoMap = make([]map[string]any, 1) pemFileInfoMap[0] = map[string]any{ - "certificates": FlattenFederatedSettingsCertificates(pemFileInfo.Certificates), + "certificates": FlattenFederatedSettingsCertificates(certificates), "file_name": pemFileInfo.FileName, } } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index 15a2affd0b..f566e7db02 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -7,8 +7,8 @@ import ( "net/http" "regexp" - oldAdmin "go.mongodb.org/atlas-sdk/v20231001002/admin" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -154,8 +154,9 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderRead(ctx context.Conte } func oldSDKRead(federationSettingsID, oktaIdpID string, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - federatedSettingsIdentityProvider, resp, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + + federatedSettingsIdentityProvider, resp, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() if err != nil { // case 404 // deleted in the backend case @@ -237,7 +238,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderUpdate(ctx context.Con if d.HasChange("associated_domains") { associatedDomains := d.Get("associated_domains") - updateRequest.AssociatedDomains = cast.ToStringSlice(associatedDomains) + updateRequest.AssociatedDomains = conversion.NonEmptyToPtr(cast.ToStringSlice(associatedDomains)) } if d.HasChange("name") { @@ -281,9 +282,9 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderUpdate(ctx context.Con } func oldSDKUpdate(ctx context.Context, federationSettingsID, oktaIdpID string, d *schema.ResourceData, meta any) diag.Diagnostics { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - var updateRequest *oldAdmin.SamlIdentityProviderUpdate - _, _, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + var updateRequest *admin20231001002.SamlIdentityProviderUpdate + _, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), federationSettingsID, oktaIdpID).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error retreiving federation settings identity provider (%s): %s", federationSettingsID, err)) @@ -331,7 +332,7 @@ func oldSDKUpdate(ctx context.Context, federationSettingsID, oktaIdpID string, d updateRequest.PemFileInfo = nil - _, _, err = connOldV2.FederatedAuthenticationApi.UpdateIdentityProvider(ctx, federationSettingsID, oktaIdpID, updateRequest).Execute() + _, _, err = conn20231001002.FederatedAuthenticationApi.UpdateIdentityProvider(ctx, federationSettingsID, oktaIdpID, updateRequest).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error updating federation settings identity provider (%s): %s", federationSettingsID, err)) } @@ -345,7 +346,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderDelete(ctx context.Con } func resourceMongoDBAtlasFederatedSettingsIdentityProviderImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 federationSettingsID, oktaIdpID, err := splitFederatedSettingsIdentityProviderImportID(d.Id()) if err != nil { return nil, err @@ -356,7 +357,7 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderImportState(ctx contex return oldSDKImport(federationSettingsID, oktaIdpID, d, meta) } - federatedSettingsIdentityProvider, _, err := connV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() + federatedSettingsIdentityProvider, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() if err != nil { return nil, fmt.Errorf("couldn't import Organization config (%s) in Federation settings (%s), error: %s", *oktaIdpID, *federationSettingsID, err) } @@ -402,8 +403,8 @@ func resourceMongoDBAtlasFederatedSettingsIdentityProviderImportState(ctx contex } func oldSDKImport(federationSettingsID, oktaIdpID *string, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - connOldV2 := meta.(*config.MongoDBClient).OldAtlasV2 - federatedSettingsIdentityProvider, _, err := connOldV2.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + federatedSettingsIdentityProvider, _, err := conn20231001002.FederatedAuthenticationApi.GetIdentityProvider(context.Background(), *federationSettingsID, *oktaIdpID).Execute() if err != nil { return nil, fmt.Errorf("couldn't import Organization config (%s) in Federation settings (%s), error: %s", *oktaIdpID, *federationSettingsID, err) } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go index 9a57d35244..05195c3cbc 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider_test.go @@ -11,7 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccFedRSFederatedSettingsIdentityProvider_basic(t *testing.T) { diff --git a/internal/service/onlinearchive/data_source_online_archive.go b/internal/service/onlinearchive/data_source_online_archive.go index e7097eb365..1f074126f2 100644 --- a/internal/service/onlinearchive/data_source_online_archive.go +++ b/internal/service/onlinearchive/data_source_online_archive.go @@ -216,12 +216,12 @@ func schemaOnlineArchive() map[string]*schema.Schema { } func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) archiveID := d.Get("archive_id").(string) - archive, _, err := connV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() + archive, _, err := conn20231001002.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error reading Online Archive datasource with id %s: %s", archiveID, err.Error())) @@ -245,20 +245,21 @@ func dataSourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.Reso } func dataSourceMongoDBAtlasOnlineArchivesRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 + projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) - archives, _, err := connV2.OnlineArchiveApi.ListOnlineArchives(ctx, projectID, clusterName).Execute() + archives, _, err := conn20231001002.OnlineArchiveApi.ListOnlineArchives(ctx, projectID, clusterName).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error getting Online Archives list for project(%s) in cluster (%s): (%s)", projectID, clusterName, err.Error())) } - results := make([]map[string]any, 0, len(archives.Results)) - - for i := range archives.Results { - archiveData := fromOnlineArchiveToMap(&archives.Results[i]) + input := archives.Results + results := make([]map[string]any, 0, len(input)) + for i := range input { + archiveData := fromOnlineArchiveToMap(&input[i]) archiveData["project_id"] = projectID results = append(results, archiveData) } diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index 83b0582d3c..fc29255e45 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -16,7 +16,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mwielbut/pointy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin" ) const ( @@ -218,13 +218,12 @@ func getMongoDBAtlasOnlineArchiveSchema() map[string]*schema.Schema { } func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - // Get client connection - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 projectID := d.Get("project_id").(string) clusterName := d.Get("cluster_name").(string) inputRequest := mapToArchivePayload(d) - outputRequest, _, err := connV2.OnlineArchiveApi.CreateOnlineArchive(ctx, projectID, clusterName, &inputRequest).Execute() + outputRequest, _, err := conn20231001002.OnlineArchiveApi.CreateOnlineArchive(ctx, projectID, clusterName, &inputRequest).Execute() if err != nil { return diag.FromErr(fmt.Errorf(errorOnlineArchivesCreate, err)) @@ -242,7 +241,7 @@ func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.Reso stateConf := &retry.StateChangeConf{ Pending: []string{"PENDING", "ARCHIVING", "PAUSING", "PAUSED", "ORPHANED", "REPEATING"}, Target: []string{"IDLE", "ACTIVE"}, - Refresh: resourceOnlineRefreshFunc(ctx, projectID, clusterName, archiveID, connV2), + Refresh: resourceOnlineRefreshFunc(ctx, projectID, clusterName, archiveID, conn20231001002), Timeout: 3 * time.Hour, MinTimeout: 1 * time.Minute, Delay: 3 * time.Minute, @@ -258,7 +257,7 @@ func resourceMongoDBAtlasOnlineArchiveCreate(ctx context.Context, d *schema.Reso return resourceMongoDBAtlasOnlineArchiveRead(ctx, d, meta) } -func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, archiveID string, client *admin.APIClient) retry.StateRefreshFunc { +func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, archiveID string, client *admin20231001002.APIClient) retry.StateRefreshFunc { return func() (any, string, error) { c, resp, err := client.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() @@ -287,14 +286,14 @@ func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, arch } func resourceMongoDBAtlasOnlineArchiveRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 ids := conversion.DecodeStateID(d.Id()) archiveID := ids["archive_id"] projectID := ids["project_id"] clusterName := ids["cluster_name"] - onlineArchive, resp, err := connV2.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() + onlineArchive, resp, err := conn20231001002.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() if err != nil { if resp != nil && resp.StatusCode == http.StatusNotFound { d.SetId("") @@ -334,7 +333,7 @@ func resourceMongoDBAtlasOnlineArchiveDelete(ctx context.Context, d *schema.Reso } func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 parts := strings.Split(d.Id(), "-") var projectID, clusterName, archiveID string @@ -351,7 +350,7 @@ func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema projectID, clusterName, archiveID = parts[0], parts[1], parts[2] } - outOnlineArchive, _, err := connV2.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() + outOnlineArchive, _, err := conn20231001002.OnlineArchiveApi.GetOnlineArchive(ctx, projectID, archiveID, clusterName).Execute() if err != nil { return nil, fmt.Errorf("could not import Online Archive %s in project %s, error %s", archiveID, projectID, err.Error()) @@ -378,9 +377,9 @@ func resourceMongoDBAtlasOnlineArchiveImportState(ctx context.Context, d *schema return []*schema.ResourceData{d}, nil } -func mapToArchivePayload(d *schema.ResourceData) admin.BackupOnlineArchiveCreate { +func mapToArchivePayload(d *schema.ResourceData) admin20231001002.BackupOnlineArchiveCreate { // shared input - requestInput := admin.BackupOnlineArchiveCreate{ + requestInput := admin20231001002.BackupOnlineArchiveCreate{ DbName: d.Get("db_name").(string), CollName: d.Get("coll_name").(string), } @@ -397,17 +396,17 @@ func mapToArchivePayload(d *schema.ResourceData) admin.BackupOnlineArchiveCreate list := partitions.([]any) if len(list) > 0 { - partitionList := make([]admin.PartitionField, 0, len(list)) + partitionList := make([]admin20231001002.PartitionField, 0, len(list)) for _, partition := range list { item := partition.(map[string]any) - query := admin.PartitionField{ + query := admin20231001002.PartitionField{ FieldName: item["field_name"].(string), Order: item["order"].(int), } if dbType, ok := item["field_type"]; ok && dbType != nil { if dbType.(string) != "" { - query.FieldType = admin.PtrString(dbType.(string)) + query.FieldType = admin20231001002.PtrString(dbType.(string)) } } @@ -422,7 +421,7 @@ func mapToArchivePayload(d *schema.ResourceData) admin.BackupOnlineArchiveCreate } func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics { - connV2 := meta.(*config.MongoDBClient).AtlasV2 + conn20231001002 := meta.(*config.MongoDBClient).Atlas20231001002 ids := conversion.DecodeStateID(d.Id()) @@ -444,7 +443,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso return nil } - request := admin.BackupOnlineArchive{} + request := admin20231001002.BackupOnlineArchive{} // reading current value if pausedHasChange { @@ -460,7 +459,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso newExpirationRule := mapDataExpirationRule(d) if newExpirationRule == nil { // expiration rule has been removed from tf config, empty dataExpirationRule object needs to be sent in patch request - request.DataExpirationRule = &admin.DataExpirationRule{} + request.DataExpirationRule = &admin20231001002.DataExpirationRule{} } else { request.DataExpirationRule = newExpirationRule } @@ -469,7 +468,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso if dataProcessRegionHasChange { newDataProcessRegion := mapDataProcessRegion(d) if newDataProcessRegion == nil { - request.DataProcessRegion = &admin.DataProcessRegion{} + request.DataProcessRegion = &admin20231001002.DataProcessRegion{} } else { request.DataProcessRegion = newDataProcessRegion } @@ -480,10 +479,10 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso } if collType := d.Get("collection_type").(string); collectionTypeHasChange && collType != "" { - request.CollectionType = admin.PtrString(collType) + request.CollectionType = admin20231001002.PtrString(collType) } - _, _, err := connV2.OnlineArchiveApi.UpdateOnlineArchive(ctx, projectID, atlasID, clusterName, &request).Execute() + _, _, err := conn20231001002.OnlineArchiveApi.UpdateOnlineArchive(ctx, projectID, atlasID, clusterName, &request).Execute() if err != nil { return diag.FromErr(fmt.Errorf("error updating Mongo Online Archive id: %s %s", atlasID, err.Error())) @@ -492,7 +491,7 @@ func resourceMongoDBAtlasOnlineArchiveUpdate(ctx context.Context, d *schema.Reso return resourceMongoDBAtlasOnlineArchiveRead(ctx, d, meta) } -func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { +func fromOnlineArchiveToMap(in *admin20231001002.BackupOnlineArchive) map[string]any { // computed attribute schemaVals := map[string]any{ "cluster_name": in.ClusterName, @@ -568,13 +567,12 @@ func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { schemaVals["data_process_region"] = []any{dataProcessRegion} } - // partitions fields - if len(in.PartitionFields) == 0 { + partitionFields := in.PartitionFields + if len(partitionFields) == 0 { return schemaVals } - - partitionFieldsMap := make([]map[string]any, 0, len(in.PartitionFields)) - for _, field := range in.PartitionFields { + partitionFieldsMap := make([]map[string]any, 0, len(partitionFields)) + for _, field := range partitionFields { fieldMap := map[string]any{ "field_name": field.FieldName, "field_type": field.FieldType, @@ -588,10 +586,10 @@ func fromOnlineArchiveToMap(in *admin.BackupOnlineArchive) map[string]any { return schemaVals } -func mapDataExpirationRule(d *schema.ResourceData) *admin.DataExpirationRule { +func mapDataExpirationRule(d *schema.ResourceData) *admin20231001002.DataExpirationRule { if dataExpireRules, ok := d.GetOk("data_expiration_rule"); ok && len(dataExpireRules.([]any)) > 0 { dataExpireRule := dataExpireRules.([]any)[0].(map[string]any) - result := admin.DataExpirationRule{} + result := admin20231001002.DataExpirationRule{} if expireAfterDays, ok := dataExpireRule["expire_after_days"]; ok { result.ExpireAfterDays = pointy.Int(expireAfterDays.(int)) } @@ -600,10 +598,10 @@ func mapDataExpirationRule(d *schema.ResourceData) *admin.DataExpirationRule { return nil } -func mapDataProcessRegion(d *schema.ResourceData) *admin.DataProcessRegion { +func mapDataProcessRegion(d *schema.ResourceData) *admin20231001002.DataProcessRegion { if dataProcessRegions, ok := d.GetOk("data_process_region"); ok && len(dataProcessRegions.([]any)) > 0 { dataProcessRegion := dataProcessRegions.([]any)[0].(map[string]any) - result := admin.DataProcessRegion{} + result := admin20231001002.DataProcessRegion{} if cloudProvider, ok := dataProcessRegion["cloud_provider"]; ok { result.CloudProvider = pointy.String(cloudProvider.(string)) } @@ -615,31 +613,31 @@ func mapDataProcessRegion(d *schema.ResourceData) *admin.DataProcessRegion { return nil } -func mapCriteria(d *schema.ResourceData) admin.Criteria { +func mapCriteria(d *schema.ResourceData) admin20231001002.Criteria { criteriaList := d.Get("criteria").([]any) criteria := criteriaList[0].(map[string]any) - criteriaInput := admin.Criteria{ - Type: admin.PtrString(criteria["type"].(string)), + criteriaInput := admin20231001002.Criteria{ + Type: admin20231001002.PtrString(criteria["type"].(string)), } if criteriaInput.Type != nil && *criteriaInput.Type == "DATE" { if dateField := criteria["date_field"].(string); dateField != "" { - criteriaInput.DateField = admin.PtrString(dateField) + criteriaInput.DateField = admin20231001002.PtrString(dateField) } criteriaInput.ExpireAfterDays = pointy.Int(criteria["expire_after_days"].(int)) // optional if dformat, ok := criteria["date_format"]; ok && dformat.(string) != "" { - criteriaInput.DateFormat = admin.PtrString(dformat.(string)) + criteriaInput.DateFormat = admin20231001002.PtrString(dformat.(string)) } } if criteriaInput.Type != nil && *criteriaInput.Type == "CUSTOM" { if query := criteria["query"].(string); query != "" { - criteriaInput.Query = admin.PtrString(query) + criteriaInput.Query = admin20231001002.PtrString(query) } } @@ -647,11 +645,11 @@ func mapCriteria(d *schema.ResourceData) admin.Criteria { return criteriaInput } -func mapSchedule(d *schema.ResourceData) *admin.OnlineArchiveSchedule { +func mapSchedule(d *schema.ResourceData) *admin20231001002.OnlineArchiveSchedule { // scheduleInput := &matlas.OnlineArchiveSchedule{ // We have to provide schedule.type="DEFAULT" when the schedule block is not provided or removed - scheduleInput := &admin.OnlineArchiveSchedule{ + scheduleInput := &admin20231001002.OnlineArchiveSchedule{ Type: scheduleTypeDefault, } @@ -670,7 +668,7 @@ func mapSchedule(d *schema.ResourceData) *admin.OnlineArchiveSchedule { } scheduleTFConfig := scheduleTFConfigList[0].(map[string]any) - scheduleInput = &admin.OnlineArchiveSchedule{ + scheduleInput = &admin20231001002.OnlineArchiveSchedule{ Type: scheduleTFConfig["type"].(string), } diff --git a/internal/service/project/data_source_project.go b/internal/service/project/data_source_project.go index e27ce51fd7..b64436dd25 100644 --- a/internal/service/project/data_source_project.go +++ b/internal/service/project/data_source_project.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/datasource" diff --git a/internal/service/project/data_source_project_test.go b/internal/service/project/data_source_project_test.go index f3dc9fb73a..a51a1e4a6e 100644 --- a/internal/service/project/data_source_project_test.go +++ b/internal/service/project/data_source_project_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -27,11 +27,11 @@ func TestAccProjectDSProject_byID(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, )), @@ -59,12 +59,12 @@ func TestAccProjectDSProject_byName(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, )), @@ -92,12 +92,12 @@ func TestAccProjectDSProject_defaultFlags(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, )), diff --git a/internal/service/project/data_source_projects.go b/internal/service/project/data_source_projects.go index f3e060f9a8..0681bef193 100644 --- a/internal/service/project/data_source_projects.go +++ b/internal/service/project/data_source_projects.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const projectsDataSourceName = "projects" @@ -170,9 +170,10 @@ func (d *ProjectsDS) Read(ctx context.Context, req datasource.ReadRequest, resp } func populateProjectsDataSourceModel(ctx context.Context, connV2 *admin.APIClient, stateModel *tfProjectsDSModel, projectsRes *admin.PaginatedAtlasGroup) error { - results := make([]*TfProjectDSModel, 0, len(projectsRes.Results)) - for i := range projectsRes.Results { - project := projectsRes.Results[i] + input := projectsRes.GetResults() + results := make([]*TfProjectDSModel, 0, len(input)) + for i := range input { + project := input[i] atlasTeams, atlasLimits, atlasProjectSettings, err := GetProjectPropsFromAPI(ctx, ServiceFromClient(connV2), project.GetId()) if err == nil { // if the project is still valid, e.g. could have just been deleted projectModel := NewTFProjectDataSourceModel(ctx, &project, atlasTeams, atlasProjectSettings, atlasLimits) diff --git a/internal/service/project/data_source_projects_test.go b/internal/service/project/data_source_projects_test.go index ba9fdf4043..2bcc24eb27 100644 --- a/internal/service/project/data_source_projects_test.go +++ b/internal/service/project/data_source_projects_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -27,11 +27,11 @@ func TestAccProjectDSProjects_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, ), @@ -62,11 +62,11 @@ func TestAccProjectDSProjects_withPagination(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, 2, 5, diff --git a/internal/service/project/model_project.go b/internal/service/project/model_project.go index 5a58ea3763..f8e57e13ff 100644 --- a/internal/service/project/model_project.go +++ b/internal/service/project/model_project.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewTFProjectDataSourceModel(ctx context.Context, project *admin.Group, @@ -32,11 +32,10 @@ func NewTFTeamsDataSourceModel(ctx context.Context, atlasTeams *admin.PaginatedT if atlasTeams.GetTotalCount() == 0 { return nil } - teams := make([]*TfTeamDSModel, len(atlasTeams.Results)) - - for i, atlasTeam := range atlasTeams.Results { + results := atlasTeams.GetResults() + teams := make([]*TfTeamDSModel, len(results)) + for i, atlasTeam := range results { roleNames, _ := types.ListValueFrom(ctx, types.StringType, atlasTeam.RoleNames) - teams[i] = &TfTeamDSModel{ TeamID: types.StringValue(atlasTeam.GetTeamId()), RoleNames: roleNames, @@ -104,11 +103,10 @@ func newTFLimitsResourceModel(ctx context.Context, dataFederationLimits []admin. } func newTFTeamsResourceModel(ctx context.Context, atlasTeams *admin.PaginatedTeamRole) types.Set { - teams := make([]TfTeamModel, len(atlasTeams.Results)) - - for i, atlasTeam := range atlasTeams.Results { + results := atlasTeams.GetResults() + teams := make([]TfTeamModel, len(results)) + for i, atlasTeam := range results { roleNames, _ := types.SetValueFrom(ctx, types.StringType, atlasTeam.RoleNames) - teams[i] = TfTeamModel{ TeamID: types.StringValue(atlasTeam.GetTeamId()), RoleNames: roleNames, @@ -125,7 +123,7 @@ func NewTeamRoleList(ctx context.Context, teams []TfTeamModel) *[]admin.TeamRole for i, team := range teams { res[i] = admin.TeamRole{ TeamId: team.TeamID.ValueStringPointer(), - RoleNames: conversion.TypesSetToString(ctx, team.RoleNames), + RoleNames: conversion.NonEmptyToPtr(conversion.TypesSetToString(ctx, team.RoleNames)), } } return &res diff --git a/internal/service/project/model_project_test.go b/internal/service/project/model_project_test.go index 1bd655ee6e..d756ea00fe 100644 --- a/internal/service/project/model_project_test.go +++ b/internal/service/project/model_project_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/project" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -30,7 +30,7 @@ var ( teamRolesSDK = []admin.TeamRole{ { TeamId: conversion.StringPtr("teamId"), - RoleNames: roles, + RoleNames: conversion.NonEmptyToPtr(roles), }, } teamsDSTF = []*project.TfTeamDSModel{ @@ -88,7 +88,7 @@ func TestTeamsDataSourceSDKToTFModel(t *testing.T) { { name: "Complete TeamRole", paginatedTeamRole: &admin.PaginatedTeamRole{ - Results: teamRolesSDK, + Results: conversion.NonEmptyToPtr(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, expectedTFModel: teamsDSTF, @@ -141,7 +141,7 @@ func TestProjectDataSourceSDKToTFModel(t *testing.T) { name: "Project", project: &projectSDK, teams: &admin.PaginatedTeamRole{ - Results: teamRolesSDK, + Results: conversion.NonEmptyToPtr(teamRolesSDK), TotalCount: conversion.IntPtr(1), }, projectSettings: &projectSettingsSDK, diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 3c0bdad36a..584699ddd4 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -9,7 +9,7 @@ import ( "sort" "time" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" @@ -675,7 +675,7 @@ func UpdateProjectTeams(ctx context.Context, client GroupProjectService, project _, _, err := client.UpdateTeamRoles(ctx, projectID, teamID, &admin.TeamRole{ - RoleNames: conversion.TypesSetToString(ctx, team.RoleNames), + RoleNames: conversion.NonEmptyToPtr(conversion.TypesSetToString(ctx, team.RoleNames)), }, ) if err != nil { @@ -768,8 +768,9 @@ func ResourceProjectDependentsDeletingRefreshFunc(ctx context.Context, projectID return dependents, projectDependentsStateIdle, nil } - for i := range dependents.AdvancedClusters.Results { - if *dependents.AdvancedClusters.Results[i].StateName != projectDependentsStateDeleting { + results := dependents.AdvancedClusters.GetResults() + for i := range results { + if *results[i].StateName != projectDependentsStateDeleting { return dependents, projectDependentsStateIdle, nil } } diff --git a/internal/service/project/resource_project_migration_test.go b/internal/service/project/resource_project_migration_test.go index cea6a6961d..fddc639ed8 100644 --- a/internal/service/project/resource_project_migration_test.go +++ b/internal/service/project/resource_project_migration_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -68,11 +68,11 @@ func TestAccMigrationProjectRS_Teams(t *testing.T) { []*admin.TeamRole{ { TeamId: &teamsIds[0], - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: &teamsIds[1], - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }) ) diff --git a/internal/service/project/resource_project_test.go b/internal/service/project/resource_project_test.go index 85e3fa1f92..4864953d4d 100644 --- a/internal/service/project/resource_project_test.go +++ b/internal/service/project/resource_project_test.go @@ -18,7 +18,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mocksvc" "github.com/stretchr/testify/mock" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( @@ -433,7 +433,7 @@ func TestResourceProjectDependentsDeletingRefreshFunc(t *testing.T) { mockResponses: AdvancedClusterDescriptionResponse{ AdvancedClusterDescription: &admin.PaginatedAdvancedClusterDescription{ TotalCount: conversion.IntPtr(2), - Results: []admin.AdvancedClusterDescription{ + Results: &[]admin.AdvancedClusterDescription{ {StateName: conversion.StringPtr("IDLE")}, {StateName: conversion.StringPtr("DELETING")}, }, @@ -477,11 +477,11 @@ func TestAccProjectRSProject_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_ADMIN", "GROUP_OWNER"}, }, }, ), @@ -499,15 +499,15 @@ func TestAccProjectRSProject_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_OWNER"}, + RoleNames: &[]string{"GROUP_OWNER"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_DATA_ACCESS_READ_WRITE"}, + RoleNames: &[]string{"GROUP_DATA_ACCESS_READ_WRITE"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(2)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}, }, }, ), @@ -526,11 +526,11 @@ func TestAccProjectRSProject_basic(t *testing.T) { []*admin.TeamRole{ { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(0)), - RoleNames: []string{"GROUP_READ_ONLY", "GROUP_READ_ONLY"}, + RoleNames: &[]string{"GROUP_READ_ONLY", "GROUP_READ_ONLY"}, }, { TeamId: conversion.StringPtr(acc.GetProjectTeamsIdsWithPos(1)), - RoleNames: []string{"GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"}, + RoleNames: &[]string{"GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN"}, }, }, ), diff --git a/internal/service/project/service_project.go b/internal/service/project/service_project.go index 2384eac840..2feb333e55 100644 --- a/internal/service/project/service_project.go +++ b/internal/service/project/service_project.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type GroupProjectService interface { diff --git a/internal/service/projectapikey/resource_project_api_key.go b/internal/service/projectapikey/resource_project_api_key.go index 7f71cf17cb..d36fdcda76 100644 --- a/internal/service/projectapikey/resource_project_api_key.go +++ b/internal/service/projectapikey/resource_project_api_key.go @@ -12,7 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" matlas "go.mongodb.org/atlas/mongodbatlas" ) diff --git a/internal/service/projectipaccesslist/model_project_ip_access_list.go b/internal/service/projectipaccesslist/model_project_ip_access_list.go index 88611806c4..c3b00d4bc3 100644 --- a/internal/service/projectipaccesslist/model_project_ip_access_list.go +++ b/internal/service/projectipaccesslist/model_project_ip_access_list.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewMongoDBProjectIPAccessList(projectIPAccessListModel *TfProjectIPAccessListModel) *[]admin.NetworkPermissionEntry { diff --git a/internal/service/projectipaccesslist/model_project_ip_access_list_test.go b/internal/service/projectipaccesslist/model_project_ip_access_list_test.go index c6608bf394..1eca74d382 100644 --- a/internal/service/projectipaccesslist/model_project_ip_access_list_test.go +++ b/internal/service/projectipaccesslist/model_project_ip_access_list_test.go @@ -9,7 +9,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectipaccesslist" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( diff --git a/internal/service/projectipaccesslist/resource_project_ip_access_list.go b/internal/service/projectipaccesslist/resource_project_ip_access_list.go index c3395a05cf..3bb1f2b7fa 100644 --- a/internal/service/projectipaccesslist/resource_project_ip_access_list.go +++ b/internal/service/projectipaccesslist/resource_project_ip_access_list.go @@ -20,7 +20,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( diff --git a/internal/service/searchdeployment/model_search_deployment.go b/internal/service/searchdeployment/model_search_deployment.go index d8f77e3b2b..8d322ea977 100644 --- a/internal/service/searchdeployment/model_search_deployment.go +++ b/internal/service/searchdeployment/model_search_deployment.go @@ -6,7 +6,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchDeploymentRSModel) admin.ApiSearchDeploymentRequest { @@ -22,7 +23,7 @@ func NewSearchDeploymentReq(ctx context.Context, searchDeploymentPlan *TFSearchD } return admin.ApiSearchDeploymentRequest{ - Specs: resultSpecs, + Specs: conversion.NonEmptyToPtr(resultSpecs), } } @@ -38,7 +39,7 @@ func NewTFSearchDeployment(ctx context.Context, clusterName string, deployResp * result.Timeouts = *timeout } - specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(deployResp.Specs)) + specsList, diagnostics := types.ListValueFrom(ctx, SpecObjectType, newTFSpecsModel(deployResp.GetSpecs())) if diagnostics.HasError() { return nil, diagnostics } diff --git a/internal/service/searchdeployment/model_search_deployment_test.go b/internal/service/searchdeployment/model_search_deployment_test.go index 7fe31ba34c..626cf6bc8b 100644 --- a/internal/service/searchdeployment/model_search_deployment_test.go +++ b/internal/service/searchdeployment/model_search_deployment_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type sdkToTFModelTestCase struct { @@ -36,7 +36,7 @@ func TestSearchDeploymentSDKToTFModel(t *testing.T) { Id: admin.PtrString(dummyDeploymentID), GroupId: admin.PtrString(dummyProjectID), StateName: admin.PtrString(stateName), - Specs: []admin.ApiSearchDeploymentSpec{ + Specs: &[]admin.ApiSearchDeploymentSpec{ { InstanceSize: instanceSize, NodeCount: nodeCount, @@ -66,14 +66,12 @@ func TestSearchDeploymentSDKToTFModel(t *testing.T) { } } -type tfToSDKModelTestCase struct { - name string - tfModel *searchdeployment.TFSearchDeploymentRSModel - expectedSDKReq admin.ApiSearchDeploymentRequest -} - func TestSearchDeploymentTFModelToSDK(t *testing.T) { - testCases := []tfToSDKModelTestCase{ + testCases := []struct { + tfModel *searchdeployment.TFSearchDeploymentRSModel + expectedSDKReq admin.ApiSearchDeploymentRequest + name string + }{ { name: "Complete TF state", tfModel: &searchdeployment.TFSearchDeploymentRSModel{ @@ -84,7 +82,7 @@ func TestSearchDeploymentTFModelToSDK(t *testing.T) { Specs: tfSpecsList(t, instanceSize, nodeCount), }, expectedSDKReq: admin.ApiSearchDeploymentRequest{ - Specs: []admin.ApiSearchDeploymentSpec{ + Specs: &[]admin.ApiSearchDeploymentSpec{ { InstanceSize: instanceSize, NodeCount: nodeCount, diff --git a/internal/service/searchdeployment/service_search_deployment.go b/internal/service/searchdeployment/service_search_deployment.go index 4d90230b49..722d48a6bd 100644 --- a/internal/service/searchdeployment/service_search_deployment.go +++ b/internal/service/searchdeployment/service_search_deployment.go @@ -4,7 +4,7 @@ import ( "context" "net/http" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) type DeploymentService interface { diff --git a/internal/service/searchdeployment/state_transition_search_deployment.go b/internal/service/searchdeployment/state_transition_search_deployment.go index 64cf06a948..9ec570b2ea 100644 --- a/internal/service/searchdeployment/state_transition_search_deployment.go +++ b/internal/service/searchdeployment/state_transition_search_deployment.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const SearchDeploymentDoesNotExistsError = "ATLAS_FTS_DEPLOYMENT_DOES_NOT_EXIST" diff --git a/internal/service/searchdeployment/state_transition_search_deployment_test.go b/internal/service/searchdeployment/state_transition_search_deployment_test.go index 9541b046b6..d074002102 100644 --- a/internal/service/searchdeployment/state_transition_search_deployment_test.go +++ b/internal/service/searchdeployment/state_transition_search_deployment_test.go @@ -12,7 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/searchdeployment" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mocksvc" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var ( @@ -140,7 +140,7 @@ func responseWithState(state *string) *admin.ApiSearchDeploymentResponse { return &admin.ApiSearchDeploymentResponse{ GroupId: admin.PtrString(dummyProjectID), Id: admin.PtrString(dummyDeploymentID), - Specs: []admin.ApiSearchDeploymentSpec{ + Specs: &[]admin.ApiSearchDeploymentSpec{ { InstanceSize: instanceSize, NodeCount: nodeCount, diff --git a/internal/service/searchindex/data_source_search_index.go b/internal/service/searchindex/data_source_search_index.go index 4a2ce89959..f4738b1e92 100644 --- a/internal/service/searchindex/data_source_search_index.go +++ b/internal/service/searchindex/data_source_search_index.go @@ -128,8 +128,8 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err) } - if len(searchIndex.Analyzers) > 0 { - searchIndexMappingFields, err := marshalSearchIndex(searchIndex.Analyzers) + if analyzers := searchIndex.GetAnalyzers(); len(analyzers) > 0 { + searchIndexMappingFields, err := marshalSearchIndex(analyzers) if err != nil { return diag.FromErr(err) } @@ -155,7 +155,7 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour return diag.Errorf("error setting `searchAnalyzer` for search index (%s): %s", d.Id(), err) } - if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.Synonyms)); err != nil { + if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.GetSynonyms())); err != nil { return diag.Errorf("error setting `synonyms` for search index (%s): %s", d.Id(), err) } @@ -175,13 +175,13 @@ func dataSourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resour } } - if len(searchIndex.Fields) > 0 { - fields, err := marshalSearchIndex(searchIndex.Fields) + if fields := searchIndex.GetFields(); len(fields) > 0 { + fieldsMarshaled, err := marshalSearchIndex(fields) if err != nil { return diag.FromErr(err) } - if err := d.Set("fields", fields); err != nil { + if err := d.Set("fields", fieldsMarshaled); err != nil { return diag.Errorf("error setting `fields` for for search index (%s): %s", d.Id(), err) } } diff --git a/internal/service/searchindex/data_source_search_indexes.go b/internal/service/searchindex/data_source_search_indexes.go index eac7675ea0..fcac27216c 100644 --- a/internal/service/searchindex/data_source_search_indexes.go +++ b/internal/service/searchindex/data_source_search_indexes.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func PluralDataSource() *schema.Resource { @@ -111,7 +111,7 @@ func flattenSearchIndexes(searchIndexes []admin.ClusterSearchIndex, projectID, c "name": searchIndexes[i].Name, "search_analyzer": searchIndexes[i].SearchAnalyzer, "status": searchIndexes[i].Status, - "synonyms": flattenSearchIndexSynonyms(searchIndexes[i].Synonyms), + "synonyms": flattenSearchIndexSynonyms(searchIndexes[i].GetSynonyms()), "type": searchIndexes[i].Type, } @@ -127,20 +127,20 @@ func flattenSearchIndexes(searchIndexes []admin.ClusterSearchIndex, projectID, c } } - if len(searchIndexes[i].Analyzers) > 0 { - searchIndexAnalyzers, err := marshalSearchIndex(searchIndexes[i].Analyzers) + if analyzers := searchIndexes[i].GetAnalyzers(); len(analyzers) > 0 { + searchIndexAnalyzers, err := marshalSearchIndex(analyzers) if err != nil { return nil, err } searchIndexesMap[i]["analyzers"] = searchIndexAnalyzers } - if len(searchIndexes[i].Fields) > 0 { - fields, err := marshalSearchIndex(searchIndexes[i].Fields) + if fields := searchIndexes[i].GetFields(); len(fields) > 0 { + fieldsMarshaled, err := marshalSearchIndex(fields) if err != nil { return nil, err } - searchIndexesMap[i]["fields"] = fields + searchIndexesMap[i]["fields"] = fieldsMarshaled } } diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index 01f99662b3..347970c5d3 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -15,7 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -224,7 +224,7 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Analyzers = analyzers + searchIndex.Analyzers = conversion.NonEmptyToPtr(analyzers) } if d.HasChange("mappings_dynamic") { @@ -251,11 +251,11 @@ func resourceMongoDBAtlasSearchIndexUpdate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndex.Fields = fields + searchIndex.Fields = conversion.NonEmptyToPtr(fields) } if d.HasChange("synonyms") { - searchIndex.Synonyms = expandSearchIndexSynonyms(d) + searchIndex.Synonyms = conversion.NonEmptyToPtr(expandSearchIndexSynonyms(d)) } searchIndex.IndexID = conversion.StringPtr("") @@ -320,8 +320,8 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource return diag.Errorf("error setting `analyzer` for search index (%s): %s", d.Id(), err) } - if len(searchIndex.Analyzers) > 0 { - searchIndexMappingFields, err := marshalSearchIndex(searchIndex.Analyzers) + if analyzers := searchIndex.GetAnalyzers(); len(analyzers) > 0 { + searchIndexMappingFields, err := marshalSearchIndex(analyzers) if err != nil { return diag.FromErr(err) } @@ -347,7 +347,7 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource return diag.Errorf("error setting `searchAnalyzer` for search index (%s): %s", d.Id(), err) } - if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.Synonyms)); err != nil { + if err := d.Set("synonyms", flattenSearchIndexSynonyms(searchIndex.GetSynonyms())); err != nil { return diag.Errorf("error setting `synonyms` for search index (%s): %s", d.Id(), err) } @@ -368,8 +368,8 @@ func resourceMongoDBAtlasSearchIndexRead(ctx context.Context, d *schema.Resource } } - if len(searchIndex.Fields) > 0 { - fields, err := marshalSearchIndex(searchIndex.Fields) + if fields := searchIndex.GetFields(); len(fields) > 0 { + fields, err := marshalSearchIndex(fields) if err != nil { return diag.FromErr(err) } @@ -413,7 +413,7 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour Name: d.Get("name").(string), SearchAnalyzer: conversion.StringPtr(d.Get("search_analyzer").(string)), Status: conversion.StringPtr(d.Get("status").(string)), - Synonyms: expandSearchIndexSynonyms(d), + Synonyms: conversion.NonEmptyToPtr(expandSearchIndexSynonyms(d)), } if indexType == vectorSearch { @@ -421,13 +421,13 @@ func resourceMongoDBAtlasSearchIndexCreate(ctx context.Context, d *schema.Resour if err != nil { return err } - searchIndexRequest.Fields = fields + searchIndexRequest.Fields = conversion.NonEmptyToPtr(fields) } else { analyzers, err := unmarshalSearchIndexAnalyzersFields(d.Get("analyzers").(string)) if err != nil { return err } - searchIndexRequest.Analyzers = analyzers + searchIndexRequest.Analyzers = conversion.NonEmptyToPtr(analyzers) mappingsFields, err := unmarshalSearchIndexMappingFields(d.Get("mappings_fields").(string)) if err != nil { return err diff --git a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go index 98cd0ad90c..6fac777bb2 100644 --- a/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go +++ b/internal/service/sharedtier/data_source_cloud_shared_tier_restore_jobs.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -97,7 +97,7 @@ func dataSourceMongoDBAtlasCloudSharedTierRestoreJobRead(ctx context.Context, d return diag.FromErr(fmt.Errorf("error getting shared tier restore jobs for cluster '%s': %w", clusterName, err)) } - if err := d.Set("results", flattenShardTierRestoreJobs(jobs.Results)); err != nil { + if err := d.Set("results", flattenShardTierRestoreJobs(jobs.GetResults())); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %w", err)) } @@ -109,7 +109,7 @@ func dataSourceMongoDBAtlasCloudSharedTierRestoreJobRead(ctx context.Context, d return nil } -func flattenShardTierRestoreJobs(sharedTierJobs []atlasSDK.TenantRestore) []map[string]any { +func flattenShardTierRestoreJobs(sharedTierJobs []admin.TenantRestore) []map[string]any { if len(sharedTierJobs) == 0 { return nil } diff --git a/internal/service/sharedtier/data_source_shared_tier_snapshots.go b/internal/service/sharedtier/data_source_shared_tier_snapshots.go index 5375e41f4b..59b69208d6 100644 --- a/internal/service/sharedtier/data_source_shared_tier_snapshots.go +++ b/internal/service/sharedtier/data_source_shared_tier_snapshots.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - atlasSDK "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -80,7 +80,7 @@ func dataSourceMongoDBAtlasSharedTierSnapshotsRead(ctx context.Context, d *schem return diag.FromErr(fmt.Errorf("error getting shard-tier snapshots for cluster '%s': %w", clusterName, err)) } - if err := d.Set("results", flattenSharedTierSnapshots(snapshots.Results)); err != nil { + if err := d.Set("results", flattenSharedTierSnapshots(snapshots.GetResults())); err != nil { return diag.FromErr(fmt.Errorf("error setting `results`: %w", err)) } @@ -92,7 +92,7 @@ func dataSourceMongoDBAtlasSharedTierSnapshotsRead(ctx context.Context, d *schem return nil } -func flattenSharedTierSnapshots(sharedTierSnapshots []atlasSDK.BackupTenantSnapshot) []map[string]any { +func flattenSharedTierSnapshots(sharedTierSnapshots []admin.BackupTenantSnapshot) []map[string]any { if len(sharedTierSnapshots) == 0 { return nil } diff --git a/internal/service/streamconnection/data_source_stream_connections.go b/internal/service/streamconnection/data_source_stream_connections.go index 5eae9bb5a6..66bda56caa 100644 --- a/internal/service/streamconnection/data_source_stream_connections.go +++ b/internal/service/streamconnection/data_source_stream_connections.go @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var _ datasource.DataSource = &streamConnectionsDS{} diff --git a/internal/service/streamconnection/data_source_stream_connections_test.go b/internal/service/streamconnection/data_source_stream_connections_test.go index c4fdd57af6..25569960b3 100644 --- a/internal/service/streamconnection/data_source_stream_connections_test.go +++ b/internal/service/streamconnection/data_source_stream_connections_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccStreamDSStreamConnections_basic(t *testing.T) { diff --git a/internal/service/streamconnection/model_stream_connection.go b/internal/service/streamconnection/model_stream_connection.go index ce7c9d5255..9ac2b2a06c 100644 --- a/internal/service/streamconnection/model_stream_connection.go +++ b/internal/service/streamconnection/model_stream_connection.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewStreamConnectionReq(ctx context.Context, plan *TFStreamConnectionModel) (*admin.StreamsConnection, diag.Diagnostics) { @@ -122,11 +122,12 @@ func newTFConnectionAuthenticationModel(ctx context.Context, currAuthConfig *typ func NewTFStreamConnections(ctx context.Context, streamConnectionsConfig *TFStreamConnectionsDSModel, paginatedResult *admin.PaginatedApiStreamsConnection) (*TFStreamConnectionsDSModel, diag.Diagnostics) { - results := make([]TFStreamConnectionModel, len(paginatedResult.Results)) - for i := range paginatedResult.Results { + input := paginatedResult.GetResults() + results := make([]TFStreamConnectionModel, len(input)) + for i := range input { projectID := streamConnectionsConfig.ProjectID.ValueString() instanceName := streamConnectionsConfig.InstanceName.ValueString() - connectionModel, diags := NewTFStreamConnection(ctx, projectID, instanceName, nil, &paginatedResult.Results[i]) + connectionModel, diags := NewTFStreamConnection(ctx, projectID, instanceName, nil, &input[i]) if diags.HasError() { return nil, diags } diff --git a/internal/service/streamconnection/model_stream_connection_test.go b/internal/service/streamconnection/model_stream_connection_test.go index 838dd62b68..bc727ce58e 100644 --- a/internal/service/streamconnection/model_stream_connection_test.go +++ b/internal/service/streamconnection/model_stream_connection_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streamconnection" "github.com/stretchr/testify/assert" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -168,7 +168,7 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) { { name: "Complete SDK response with configured page options", SDKResp: &admin.PaginatedApiStreamsConnection{ - Results: []admin.StreamsConnection{ + Results: &[]admin.StreamsConnection{ { Name: admin.PtrString(connectionName), Type: admin.PtrString("Kafka"), @@ -232,7 +232,7 @@ func TestStreamConnectionsSDKToTFModel(t *testing.T) { { name: "Without defining page options", SDKResp: &admin.PaginatedApiStreamsConnection{ - Results: []admin.StreamsConnection{}, + Results: &[]admin.StreamsConnection{}, TotalCount: admin.PtrInt(0), }, providedConfig: &streamconnection.TFStreamConnectionsDSModel{ diff --git a/internal/service/streaminstance/data_source_stream_instances.go b/internal/service/streaminstance/data_source_stream_instances.go index 1ca3cfb1a7..3a0b32ff15 100644 --- a/internal/service/streaminstance/data_source_stream_instances.go +++ b/internal/service/streaminstance/data_source_stream_instances.go @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) var _ datasource.DataSource = &streamInstancesDS{} diff --git a/internal/service/streaminstance/data_source_stream_instances_test.go b/internal/service/streaminstance/data_source_stream_instances_test.go index 3b5cb5a645..f2ba3848f8 100644 --- a/internal/service/streaminstance/data_source_stream_instances_test.go +++ b/internal/service/streaminstance/data_source_stream_instances_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func TestAccStreamDSStreamInstances_basic(t *testing.T) { diff --git a/internal/service/streaminstance/model_stream_instance.go b/internal/service/streaminstance/model_stream_instance.go index 4871b93a37..c3c7334d52 100644 --- a/internal/service/streaminstance/model_stream_instance.go +++ b/internal/service/streaminstance/model_stream_instance.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func NewStreamInstanceCreateReq(ctx context.Context, plan *TFStreamInstanceModel) (*admin.StreamsTenant, diag.Diagnostics) { @@ -63,9 +63,10 @@ func NewTFStreamInstance(ctx context.Context, apiResp *admin.StreamsTenant) (*TF } func NewTFStreamInstances(ctx context.Context, streamInstancesConfig *TFStreamInstancesModel, paginatedResult *admin.PaginatedApiStreamsTenant) (*TFStreamInstancesModel, diag.Diagnostics) { - results := make([]TFStreamInstanceModel, len(paginatedResult.Results)) - for i := range paginatedResult.Results { - instance, diags := NewTFStreamInstance(ctx, &paginatedResult.Results[i]) + input := paginatedResult.GetResults() + results := make([]TFStreamInstanceModel, len(input)) + for i := range input { + instance, diags := NewTFStreamInstance(ctx, &input[i]) if diags.HasError() { return nil, diags } diff --git a/internal/service/streaminstance/model_stream_instance_test.go b/internal/service/streaminstance/model_stream_instance_test.go index c5e1e4408a..92532c38a2 100644 --- a/internal/service/streaminstance/model_stream_instance_test.go +++ b/internal/service/streaminstance/model_stream_instance_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/streaminstance" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) const ( @@ -18,7 +18,7 @@ const ( instanceName = "InstanceName" ) -var hostnames = []string{"atlas-stream.virginia-usa.a.query.mongodb-dev.net"} +var hostnames = &[]string{"atlas-stream.virginia-usa.a.query.mongodb-dev.net"} type sdkToTFModelTestCase struct { SDKResp *admin.StreamsTenant @@ -90,7 +90,7 @@ func TestStreamInstancesSDKToTFModel(t *testing.T) { { name: "Complete SDK response with configured page options", SDKResp: &admin.PaginatedApiStreamsTenant{ - Results: []admin.StreamsTenant{ + Results: &[]admin.StreamsTenant{ { Id: admin.PtrString(dummyStreamInstanceID), DataProcessRegion: &admin.StreamsDataProcessRegion{ @@ -128,7 +128,7 @@ func TestStreamInstancesSDKToTFModel(t *testing.T) { { name: "Without defining page options", SDKResp: &admin.PaginatedApiStreamsTenant{ - Results: []admin.StreamsTenant{}, + Results: &[]admin.StreamsTenant{}, TotalCount: admin.PtrInt(0), }, providedConfig: &streaminstance.TFStreamInstancesModel{ @@ -246,7 +246,7 @@ func tfRegionObject(t *testing.T, cloudProvider, region string) types.Object { return dataProcessRegion } -func tfHostnamesList(t *testing.T, hostnames []string) types.List { +func tfHostnamesList(t *testing.T, hostnames *[]string) types.List { t.Helper() resultList, diags := types.ListValueFrom(context.Background(), types.StringType, hostnames) if diags.HasError() { diff --git a/internal/testutil/acc/database_user.go b/internal/testutil/acc/database_user.go index d1ec9e0611..3b92867f2d 100644 --- a/internal/testutil/acc/database_user.go +++ b/internal/testutil/acc/database_user.go @@ -10,7 +10,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/databaseuser" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func CheckDatabaseUserExists(resourceName string, dbUser *admin.CloudDatabaseUser) resource.TestCheckFunc { diff --git a/internal/testutil/acc/project.go b/internal/testutil/acc/project.go index 9c84d71bf3..55b539d0e0 100644 --- a/internal/testutil/acc/project.go +++ b/internal/testutil/acc/project.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20231115003/admin" ) func CheckProjectExists(resourceName string, project *admin.Group) resource.TestCheckFunc { @@ -72,7 +72,7 @@ func ConfigProject(projectName, orgID string, teams []*admin.TeamRole) string { team_id = "%s" role_names = %s } - `, t.GetTeamId(), strings.ReplaceAll(fmt.Sprintf("%+q", t.RoleNames), " ", ",")) + `, t.GetTeamId(), strings.ReplaceAll(fmt.Sprintf("%+q", *t.RoleNames), " ", ",")) } return fmt.Sprintf(` diff --git a/internal/testutil/mocksvc/deployment_service.go b/internal/testutil/mocksvc/deployment_service.go index 62c96ad9bd..4465516fbf 100644 --- a/internal/testutil/mocksvc/deployment_service.go +++ b/internal/testutil/mocksvc/deployment_service.go @@ -5,7 +5,7 @@ package mocksvc import ( context "context" - admin "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin "go.mongodb.org/atlas-sdk/v20231115003/admin" http "net/http" diff --git a/internal/testutil/mocksvc/ear_service.go b/internal/testutil/mocksvc/ear_service.go index ea9825f425..08b32f1c7e 100644 --- a/internal/testutil/mocksvc/ear_service.go +++ b/internal/testutil/mocksvc/ear_service.go @@ -5,7 +5,7 @@ package mocksvc import ( context "context" - admin "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin "go.mongodb.org/atlas-sdk/v20231115003/admin" http "net/http" diff --git a/internal/testutil/mocksvc/group_project_service.go b/internal/testutil/mocksvc/group_project_service.go index 3b7a4b31d8..e9adc3f78d 100644 --- a/internal/testutil/mocksvc/group_project_service.go +++ b/internal/testutil/mocksvc/group_project_service.go @@ -5,7 +5,7 @@ package mocksvc import ( context "context" - admin "go.mongodb.org/atlas-sdk/v20231115002/admin" + admin "go.mongodb.org/atlas-sdk/v20231115003/admin" http "net/http" diff --git a/tools/scaffold/template/model.tmpl b/tools/scaffold/template/model.tmpl index e3b6d2aa12..067365ef41 100644 --- a/tools/scaffold/template/model.tmpl +++ b/tools/scaffold/template/model.tmpl @@ -4,7 +4,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/diag" - // "go.mongodb.org/atlas-sdk/v20231115002/admin" use latest version + // "go.mongodb.org/atlas-sdk/v20231115003/admin" use latest version ) // TODO: `ctx` parameter and `diags` return value can be removed if tf schema has no complex data types (e.g., schema.ListAttribute, schema.SetAttribute) diff --git a/tools/scaffold/template/model_test.tmpl b/tools/scaffold/template/model_test.tmpl index e7ad41f3df..cc359058f7 100644 --- a/tools/scaffold/template/model_test.tmpl +++ b/tools/scaffold/template/model_test.tmpl @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/{{.NameLowerNoSpaces}}" - // "go.mongodb.org/atlas-sdk/v20231115002/admin" use latest version + // "go.mongodb.org/atlas-sdk/v20231115003/admin" use latest version ) type sdkToTFModelTestCase struct {