Skip to content

Commit

Permalink
INTMDB-214: Deprecation of private endpoint (#484)
Browse files Browse the repository at this point in the history
* deleted deprecated resource, datasource and docs of private endpoint

* added upgrade guide for deprecation private endpoint

* changed name of resource

* added terratest for deprecation private endpoint and import with privatelink endpoint

* added comments

Co-authored-by: Edgar López <[email protected]>
  • Loading branch information
coderGo93 and Edgar López authored Jun 29, 2021
1 parent a5756de commit 3e1befb
Show file tree
Hide file tree
Showing 23 changed files with 304 additions and 1,429 deletions.
10 changes: 5 additions & 5 deletions examples/aws-atlas-privatelink/atlas-pl.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
resource "mongodbatlas_private_endpoint" "atlaspl" {
resource "mongodbatlas_privatelink_endpoint" "atlaspl" {
project_id = var.atlasprojectid
provider_name = "AWS"
region = var.aws_region
}

resource "aws_vpc_endpoint" "ptfe_service" {
vpc_id = aws_vpc.primary.id
service_name = mongodbatlas_private_endpoint.atlaspl.endpoint_service_name
service_name = mongodbatlas_privatelink_endpoint.atlaspl.endpoint_service_name
vpc_endpoint_type = "Interface"
subnet_ids = [aws_subnet.primary-az1.id, aws_subnet.primary-az2.id]
security_group_ids = [aws_security_group.primary_default.id]
}

resource "mongodbatlas_private_endpoint_interface_link" "atlaseplink" {
project_id = mongodbatlas_private_endpoint.atlaspl.project_id
private_link_id = mongodbatlas_private_endpoint.atlaspl.private_link_id
resource "mongodbatlas_privatelink_endpoint_service" "atlaseplink" {
project_id = mongodbatlas_privatelink_endpoint.atlaspl.project_id
private_link_id = mongodbatlas_privatelink_endpoint.atlaspl.private_link_id
interface_endpoint_id = aws_vpc_endpoint.ptfe_service.id
}
44 changes: 44 additions & 0 deletions examples/test-upgrade/v100/privatelink-endpoint/v091/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This config will create aws endpoint, private endpoint and private endpoint interface
// To verify that everything is working even after terraform plan and show not changes
// and then do the import stuff in the folder for v100

resource "mongodbatlas_project" "test" {
name = var.project_name
org_id = var.org_id
}

provider "aws" {
region = "us-east-1"
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}

resource "mongodbatlas_private_endpoint" "test" {
project_id = mongodbatlas_project.test.id
provider_name = "AWS"
region = "us-east-1"
}

resource "aws_vpc_endpoint" "ptfe_service" {
vpc_id = var.aws_vpc_id
service_name = mongodbatlas_private_endpoint.test.endpoint_service_name
vpc_endpoint_type = "Interface"
subnet_ids = [var.aws_subnet_ids]
security_group_ids = [var.aws_sg_ids]
}

resource "mongodbatlas_private_endpoint_interface_link" "test" {
project_id = mongodbatlas_private_endpoint.test.project_id
private_link_id = mongodbatlas_private_endpoint.test.private_link_id
interface_endpoint_id = aws_vpc_endpoint.ptfe_service.id
}

output "project_id" {
value = mongodbatlas_project.test.id
}
output "private_endpoint_id" {
value = mongodbatlas_private_endpoint.test.private_link_id
}
output "vpc_endpoint_id" {
value = aws_vpc_endpoint.ptfe_service.id
}
44 changes: 44 additions & 0 deletions examples/test-upgrade/v100/privatelink-endpoint/v091/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 "username" {
description = "Username"
default = ""
}
variable "role_name" {
description = "The role name"
default = ""
}
variable "aws_access_key" {
description = "The access key for AWS Account"
default = ""
}
variable "aws_secret_key" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_vpc_id" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_subnet_ids" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_sg_ids" {
description = "The secret key for AWS Account"
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"
}
34 changes: 34 additions & 0 deletions examples/test-upgrade/v100/privatelink-endpoint/v100/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This is only for import stuff because it needs the resource names and set to
// avoid changes when terraform plan

resource "mongodbatlas_project" "test" {
name = var.project_name
org_id = var.org_id
}

provider "aws" {
region = "us-east-1"
access_key = var.aws_access_key
secret_key = var.aws_secret_key
}

resource "mongodbatlas_privatelink_endpoint" "test" {
project_id = mongodbatlas_project.test.id
provider_name = "AWS"
region = "us-east-1"
}

resource "aws_vpc_endpoint" "ptfe_service" {
vpc_id = var.aws_vpc_id
service_name = mongodbatlas_privatelink_endpoint.test.endpoint_service_name
vpc_endpoint_type = "Interface"
subnet_ids = [var.aws_subnet_ids]
security_group_ids = [var.aws_sg_ids]
}

resource "mongodbatlas_privatelink_endpoint_service" "test" {
project_id = mongodbatlas_privatelink_endpoint.test.project_id
private_link_id = mongodbatlas_privatelink_endpoint.test.private_link_id
endpoint_service_id = aws_vpc_endpoint.ptfe_service.id
provider_name = "AWS"
}
44 changes: 44 additions & 0 deletions examples/test-upgrade/v100/privatelink-endpoint/v100/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 "username" {
description = "Username"
default = ""
}
variable "role_name" {
description = "The role name"
default = ""
}
variable "aws_access_key" {
description = "The access key for AWS Account"
default = ""
}
variable "aws_secret_key" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_vpc_id" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_subnet_ids" {
description = "The secret key for AWS Account"
default = ""
}
variable "aws_sg_ids" {
description = "The secret key for AWS Account"
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"
}
73 changes: 73 additions & 0 deletions integration-testing/test-upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,79 @@ func TestUpgradeDesignIDState(t *testing.T) {
terraform.Plan(t, terraformOptionsSnapshotRestore)
}

func TestUpgradePrivateLinkEndpointDeprecation(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")
awsAccess = os.Getenv("AWS_ACCESS_KEY_ID")
awsSecret = os.Getenv("AWS_SECRET_ACCESS_KEY")
awsVPC = os.Getenv("AWS_VPC_ID")
awsSubnets = os.Getenv("AWS_SUBNET_ID")
awsSG = os.Getenv("AWS_SECURITY_GROUP_ID")
)
// 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/privatelink-endpoint/v091",
Vars: map[string]interface{}{
"project_name": projectName,
"org_id": orgID,
"public_key": publicKey,
"private_key": privateKey,
"aws_access_key": awsAccess,
"aws_secret_key": awsSecret,
"aws_vpc_id": awsVPC,
"aws_subnet_ids": awsSubnets,
"aws_sg_ids": awsSG,
},
})

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

