Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds atlas Organization New Parameters Support #1835

Merged
merged 53 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
27df3ca
apply update-atlas-sdk
lantoli Jan 12, 2024
c2e5a40
revert changes to oldAdmin
lantoli Jan 12, 2024
258cff2
remove atlasSDK alias
lantoli Jan 12, 2024
25ea035
use SlicePtrToSlice and NonEmptySliceToPtrSlice
lantoli Jan 12, 2024
b3e01d9
TEMPORARY - remove DataProcessRegion to make it compile and run tests
lantoli Jan 12, 2024
8c48565
fix linter: fieldalignment: struct with 32 pointer bytes could be 24 …
lantoli Jan 12, 2024
23793e5
fix project tests
lantoli Jan 12, 2024
c28ae5e
apply update-atlas-sdk
lantoli Jan 12, 2024
32d630a
revert changes to oldAdmin
lantoli Jan 12, 2024
2527ba6
remove atlasSDK alias
lantoli Jan 12, 2024
2587fb3
use SlicePtrToSlice and NonEmptySliceToPtrSlice
lantoli Jan 12, 2024
404512e
TEMPORARY - remove DataProcessRegion to make it compile and run tests
lantoli Jan 12, 2024
f93464f
fix linter: fieldalignment: struct with 32 pointer bytes could be 24 …
lantoli Jan 12, 2024
5651c2b
fix project tests
lantoli Jan 12, 2024
d0d2d67
Revert "TEMPORARY - remove DataProcessRegion to make it compile and r…
lantoli Jan 12, 2024
37c0ace
upgrade to atlas sdk
maastha Jan 12, 2024
d9ca6cc
upgrade plural DS to atlas sdk
maastha Jan 12, 2024
db96b10
migrate plural DS to new atlas SDK
maastha Jan 12, 2024
479afb8
migrate plural DS to new atlas SDK
maastha Jan 12, 2024
c98bab9
migrate plural DS to new atlas SDK
maastha Jan 12, 2024
f914609
update sdk to latest
maastha Jan 12, 2024
0859331
update sdk to latest
maastha Jan 12, 2024
7a1caae
update sdk to latest
maastha Jan 12, 2024
58abc5f
user old SDK for online archive as DataProcessRegion was removed
lantoli Jan 12, 2024
0ab62a3
fix merge
maastha Jan 12, 2024
9ca501b
Merge branch 'CLOUDP-222424_sdk_update_pointers' of github.com:mongod…
maastha Jan 12, 2024
1d8dec4
fix merge
maastha Jan 12, 2024
b7818a9
add new API support
maastha Jan 10, 2024
5dd60df
add new APIs and params
maastha Jan 12, 2024
a64c3c2
add new APIs and params
maastha Jan 12, 2024
06cc66e
update templates
lantoli Jan 15, 2024
1d0f3fa
rename to NonEmptySliceToSlicePtr
lantoli Jan 15, 2024
879a09b
tests for slice functions
lantoli Jan 15, 2024
0ab1d20
use Run in tests
lantoli Jan 15, 2024
63671e7
remove SlicePtrToSlice
lantoli Jan 15, 2024
452239a
Merge branch 'CLOUDP-222424_sdk_update_pointers' into CLOUDP-219771-u…
maastha Jan 15, 2024
70c5afa
minor
maastha Jan 15, 2024
02cf0fe
Merge branch 'CLOUDP-219771-update-sdk' into CLOUDP-219771-new-org-pa…
maastha Jan 15, 2024
2524eff
update documentation
maastha Jan 15, 2024
2028d05
Merge branch 'master' into CLOUDP-219771-update-sdk
maastha Jan 16, 2024
f5933ec
minor
maastha Jan 16, 2024
866fff5
fix: undo sh file commit
maastha Jan 16, 2024
49a1d9c
fix: undo sh file commit
maastha Jan 16, 2024
c3cfbd9
add documentation and examples
maastha Jan 16, 2024
7c1ef2c
address PR comments
maastha Jan 17, 2024
046ce94
Merge branch 'CLOUDP-219771-update-sdk' into CLOUDP-219771-new-org-pa…
maastha Jan 17, 2024
a6cc69e
address PR comments
maastha Jan 17, 2024
5a08be6
minor
maastha Jan 17, 2024
9ce0107
Apply suggestions from code review
maastha Jan 17, 2024
de65a01
Merge branch 'CLOUDP-219771-update-sdk' of github.com:mongodb/terrafo…
maastha Jan 17, 2024
8e631e7
minor
maastha Jan 17, 2024
fbe2c8c
Merge branch 'master' of github.com:mongodb/terraform-provider-mongod…
maastha Jan 18, 2024
0d2f77f
update include_deleted_orgs deprecation message
maastha Jan 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ resource "mongodbatlas_organization" "test" {
name = "testCreateORG"
description = "test API key from Org Creation Test"
role_names = ["ORG_OWNER"]
multi_factor_auth_required = true
restrict_employee_access = true
api_access_list_required = false
}

