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

Upgrade CosmosDB Account API version from 2021-10-15 to 2023-04-15 #24541

Merged
15 changes: 8 additions & 7 deletions internal/services/cosmos/common/cors_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ package common
import (
"strings"

"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2023-04-15/cosmosdb"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/utils"
Expand Down Expand Up @@ -80,20 +81,20 @@ func SchemaCorsRule() *pluginsdk.Schema {
}
}

func ExpandCosmosCorsRule(input []interface{}) *[]documentdb.CorsPolicy {
func ExpandCosmosCorsRule(input []interface{}) *[]cosmosdb.CorsPolicy {
if len(input) == 0 || input[0] == nil {
return nil
}
corsRules := make([]documentdb.CorsPolicy, 0)
corsRules := make([]cosmosdb.CorsPolicy, 0)

if len(input) == 0 {
return &corsRules
}

for _, attr := range input {
corsRuleAttr := attr.(map[string]interface{})
corsRule := documentdb.CorsPolicy{}
corsRule.AllowedOrigins = utils.String(strings.Join(*utils.ExpandStringSlice(corsRuleAttr["allowed_origins"].([]interface{})), ","))
corsRule := cosmosdb.CorsPolicy{}
corsRule.AllowedOrigins = strings.Join(*utils.ExpandStringSlice(corsRuleAttr["allowed_origins"].([]interface{})), ",")
corsRule.ExposedHeaders = utils.String(strings.Join(*utils.ExpandStringSlice(corsRuleAttr["exposed_headers"].([]interface{})), ","))
corsRule.AllowedHeaders = utils.String(strings.Join(*utils.ExpandStringSlice(corsRuleAttr["allowed_headers"].([]interface{})), ","))
corsRule.AllowedMethods = utils.String(strings.Join(*utils.ExpandStringSlice(corsRuleAttr["allowed_methods"].([]interface{})), ","))
Expand All @@ -108,7 +109,7 @@ func ExpandCosmosCorsRule(input []interface{}) *[]documentdb.CorsPolicy {
return &corsRules
}

func FlattenCosmosCorsRule(input *[]documentdb.CorsPolicy) []interface{} {
func FlattenCosmosCorsRule(input *[]cosmosdb.CorsPolicy) []interface{} {
corsRules := make([]interface{}, 0)

if input == nil || len(*input) == 0 {
Expand All @@ -124,7 +125,7 @@ func FlattenCosmosCorsRule(input *[]documentdb.CorsPolicy) []interface{} {

corsRules = append(corsRules, map[string]interface{}{
"allowed_headers": flattenCorsProperty(corsRule.AllowedHeaders),
"allowed_origins": flattenCorsProperty(corsRule.AllowedOrigins),
"allowed_origins": flattenCorsProperty(pointer.To(corsRule.AllowedOrigins)),
"allowed_methods": flattenCorsProperty(corsRule.AllowedMethods),
"exposed_headers": flattenCorsProperty(corsRule.ExposedHeaders),
"max_age_in_seconds": maxAgeInSeconds,
Expand Down
18 changes: 9 additions & 9 deletions internal/services/cosmos/common/ip_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package common
import (
"strings"

"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2023-04-15/cosmosdb"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

// CosmosDBIpRulesToIpRangeFilterThreePointOh todo Remove for 4.0
func CosmosDBIpRulesToIpRangeFilterThreePointOh(ipRules *[]documentdb.IPAddressOrRange) string {
func CosmosDBIpRulesToIpRangeFilterThreePointOh(ipRules *[]cosmosdb.IPAddressOrRange) string {
ipRangeFilter := make([]string, 0)
if ipRules != nil {
for _, ipRule := range *ipRules {
Expand All @@ -22,7 +22,7 @@ func CosmosDBIpRulesToIpRangeFilterThreePointOh(ipRules *[]documentdb.IPAddressO
return strings.Join(ipRangeFilter, ",")
}

func CosmosDBIpRulesToIpRangeFilter(ipRules *[]documentdb.IPAddressOrRange) []string {
func CosmosDBIpRulesToIpRangeFilter(ipRules *[]cosmosdb.IPAddressOrRange) []string {
ipRangeFilter := make([]string, 0)
if ipRules != nil {
for _, ipRule := range *ipRules {
Expand All @@ -33,10 +33,10 @@ func CosmosDBIpRulesToIpRangeFilter(ipRules *[]documentdb.IPAddressOrRange) []st
return ipRangeFilter
}

func CosmosDBIpRangeFilterToIpRules(ipRangeFilter []string) *[]documentdb.IPAddressOrRange {
ipRules := make([]documentdb.IPAddressOrRange, 0)
func CosmosDBIpRangeFilterToIpRules(ipRangeFilter []string) *[]cosmosdb.IPAddressOrRange {
ipRules := make([]cosmosdb.IPAddressOrRange, 0)
for _, ipRange := range ipRangeFilter {
ipRules = append(ipRules, documentdb.IPAddressOrRange{
ipRules = append(ipRules, cosmosdb.IPAddressOrRange{
IPAddressOrRange: utils.String(ipRange),
})
}
Expand All @@ -45,11 +45,11 @@ func CosmosDBIpRangeFilterToIpRules(ipRangeFilter []string) *[]documentdb.IPAddr
}

// CosmosDBIpRangeFilterToIpRulesThreePointOh todo Remove for 4.0
func CosmosDBIpRangeFilterToIpRulesThreePointOh(ipRangeFilter string) *[]documentdb.IPAddressOrRange {
ipRules := make([]documentdb.IPAddressOrRange, 0)
func CosmosDBIpRangeFilterToIpRulesThreePointOh(ipRangeFilter string) *[]cosmosdb.IPAddressOrRange {
ipRules := make([]cosmosdb.IPAddressOrRange, 0)
if len(ipRangeFilter) > 0 {
for _, ipRange := range strings.Split(ipRangeFilter, ",") {
ipRules = append(ipRules, documentdb.IPAddressOrRange{
ipRules = append(ipRules, cosmosdb.IPAddressOrRange{
IPAddressOrRange: utils.String(ipRange),
})
}
Expand Down
16 changes: 8 additions & 8 deletions internal/services/cosmos/common/ip_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"reflect"
"testing"

"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2023-04-15/cosmosdb"
)

var (
Expand All @@ -18,7 +18,7 @@ var (
func TestCosmosDBIpRulesToIpRangeFilter(t *testing.T) {
testData := []struct {
Name string
Input *[]documentdb.IPAddressOrRange
Input *[]cosmosdb.IPAddressOrRange
Expected []string
}{
{
Expand All @@ -28,14 +28,14 @@ func TestCosmosDBIpRulesToIpRangeFilter(t *testing.T) {
},
{
Name: "One element",
Input: &[]documentdb.IPAddressOrRange{
Input: &[]cosmosdb.IPAddressOrRange{
{IPAddressOrRange: &ipAddressOne},
},
Expected: []string{"127.0.0.1/32"},
},
{
Name: "Multiple elements",
Input: &[]documentdb.IPAddressOrRange{
Input: &[]cosmosdb.IPAddressOrRange{
{IPAddressOrRange: &ipAddressOne},
{IPAddressOrRange: &ipAddressTwo},
},
Expand All @@ -58,24 +58,24 @@ func TestCosmosDBIpRangeFilterToIpRules(t *testing.T) {
testData := []struct {
Name string
Input []string
Expected *[]documentdb.IPAddressOrRange
Expected *[]cosmosdb.IPAddressOrRange
}{
{
Name: "Empty",
Input: []string{},
Expected: &[]documentdb.IPAddressOrRange{},
Expected: &[]cosmosdb.IPAddressOrRange{},
},
{
Name: "One element",
Input: []string{ipAddressOne},
Expected: &[]documentdb.IPAddressOrRange{
Expected: &[]cosmosdb.IPAddressOrRange{
{IPAddressOrRange: &ipAddressOne},
},
},
{
Name: "Multiple elements",
Input: []string{ipAddressOne, ipAddressTwo},
Expected: &[]documentdb.IPAddressOrRange{
Expected: &[]cosmosdb.IPAddressOrRange{
{IPAddressOrRange: &ipAddressOne},
{IPAddressOrRange: &ipAddressTwo},
},
Expand Down
Loading
Loading