Skip to content

Commit

Permalink
chore: Upgrades Atlas SDK to v20231115012 (#2211)
Browse files Browse the repository at this point in the history
* initial import path changes

* refactor: adjust to new matchers model

* adjust unit test an assertion functions
  • Loading branch information
AgustinBettati authored Apr 25, 2024
1 parent 5359976 commit 42f6cf6
Show file tree
Hide file tree
Showing 109 changed files with 154 additions and 185 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/zclconf/go-cty v1.14.4
go.mongodb.org/atlas v0.36.0
go.mongodb.org/atlas-sdk/v20231115010 v20231115010.1.0
go.mongodb.org/atlas-sdk/v20231115012 v20231115012.0.0
go.mongodb.org/realm v0.1.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,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/v20231115008 v20231115008.5.0 h1:OuV1HfIpZUZa4+BKvtrvDlNqnilkCkdHspuZok6KAbM=
go.mongodb.org/atlas-sdk/v20231115008 v20231115008.5.0/go.mod h1:0707RpWIrNFZ6Msy/dwRDCzC5JVDon61JoOqcbfCujg=
go.mongodb.org/atlas-sdk/v20231115010 v20231115010.1.0 h1:++ZXml+foSkFymb7/5LsW09zRM1gjqyhMZmPkVjhxcM=
go.mongodb.org/atlas-sdk/v20231115010 v20231115010.1.0/go.mod h1:jfwDhrkj8OyLIn0qQ8SdcwqmALow1G/njEOtPyQgoSM=
go.mongodb.org/atlas-sdk/v20231115012 v20231115012.0.0 h1:W9UBXxf+/honL2H8W0/GizUWa9kJ2Ge0H6gsexPTU6c=
go.mongodb.org/atlas-sdk/v20231115012 v20231115012.0.0/go.mod h1:8Mjf7v7mtjTcwF8NLsKjb1aqFAyf1bmsjzBoykjWdUw=
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
2 changes: 1 addition & 1 deletion internal/common/conversion/flatten_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package conversion
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

func FlattenLinks(links []admin.Link) []map[string]string {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

admin20231115008 "go.mongodb.org/atlas-sdk/v20231115008/admin"
"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
matlasClient "go.mongodb.org/atlas/mongodbatlas"
realmAuth "go.mongodb.org/realm/auth"
"go.mongodb.org/realm/realm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"

"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

func PluralDataSource() *schema.Resource {
Expand Down
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/validation"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

func Resource() *schema.Resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

func PluralDataSource() *schema.Resource {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/advancedcluster/model_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/spf13/cast"
"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115010/mockadmin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
"go.mongodb.org/atlas-sdk/v20231115012/mockadmin"
)

var (
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/validate"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
"github.com/spf13/cast"
"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

const (
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/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

var _ datasource.DataSource = &alertConfigurationDS{}
Expand Down Expand Up @@ -343,14 +343,11 @@ func outputAlertConfigurationResourceImport(label string, alert *admin.GroupAler
return fmt.Sprintf("terraform import mongodbatlas_alert_configuration.%s %s-%s\n", label, *alert.GroupId, *alert.Id)
}

func convertMatcherToCtyValues(matcher map[string]any) map[string]cty.Value {
fieldName, _ := matcher["fieldName"].(string)
operator, _ := matcher["operator"].(string)
value, _ := matcher["value"].(string)
func convertMatcherToCtyValues(matcher admin.StreamsMatcher) map[string]cty.Value {
return map[string]cty.Value{
"field_name": cty.StringVal(fieldName),
"operator": cty.StringVal(operator),
"value": cty.StringVal(value),
"field_name": cty.StringVal(matcher.FieldName),
"operator": cty.StringVal(matcher.Operator),
"value": cty.StringVal(matcher.Value),
}
}

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/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

const alertConfigurationsDataSourceName = "alert_configurations"
Expand Down
34 changes: 14 additions & 20 deletions internal/service/alertconfiguration/model_alert_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"go.mongodb.org/atlas-sdk/v20231115010/admin"
"go.mongodb.org/atlas-sdk/v20231115012/admin"
)

func NewNotificationList(list []TfNotificationModel) (*[]admin.AlertsNotificationRootForGroup, error) {
Expand Down Expand Up @@ -81,13 +81,13 @@ func NewMetricThreshold(tfMetricThresholdConfigSlice []TfMetricThresholdConfigMo
}
}

func NewMatcherList(list []TfMatcherModel) *[]map[string]any {
matchers := make([]map[string]any, len(list))
func NewMatcherList(list []TfMatcherModel) *[]admin.StreamsMatcher {
matchers := make([]admin.StreamsMatcher, len(list))
for i, matcher := range list {
matchers[i] = map[string]any{
"fieldName": matcher.FieldName.ValueString(),
"operator": matcher.Operator.ValueString(),
"value": matcher.Value.ValueString(),
matchers[i] = admin.StreamsMatcher{
FieldName: matcher.FieldName.ValueString(),
Operator: matcher.Operator.ValueString(),
Value: matcher.Value.ValueString(),
}
}
return &matchers
Expand Down Expand Up @@ -250,17 +250,14 @@ func NewTFThresholdConfigModel(t *admin.GreaterThanRawThreshold, currStateSlice
return []TfThresholdConfigModel{newState}
}

func NewTFMatcherModelList(m []map[string]any, currStateSlice []TfMatcherModel) []TfMatcherModel {
func NewTFMatcherModelList(m []admin.StreamsMatcher, currStateSlice []TfMatcherModel) []TfMatcherModel {
matchers := make([]TfMatcherModel, len(m))
if len(m) != len(currStateSlice) { // matchers were modified elsewhere from terraform, or import statement is being called
for i, matcher := range m {
fieldName, _ := matcher["fieldName"].(string)
operator, _ := matcher["operator"].(string)
value, _ := matcher["value"].(string)
matchers[i] = TfMatcherModel{
FieldName: conversion.StringNullIfEmpty(fieldName),
Operator: conversion.StringNullIfEmpty(operator),
Value: conversion.StringNullIfEmpty(value),
FieldName: types.StringValue(matcher.FieldName),
Operator: types.StringValue(matcher.Operator),
Value: types.StringValue(matcher.Value),
}
}
return matchers
Expand All @@ -269,16 +266,13 @@ func NewTFMatcherModelList(m []map[string]any, currStateSlice []TfMatcherModel)
currState := currStateSlice[i]
newState := TfMatcherModel{}
if !currState.FieldName.IsNull() {
fieldName, _ := matcher["fieldName"].(string)
newState.FieldName = conversion.StringNullIfEmpty(fieldName)
newState.FieldName = types.StringValue(matcher.FieldName)
}
if !currState.Operator.IsNull() {
operator, _ := matcher["operator"].(string)
newState.Operator = conversion.StringNullIfEmpty(operator)
newState.Operator = types.StringValue(matcher.Operator)
}
if !currState.Value.IsNull() {
value, _ := matcher["value"].(string)
newState.Value = conversion.StringNullIfEmpty(value)
newState.Value = types.StringValue(matcher.Value)
}
matchers[i] = newState
}
Expand Down
Loading

0 comments on commit 42f6cf6

Please sign in to comment.