Skip to content

Commit

Permalink
chore: Updates Atlas Go SDK and unifies resource prefix names in tests (
Browse files Browse the repository at this point in the history
#1966)

* build(deps): bump go.mongodb.org/atlas-sdk

* revert changes in v20231001002

* fix teams

* TestStepCheckEmptyPlan

* update linter

* update mockery

* remove unneeded linter rules

* random name functions

* RandomIP

* more random name functions [skip ci]

* fix backup schedule imports [skip ci]

* run ci

---------

Co-authored-by: lantoli <[email protected]>
  • Loading branch information
github-actions[bot] and lantoli authored Feb 21, 2024
1 parent 5aa9dfd commit 27a3486
Show file tree
Hide file tree
Showing 182 changed files with 576 additions and 613 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-health.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804
with:
version: v1.55.0
version: v1.56.2
website-lint:
runs-on: ubuntu-latest
steps:
Expand Down
17 changes: 0 additions & 17 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ linters-settings:
- opinionated
- performance
- style
disabled-checks:
- octalLiteral
govet:
check-shadowing: true
enable:
Expand Down Expand Up @@ -120,23 +118,8 @@ linters:
# - gocognit
issues:
exclude:
- composite literal uses unkeyed fields
- Using the variable on range scope .* in function literal
- declaration of ".*" shadows declaration at line .*
- only one cuddle assignment allowed before if statement
- func `testAccMongoDBAtlasThirdPartyIntegrationDataSourceConfig` is unused
- func `testAccMongoDBAtlasAlertConfigurationConfigWithThresholdUpdated` is unused
- func `testAccMongoDBAtlasAlertConfigurationConfigWithMatchers` is unused
- func `testAccDSMongoDBAtlasAlertConfigurationConfigWithThreshold` is unused
- func `testAccMongoDBAtlasCloudProviderSnapshotRestoreJobConfigPointInTime` is unused
- func `testAccMongoDBAtlasCloudBackupScheduleExportPoliciesConfig` is unused
exclude-rules:
- path: _test\.go
linters:
- testpackage
# part of the golangci govet package is picking up things that go vet doesn't. Seems flaky, shutting that specific error off

# Exclude some staticcheck messages
- linters:
- staticcheck
text: "SA1019:" # d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK
Expand Down
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ GITTAG=$(shell git describe --always --tags)
VERSION=$(GITTAG:v%=%)
LINKER_FLAGS=-s -w -X 'github.com/mongodb/terraform-provider-mongodbatlas/version.ProviderVersion=${VERSION}'

GOLANGCI_VERSION=v1.55.0
MOCKERY_VERSION=v2.38.0
GOLANGCI_VERSION=v1.56.2
MOCKERY_VERSION=v2.42.0

export PATH := $(shell go env GOPATH)/bin:$(PATH)
export SHELL := env PATH=$(PATH) /bin/bash
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/zclconf/go-cty v1.14.2
go.mongodb.org/atlas v0.36.0
go.mongodb.org/atlas-sdk/v20231001002 v20231001002.0.0
go.mongodb.org/atlas-sdk/v20231115006 v20231115006.0.0
go.mongodb.org/atlas-sdk/v20231115007 v20231115007.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 @@ -759,8 +759,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/v20231115006 v20231115006.0.0 h1:3FvL4J1Ni/4PR2P0Gapo3wJ6w/6RpFbaJd/IGrTYgMQ=
go.mongodb.org/atlas-sdk/v20231115006 v20231115006.0.0/go.mod h1:R0s6He5geum/u75tpnww4nbPGVFnGO1vVp8Heiq6aq8=
go.mongodb.org/atlas-sdk/v20231115007 v20231115007.0.0 h1:gvUBkSoeNtM9FSBQy8rh6cm6qXn4yXbQGzK09X0eAdk=
go.mongodb.org/atlas-sdk/v20231115007 v20231115007.0.0/go.mod h1:JU7JOUGcv7pfDzbRTwIr8hGy2R1lehdrdfGj9fDjSVY=
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

func TestTerraformResourceMongoDBAtlasEncryptionAtRestWithRole_basicAWS(t *testing.T) {
Expand Down Expand Up @@ -90,10 +90,9 @@ func TestResourceEncryptionAtRestAws(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = mongoSecrets.PublicKey
privateKey = mongoSecrets.PrivateKey

awsAccess = awsSecrets.AccessKey
awsSecret = awsSecrets.SecretKey
awsCustomer = awsSecrets.CustomerMasterKey
Expand Down Expand Up @@ -136,7 +135,7 @@ func TestResourceEncryptionAtRestAzure(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = mongoSecrets.PublicKey
privateKey = mongoSecrets.PrivateKey

Expand Down Expand Up @@ -190,7 +189,7 @@ func TestResourceEncryptionAtRestGCP(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = mongoSecrets.PublicKey
privateKey = mongoSecrets.PrivateKey

Expand Down
38 changes: 19 additions & 19 deletions integrationtesting/test-upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gruntwork-io/terratest/modules/terraform"
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

var (
Expand All @@ -22,13 +23,12 @@ func TestUpgradeNetworkContainerRegionsGCP(t *testing.T) {
t.Parallel()

var (
randInt = acctest.RandIntRange(0, 255)
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
atlasCIDRBlock = fmt.Sprintf("10.%d.0.0/18", randInt)
providerName = "GCP"
publicKey = os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
privateKey = os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")
providerName = "GCP"
atlasCIDRBlock = fmt.Sprintf("10.%d.0.0/18", acctest.RandIntRange(0, 255))
)
// Construct the terraform options with default retryable errors to handle the most common
// retryable errors in terraform testing.
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestUpgradeDatabaseUserLDAPAuthType(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
roleName = "atlasAdmin"
username = "[email protected],OU=users,DC=example,DC=com"
publicKey = os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
Expand Down Expand Up @@ -146,8 +146,8 @@ func TestUpgradeClusterDeprecationEBSVolume(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
clusterName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
clusterName = acc.RandomClusterName()
publicKey = os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
privateKey = os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")
majorVersion = testAccGetMongoDBAtlasMajorVersion()
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestUpgradePrivateEndpoint(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
privateKey = os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")
baseURL = os.Getenv("MONGODB_ATLAS_BASE_URL")
Expand Down Expand Up @@ -279,10 +279,10 @@ func TestUpgradeProjectIPWhitelistDeprecation(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
privateKey = os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")
ipAddress = fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255))
ipAddress = acc.RandomIP(179, 154, 226)
comment = fmt.Sprintf("TestAcc for ipAddress (%s)", ipAddress)
)
// Construct the terraform options with default retryable errors to handle the most common
Expand Down Expand Up @@ -339,8 +339,8 @@ func TestUpgradeDesignIDState(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
clusterName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
clusterName = acc.RandomClusterName()
description = fmt.Sprintf("My description in %s", clusterName)
retentionInDays = "1"
publicKey = mongoSecrets.PublicKey
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestUpgradePrivateLinkEndpointDeprecation(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
privateKey = os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")
awsAccess = os.Getenv("AWS_ACCESS_KEY_ID")
Expand Down Expand Up @@ -538,10 +538,10 @@ func TestUpgradeCloudBackupPolicies(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
privateKey = os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")
clusterName = fmt.Sprintf("test-acc-%s", acctest.RandString(10))
clusterName = acc.RandomClusterName()
)
// Construct the terraform options with default retryable errors to handle the most common
// retryable errors in terraform testing.
Expand Down Expand Up @@ -597,7 +597,7 @@ func TestUpgradeEncryptionAtRestAws(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = mongoSecrets.PublicKey
privateKey = mongoSecrets.PrivateKey

Expand Down Expand Up @@ -664,7 +664,7 @@ func TestUpgradeEncryptionAtRestAzure(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = mongoSecrets.PublicKey
privateKey = mongoSecrets.PrivateKey

Expand Down Expand Up @@ -739,7 +739,7 @@ func TestUpgradeEncryptionAtRestGCP(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
publicKey = mongoSecrets.PublicKey
privateKey = mongoSecrets.PrivateKey

Expand Down Expand Up @@ -798,8 +798,8 @@ func TestUpgradeCloudBackupSnapshot(t *testing.T) {

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
clusterName = fmt.Sprintf("test-acc-%s", acctest.RandString(10))
projectName = acc.RandomProjectName()
clusterName = acc.RandomClusterName()
)
// Construct the terraform options with default retryable errors to handle the most common
// retryable errors in terraform testing.
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/v20231115006/admin"
"go.mongodb.org/atlas-sdk/v20231115007/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 @@ -13,7 +13,7 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/version"
"github.com/spf13/cast"
admin20231001002 "go.mongodb.org/atlas-sdk/v20231001002/admin"
"go.mongodb.org/atlas-sdk/v20231115006/admin"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
matlasClient "go.mongodb.org/atlas/mongodbatlas"
realmAuth "go.mongodb.org/realm/auth"
"go.mongodb.org/realm/realm"
Expand Down
5 changes: 2 additions & 3 deletions internal/provider/provider_authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
"os"
"testing"

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

func TestAccSTSAssumeRole_basic(t *testing.T) {
var (
resourceName = "mongodbatlas_project.test"
projectName = acctest.RandomWithPrefix("test-acc")
projectName = acc.RandomProjectName()
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
clusterCount = "0"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"testing"

"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"
)
Expand All @@ -14,8 +13,8 @@ func TestAccConfigDSAccesslistAPIKey_basic(t *testing.T) {
resourceName := "mongodbatlas_access_list_api_key.test"
dataSourceName := "data.mongodbatlas_access_list_api_key.test"
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
description := fmt.Sprintf("test-acc-accesslist-api_key-%s", acctest.RandString(5))
ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255))
description := acc.RandomName()
ipAddress := acc.RandomIP(179, 154, 226)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
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/v20231115006/admin"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
)

func PluralDataSource() *schema.Resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import (
"os"
"testing"

"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"
)

func TestAccConfigDSAccesslistAPIKeys_basic(t *testing.T) {
resourceName := "mongodbatlas_access_list_api_key.test"
dataSourceName := "data.mongodbatlas_access_list_api_keys.test"
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
description := fmt.Sprintf("test-acc-accesslist-api_keys-%s", acctest.RandString(5))
ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255))
var (
resourceName = "mongodbatlas_access_list_api_key.test"
dataSourceName = "data.mongodbatlas_access_list_api_keys.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
description = acc.RandomName()
ipAddress = acc.RandomIP(179, 154, 226)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acc.PreCheckBasic(t) },
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/v20231115006/admin"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
)

func Resource() *schema.Resource {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package accesslistapikey_test

import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
)

func TestAccMigrationProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
resourceName := "mongodbatlas_access_list_api_key.test"
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
ipAddress := fmt.Sprintf("179.154.226.%d", acctest.RandIntRange(0, 255))
description := fmt.Sprintf("test-acc-access_list-api_key-%s", acctest.RandString(5))
var (
resourceName = "mongodbatlas_access_list_api_key.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
ipAddress = acc.RandomIP(179, 154, 226)
description = acc.RandomName()
)

resource.Test(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
Expand Down Expand Up @@ -46,10 +46,12 @@ func TestAccMigrationProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
}

func TestAccMigrationProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
resourceName := "mongodbatlas_access_list_api_key.test"
orgID := os.Getenv("MONGODB_ATLAS_ORG_ID")
cidrBlock := fmt.Sprintf("179.154.226.%d/32", acctest.RandIntRange(0, 255))
description := fmt.Sprintf("test-acc-access_list-api_key-%s", acctest.RandString(5))
var (
resourceName = "mongodbatlas_access_list_api_key.test"
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
cidrBlock = acc.RandomIP(179, 154, 226) + "/32"
description = acc.RandomName()
)

resource.Test(t, resource.TestCase{
PreCheck: func() { mig.PreCheckBasic(t) },
Expand Down
Loading

0 comments on commit 27a3486

Please sign in to comment.