output "org_id" {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 7 additions & 0 deletions internal/common/conversion/type_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ func IsStringPresent(strPtr *string) bool {
func MongoDBRegionToAWSRegion(region string) string {
return strings.ReplaceAll(strings.ToLower(region), "_", "-")
}

func NonEmptySliceToSlicePtr[T any](v []T) *[]T {
if len(v) == 0 {
return nil
}
return &v
}
23 changes: 23 additions & 0 deletions internal/common/conversion/type_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -67,3 +68,25 @@ func TestMongoDBRegionToAWSRegion(t *testing.T) {
}
}
}

func TestNonEmptySliceToSlicePtr(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.NonEmptySliceToSlicePtr(tc.given))
})
}
}
2 changes: 1 addition & 1 deletion internal/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"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"
atlasSDK "go.mongodb.org/atlas-sdk/v20231115003/admin"
matlasClient "go.mongodb.org/atlas/mongodbatlas"
realmAuth "go.mongodb.org/realm/auth"
"go.mongodb.org/realm/realm"
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider_authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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))
}

Expand All @@ -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(&notifications[i]))
}

return string(f.Bytes())
Expand Down Expand Up @@ -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)
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
}
Expand Down
16 changes: 8 additions & 8 deletions internal/service/alertconfiguration/model_alert_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.NonEmptySliceToSlicePtr(n.Roles),
MicrosoftTeamsWebhookUrl: n.MicrosoftTeamsWebhookURL.ValueStringPointer(),
WebhookSecret: n.WebhookSecret.ValueStringPointer(),
WebhookUrl: n.WebhookURL.ValueStringPointer(),
Expand Down Expand Up @@ -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),
}
}

Expand All @@ -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)),
Expand All @@ -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()),
Expand Down Expand Up @@ -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{}),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.NonEmptySliceToSlicePtr(roles),
ApiToken: admin.PtrString("newApiToken"),
},
},
Expand Down Expand Up @@ -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.NonEmptySliceToSlicePtr(roles),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.NonEmptySliceToSlicePtr(NewMatcherList(alertConfigPlan.Matcher)),
MetricThreshold: NewMetricThreshold(alertConfigPlan.MetricThresholdConfig),
Threshold: NewThreshold(alertConfigPlan.ThresholdConfig),
}
Expand All @@ -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.NonEmptySliceToSlicePtr(notifications)

apiResp, _, err := connV2.AlertConfigurationsApi.CreateAlertConfiguration(ctx, projectID, apiReq).Execute()
if err != nil {
Expand Down Expand Up @@ -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.NonEmptySliceToSlicePtr(NewMatcherList(alertConfigPlan.Matcher))
}

// Always refresh structure to handle service keys being obfuscated coming back from read API call
Expand All @@ -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.NonEmptySliceToSlicePtr(notifications)

var updatedAlertConfigResp *admin.GroupAlertsConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions internal/service/atlasuser/data_source_atlas_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()),
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/service/atlasuser/data_source_atlas_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)),
Expand Down
8 changes: 4 additions & 4 deletions internal/service/atlasuser/data_source_atlas_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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
}

Expand Down
Loading
Loading