-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make it compile * uncomment * rename alert configuration files * example of transition * remove duplicated functions * use transition functions to minimize changes * use encodeStateID * transition deprecation messages * transition AWS and AZURE constants * move resources in new fw to internal * move old provider to internal * start extracting acctest helper methods * fix TF test dependencies * split test transtion * skip test helpers * SkipTestExtCred * no need to expose alertConfigurationDS and alertConfigurationRS * fix type doc * removeLabel and acctest helper methods * extract helper functions from provider * migration test helper methods * DebugPlan and some destroy check and skip functions * fix some linter problems * remove unneeded DebugPlan transition * remove migration package * change test package to avoid circula dependencies * fixed some items shared with test * fixed linter * test factories * move todoacc into acc package * remove _acc_test files * move DebugPlan * remove MongoDBClient from transition * extract pre checks from transition * extract constants from transition * remove transition_test * extract data source and resource references from transition * remove redundant name on resources and data sources * remove transition * databaseuser * rename databaseuser files * project * encryptionatrest * projectipaccesslist * atlasuser * searchdeployment * cluster and advancedcluster * remove share * move testutil * remove folders in mongodbatlas * remove mongodbatlas from filenames * rename provider files * refactor database_user acc * keep same function order in acc files * remove generic check_destroy file * rename package util to conversion * remove common in config * remove flatten from config * move MultiEnvDefaultFunc * move encoded state to conversion * move state conversion test file * remove constant from config * refactor secretsManagerGetSecretValue and ConfigureCredentialsSTS * refactor SecretsManagerGetSecretValue * remove credentials file in config * move ValRegion and ExpandStringList to conversion * rename fw_base * don't export credential methods
- Loading branch information
Showing
308 changed files
with
6,275 additions
and
5,661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package constant | ||
|
||
const ( | ||
AWS = "AWS" | ||
AZURE = "AZURE" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package constant | ||
|
||
const ( | ||
DeprecationParamByDate = "this parameter is deprecated and will be removed by %s" | ||
DeprecationParamByDateWithReplacement = "this parameter is deprecated and will be removed by %s, please transition to %s" | ||
DeprecationParamByVersion = "this parameter is deprecated and will be removed in version %s" | ||
DeprecationResourceByDateWithReplacement = "this resource is deprecated and will be removed in %s, please transition to %s" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package conversion | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"log" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
func GetEncodedID(stateID, keyPosition string) string { | ||
id := "" | ||
if !hasMultipleValues(stateID) { | ||
return stateID | ||
} | ||
|
||
decoded := DecodeStateID(stateID) | ||
id = decoded[keyPosition] | ||
|
||
return id | ||
} | ||
|
||
func EncodeStateID(values map[string]string) string { | ||
encode := func(e string) string { return base64.StdEncoding.EncodeToString([]byte(e)) } | ||
encodedValues := make([]string, 0) | ||
|
||
// sort to make sure the same encoding is returned in case of same input | ||
keys := make([]string, 0, len(values)) | ||
for key := range values { | ||
keys = append(keys, key) | ||
} | ||
|
||
sort.Strings(keys) | ||
|
||
for _, key := range keys { | ||
encodedValues = append(encodedValues, fmt.Sprintf("%s:%s", encode(key), encode(values[key]))) | ||
} | ||
|
||
return strings.Join(encodedValues, "-") | ||
} | ||
|
||
func DecodeStateID(stateID string) map[string]string { | ||
decode := func(d string) string { | ||
decodedString, err := base64.StdEncoding.DecodeString(d) | ||
if err != nil { | ||
log.Printf("[WARN] error decoding state ID: %s", err) | ||
} | ||
|
||
return string(decodedString) | ||
} | ||
decodedValues := make(map[string]string) | ||
encodedValues := strings.Split(stateID, "-") | ||
|
||
for _, value := range encodedValues { | ||
keyValue := strings.Split(value, ":") | ||
if len(keyValue) > 1 { | ||
decodedValues[decode(keyValue[0])] = decode(keyValue[1]) | ||
} | ||
} | ||
|
||
return decodedValues | ||
} | ||
|
||
func hasMultipleValues(value string) bool { | ||
if strings.Contains(value, "-") && strings.Contains(value, ":") { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package conversion_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-test/deep" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" | ||
) | ||
|
||
func TestEncodeDecodeID(t *testing.T) { | ||
expected := map[string]string{ | ||
"project_id": "5cf5a45a9ccf6400e60981b6", | ||
"cluster_name": "test-acc-q4y272zo9y", | ||
"snapshot_id": "5e42e646553855a5aee40138", | ||
} | ||
|
||
got := conversion.DecodeStateID(conversion.EncodeStateID(expected)) | ||
|
||
if diff := deep.Equal(expected, got); diff != nil { | ||
t.Fatalf("Bad testEncodeDecodeID return \n got = %#v\nwant = %#v \ndiff = %#v", got, expected, diff) | ||
} | ||
} | ||
|
||
func TestDecodeID(t *testing.T) { | ||
expected := "Y2x1c3Rlcl9uYW1l:dGVzdC1hY2MtcTR5Mjcyem85eQ==-c25hcHNob3RfaWQ=:NWU0MmU2NDY1NTM4NTVhNWFlZTQwMTM4-cHJvamVjdF9pZA==:NWNmNWE0NWE5Y2NmNjQwMGU2MDk4MWI2" | ||
expected2 := "c25hcHNob3RfaWQ=:NWU0MmU2NDY1NTM4NTVhNWFlZTQwMTM4-cHJvamVjdF9pZA==:NWNmNWE0NWE5Y2NmNjQwMGU2MDk4MWI2-Y2x1c3Rlcl9uYW1l:dGVzdC1hY2MtcTR5Mjcyem85eQ==" | ||
|
||
got := conversion.DecodeStateID(expected) | ||
got2 := conversion.DecodeStateID(expected2) | ||
|
||
if diff := deep.Equal(got, got2); diff != nil { | ||
t.Fatalf("Bad TestDecodeID return \n got = %#v\nwant = %#v \ndiff = %#v", got, got2, diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package conversion | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cast" | ||
) | ||
|
||
func ValRegion(reg any, opt ...string) (string, error) { | ||
region, err := cast.ToStringE(reg) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if region == "" { | ||
return "", fmt.Errorf("region must be set") | ||
} | ||
|
||
/* | ||
We need to check if the option will be similar to network_peering word | ||
(this comes in from the same resource) because network_pering resource | ||
has not the standard region name pattern "US_EAST_1", | ||
instead it needs the following one: "us-east-1". | ||
*/ | ||
if len(opt) > 0 && strings.EqualFold("network_peering", opt[0]) { | ||
return strings.ToLower(strings.ReplaceAll(region, "_", "-")), nil | ||
} | ||
|
||
return strings.ReplaceAll(region, "-", "_"), nil | ||
} | ||
|
||
func ExpandStringList(list []any) (res []string) { | ||
for _, v := range list { | ||
res = append(res, v.(string)) | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package conversion | ||
|
||
func Pointer[T any](x T) *T { | ||
return &x | ||
} | ||
|
||
func IntPtr(v int) *int { | ||
if v != 0 { | ||
return &v | ||
} | ||
return nil | ||
} | ||
|
||
func StringPtr(v string) *string { | ||
if v != "" { | ||
return &v | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
mongodbatlas/util/type_conversion.go → ...rnal/common/conversion/type_conversion.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package util | ||
package conversion | ||
|
||
import ( | ||
"strings" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
mongodbatlas/framework/retry/retry_state.go → internal/common/retrystrategy/retry_state.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package retry | ||
package retrystrategy | ||
|
||
const ( | ||
RetryStrategyPendingState = "PENDING" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...las/framework/validator/cidr_validator.go → internal/common/validate/cidr_validator.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package validator | ||
package validate | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.