Skip to content

Commit

Permalink
INTMDB-212: Deprecation of Project IP Whitelist (#473)
Browse files Browse the repository at this point in the history
* chore: updated vendor

* deprecated project ip whitelist

* docs: added guide for deprecation project whitelist

* tests: added terratest for upgrading/import for whitelist and access list

* updated the title

Co-authored-by: Edgar López <[email protected]>
  • Loading branch information
coderGo93 and Edgar López authored Jun 8, 2021
1 parent 8b22df8 commit 9acaa6f
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 1,108 deletions.
17 changes: 17 additions & 0 deletions examples/test-upgrade/v100/ip-whitelist-accestList/v091/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "mongodbatlas_project" "test" {
name = var.project_name
org_id = var.org_id
}


resource "mongodbatlas_project_ip_whitelist" "test" {
project_id = mongodbatlas_project.test.id
ip_address = var.ip_address
comment = var.comment
}
output "project_id" {
value = mongodbatlas_project.test.id
}
output "entry" {
value = mongodbatlas_project_ip_whitelist.test.ip_address
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "public_key" {
description = "The public API key for MongoDB Atlas"
default = ""
}
variable "private_key" {
description = "The private API key for MongoDB Atlas"
default = ""
}
variable "project_name" {
description = "Atlas project name"
default = ""
}
variable "org_id" {
description = "The organization ID"
default = ""
}
variable "ip_address" {
description = "IP Address"
default = ""
}
variable "comment" {
description = "Comment"
default = ""
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.9.1"
}
}
required_version = ">= 0.15"
}
11 changes: 11 additions & 0 deletions examples/test-upgrade/v100/ip-whitelist-accestList/v100/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "mongodbatlas_project" "test" {
name = var.project_name
org_id = var.org_id
}


resource "mongodbatlas_project_ip_access_list" "test" {
project_id = mongodbatlas_project.test.id
ip_address = var.ip_address
comment = var.comment
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
variable "public_key" {
description = "The public API key for MongoDB Atlas"
default = ""
}
variable "private_key" {
description = "The private API key for MongoDB Atlas"
default = ""
}
variable "project_name" {
description = "Atlas project name"
default = ""
}
variable "org_id" {
description = "The organization ID"
default = ""
}
variable "ip_address" {
description = "IP Address"
default = ""
}
variable "comment" {
description = "Comment"
default = ""
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.1.0-dev"
}
}
required_version = ">= 0.15"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ require (
github.com/spf13/cast v1.3.1
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20200518153306-40099de47e37
github.com/terraform-providers/terraform-provider-google v1.20.1-0.20200518165017-1dd21651c496
go.mongodb.org/atlas v0.8.1-0.20210528214129-330aa9199dbf
go.mongodb.org/atlas v0.8.1-0.20210604212331-3f489d7a4eed
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ go.mongodb.org/atlas v0.7.3-0.20210302081736-7ccf7e1f4351 h1:3NuN2K6VtDuDNfAKX/4
go.mongodb.org/atlas v0.7.3-0.20210302081736-7ccf7e1f4351/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
go.mongodb.org/atlas v0.8.1-0.20210528214129-330aa9199dbf h1:B9IN5pGOtgtgmx8jjtuP9Gx6PPFWIIKx3AKQKYKcxJM=
go.mongodb.org/atlas v0.8.1-0.20210528214129-330aa9199dbf/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
go.mongodb.org/atlas v0.8.1-0.20210604212331-3f489d7a4eed h1:qPaT/RvfXXKEJ2fTNckgPKoqfg4oLgJFj7exXUM8mUQ=
go.mongodb.org/atlas v0.8.1-0.20210604212331-3f489d7a4eed/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
63 changes: 62 additions & 1 deletion integration-testing/test-upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
)

const localPluginPath = "TERRAFORM PLUGINS PATH"
var (
localPluginPath = os.Getenv("TERRATEST_PLUGIN_PATH")
)

func TestUpgradeNetworkContainerRegionsGCP(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -276,6 +278,65 @@ func TestUpgradePrivateEndpoint(t *testing.T) {

}

func TestUpgradeProjectIPWhitelistDeprecation(t *testing.T) {
t.Parallel()

var (
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
projectName = acctest.RandomWithPrefix("test-acc")
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))
comment = fmt.Sprintf("TestAcc for ipAddress (%s)", ipAddress)
)
// Construct the terraform options with default retryable errors to handle the most common
// retryable errors in terraform testing.
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: "../examples/test-upgrade/v100/ip-whitelist-accestList/v091",
Vars: map[string]interface{}{
"project_name": projectName,
"org_id": orgID,
"ip_address": ipAddress,
"public_key": publicKey,
"private_key": privateKey,
"comment": comment,
},
})

// At the end of the test, run `terraform destroy` to clean up any resources that were created.
defer terraform.Destroy(t, terraformOptions)

// Run `terraform init` and `terraform apply`. Fail the test if there are any errors.
terraform.InitAndApply(t, terraformOptions)

projectID := terraform.Output(t, terraformOptions, "project_id")
entry := terraform.Output(t, terraformOptions, "entry")

tempTestFolder := CleanUpState(t, "examples/test-upgrade/v100/ip-whitelist-accestList/v100")

terraformOptionsSecond := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// The path to where our Terraform code is located
TerraformDir: tempTestFolder,
Vars: map[string]interface{}{
"project_name": projectName,
"org_id": orgID,
"ip_address": ipAddress,
"public_key": publicKey,
"private_key": privateKey,
"comment": comment,
},
})

terraform.RunTerraformCommand(t, terraformOptionsSecond, "init", fmt.Sprintf("--plugin-dir=%s", localPluginPath))
//Remove states
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project.test", projectID)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_project_ip_access_list.test", fmt.Sprintf("%s-%s", projectID, entry))
// Run `terraform apply`. Fail the test if there are any errors.
terraform.Plan(t, terraformOptionsSecond)

}

// This func means that the terraform state will be always clean to avoid error about resource already used
func CleanUpState(t *testing.T, path string) string {
// Root folder where terraform files should be (relative to the test folder)
Expand Down
107 changes: 0 additions & 107 deletions mongodbatlas/data_source_mongodbatlas_project_ip_whitelist.go

This file was deleted.

Loading

0 comments on commit 9acaa6f

Please sign in to comment.