Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
Update regional mode test to spin up vpc requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
evertsd committed Jun 21, 2022
1 parent 310a29c commit 3f5893c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ func TestAccResourceMongoDBAtlasPrivateEndpointRegionalMode_basic(t *testing.T)
awsAccessKey = os.Getenv("AWS_ACCESS_KEY_ID")
awsSecretKey = os.Getenv("AWS_SECRET_ACCESS_KEY")

projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
providerName = "AWS"
region = os.Getenv("AWS_REGION")
vpcID = os.Getenv("AWS_VPC_ID")
subnetID = os.Getenv("AWS_SUBNET_ID")
securityGroupID = os.Getenv("AWS_SECURITY_GROUP_ID")
projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID")
providerName = "AWS"
region = os.Getenv("AWS_REGION")

clusterName = fmt.Sprintf("test-acc-global-%s", acctest.RandString(10))
)

endpointResources := testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(
awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID, endpointResourceSuffix,
endpointResources := testAccMongoDBAtlasPrivateLinkEndpointServiceConfigUnmanagedAWS(
awsAccessKey, awsSecretKey, projectID, providerName, region, endpointResourceSuffix,
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -45,7 +42,8 @@ func TestAccResourceMongoDBAtlasPrivateEndpointRegionalMode_basic(t *testing.T)
Config: testAccMongoDBAtlasPrivateEndpointRegionalModeConfig(resourceSuffix, projectID, clusterName, endpointResources, endpointResourceSuffix, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasPrivateEndpointRegionalModeExists(resourceName),
testAccCheckMongoDBAtlasPrivateEndpointRegionalModeClustersUpToDate(projectID, clusterName),
resource.TestCheckResourceAttrSet("mongodbatlas_cluster.global_cluster", "connection_strings"),
// testAccCheckMongoDBAtlasPrivateEndpointRegionalModeClustersUpToDate(projectID, clusterName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "enabled"),
resource.TestCheckResourceAttr(resourceName, "enabled", "false"),
Expand All @@ -55,7 +53,8 @@ func TestAccResourceMongoDBAtlasPrivateEndpointRegionalMode_basic(t *testing.T)
Config: testAccMongoDBAtlasPrivateEndpointRegionalModeConfig(resourceSuffix, projectID, clusterName, endpointResources, endpointResourceSuffix, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckMongoDBAtlasPrivateEndpointRegionalModeExists(resourceName),
testAccCheckMongoDBAtlasPrivateEndpointRegionalModeClustersUpToDate(projectID, clusterName),
resource.TestCheckResourceAttrSet("mongodbatlas_cluster.global_cluster", "connection_strings"),
// testAccCheckMongoDBAtlasPrivateEndpointRegionalModeClustersUpToDate(projectID, clusterName),
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
resource.TestCheckResourceAttrSet(resourceName, "enabled"),
resource.TestCheckResourceAttr(resourceName, "enabled", "true"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,94 @@ func testAccMongoDBAtlasPrivateLinkEndpointServiceConfigCompleteAWS(awsAccessKey
}
`, awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID, serviceResourceName)
}

func testAccMongoDBAtlasPrivateLinkEndpointServiceConfigUnmanagedAWS(awsAccessKey, awsSecretKey, projectID, providerName, region, serviceResourceName string) string {
return fmt.Sprintf(`
provider "aws" {
region = "%[5]s"
access_key = "%[1]s"
secret_key = "%[2]s"
}
resource "mongodbatlas_privatelink_endpoint" "test" {
project_id = "%[3]s"
provider_name = "%[4]s"
region = "%[5]s"
}
resource "aws_vpc_endpoint" "ptfe_service" {
vpc_id = aws_vpc.primary.id
service_name = mongodbatlas_privatelink_endpoint.test.endpoint_service_name
vpc_endpoint_type = "Interface"
subnet_ids = [aws_subnet.primary-az1.id]
security_group_ids = [aws_security_group.primary_default.id]
}
resource "mongodbatlas_privatelink_endpoint_service" %[6]q {
project_id = mongodbatlas_privatelink_endpoint.test.project_id
endpoint_service_id = aws_vpc_endpoint.ptfe_service.id
private_link_id = mongodbatlas_privatelink_endpoint.test.id
provider_name = %[4]q
}
resource "aws_vpc" "primary" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
enable_dns_support = true
}
# Create IGW
resource "aws_internet_gateway" "primary" {
vpc_id = aws_vpc.primary.id
}
# Route Table
resource "aws_route" "primary-internet_access" {
route_table_id = aws_vpc.primary.main_route_table_id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.primary.id
}
# Subnet-A
resource "aws_subnet" "primary-az1" {
vpc_id = aws_vpc.primary.id
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
availability_zone = "%[5]sa"
}
# Subnet-B
resource "aws_subnet" "primary-az2" {
vpc_id = aws_vpc.primary.id
cidr_block = "10.0.2.0/24"
map_public_ip_on_launch = false
availability_zone = "%[5]sb"
}
/*Security-Group
Ingress - Port 80 -- limited to instance
Port 22 -- Open to ssh without limitations
Egress - Open to All*/
resource "aws_security_group" "primary_default" {
name_prefix = "default-"
description = "Default security group for all instances in vpc"
vpc_id = aws_vpc.primary.id
ingress {
from_port = 0
to_port = 0
protocol = "tcp"
cidr_blocks = [
"0.0.0.0/0",
]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
`, awsAccessKey, awsSecretKey, projectID, providerName, region, serviceResourceName)
}

0 comments on commit 3f5893c

Please sign in to comment.