terraform.Plan(t, terraformOptions)

projectID := terraform.Output(t, terraformOptions, "project_id")
vpcEndpoint := terraform.Output(t, terraformOptions, "vpc_endpoint_id")
privateEndpoint := terraform.Output(t, terraformOptions, "private_endpoint_id")

tempTestFolder := CleanUpState(t, "examples/test-upgrade/v100/privatelink-endpoint/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,
"public_key": publicKey,
"private_key": privateKey,
"aws_access_key": awsAccess,
"aws_secret_key": awsSecret,
"aws_vpc_id": awsVPC,
"aws_subnet_ids": awsSubnets,
"aws_sg_ids": awsSG,
},
})

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_privatelink_endpoint.test", fmt.Sprintf("%s-%s-%s-%s", projectID, privateEndpoint, "AWS", "us-east-1"))
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "aws_vpc_endpoint.ptfe_service", vpcEndpoint)
terraform.RunTerraformCommand(t, terraformOptionsSecond, "import", "mongodbatlas_privatelink_endpoint_service.test", fmt.Sprintf("%s--%s--%s--%s", projectID, privateEndpoint, vpcEndpoint, "AWS"))
// 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
88 changes: 0 additions & 88 deletions mongodbatlas/data_source_mongodbatlas_private_endpoint.go

This file was deleted.

Loading

0 comments on commit 3e1befb

Please sign in to comment.