Skip to content

B1749 multiple clusters #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ It does so with a Private Link Endpoint. See the Mongo Atlas guide on [Private L
In order to establish this secure connection, an AWS VPC Endpoint from your AWS account is connected to a Mongo Atlas Private Link Endpoint.
This is the recommended and most secure way to connect to your Mongo Atlas cluster. It does make this module AWS specific.

## Connections

This module requires two connections: one to your AWS network and one to your Atlas project.
It will create a secure and performant connection between your AWS network and the Private Link endpoint from your Atlas project.

## Logs

Logs for this infrastructure can be access through Atlas.
42 changes: 2 additions & 40 deletions atlas.tf
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
provider "mongodbatlas" {
public_key = var.atlas_public_key
private_key = var.atlas_private_key
}

resource "aws_secretsmanager_secret" "atlas_public_key" {
name_prefix = "${local.block_name}/atlas_public_key/"
tags = local.tags
kms_key_id = aws_kms_key.this.arn

lifecycle {
create_before_destroy = true
}
}

resource "aws_secretsmanager_secret_version" "atlas_public_key" {
secret_id = aws_secretsmanager_secret.atlas_public_key.id
secret_string = var.atlas_public_key

lifecycle {
create_before_destroy = true
}
}

resource "aws_secretsmanager_secret" "atlas_private_key" {
name_prefix = "${local.block_name}/atlas_private_key/"
tags = local.tags
kms_key_id = aws_kms_key.this.arn

lifecycle {
create_before_destroy = true
}
}

resource "aws_secretsmanager_secret_version" "atlas_private_key" {
secret_id = aws_secretsmanager_secret.atlas_private_key.id
secret_string = var.atlas_private_key

lifecycle {
create_before_destroy = true
}
public_key = data.aws_secretsmanager_secret_version.atlas_public_key.secret_string
private_key = data.aws_secretsmanager_secret_version.atlas_private_key.secret_string
}
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ output "db_admin_secret_id" {
}

output "atlas_public_key_secret_id" {
value = aws_secretsmanager_secret.atlas_public_key.name
value = local.atlas_public_key_secret_id
description = "The public key used to authenticate to your MongoDB Atlas account"
}

output "atlas_private_key_secret_id" {
value = aws_secretsmanager_secret.atlas_private_key.name
value = local.atlas_private_key_secret_id
description = "The private key used to authenticate to your MongoDB Atlas account"
}

output "atlas_project_id" {
value = var.atlas_project_id
value = local.atlas_project_id
description = "string ||| The ID of the Atlas project"
}

output "atlas_private_link_id" {
value = mongodbatlas_privatelink_endpoint.this.id
value = local.private_link_id
description = "string ||| The ID of the Atlas private link"
}
12 changes: 6 additions & 6 deletions private-link.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
resource "mongodbatlas_privatelink_endpoint" "this" {
project_id = var.atlas_project_id
data "mongodbatlas_privatelink_endpoint" "this" {
provider_name = "AWS"
region = data.aws_region.this.name
project_id = local.atlas_project_id
private_link_id = local.private_link_id
}

resource "aws_vpc_endpoint" "this" {
vpc_id = local.vpc_id
service_name = mongodbatlas_privatelink_endpoint.this.endpoint_service_name
service_name = data.mongodbatlas_privatelink_endpoint.this.endpoint_service_name
vpc_endpoint_type = "Interface"
subnet_ids = local.private_subnet_ids
security_group_ids = [aws_security_group.this.id]
tags = merge(local.tags, { Name = local.resource_name })
}

resource "mongodbatlas_privatelink_endpoint_service" "this" {
project_id = var.atlas_project_id
private_link_id = mongodbatlas_privatelink_endpoint.this.private_link_id
project_id = local.atlas_project_id
private_link_id = data.mongodbatlas_privatelink_endpoint.this.private_link_id
endpoint_service_id = aws_vpc_endpoint.this.id
provider_name = "AWS"
}
18 changes: 18 additions & 0 deletions project.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
data "ns_connection" "atlas-project" {
name = "atlas-project"
contract = "network/aws/mongo:atlas"
}

locals {
atlas_project_id = data.ns_connection.atlas-project.outputs.project_id
private_link_id = data.ns_connection.atlas-project.outputs.private_link_id
atlas_public_key_secret_id = data.ns_connection.atlas-project.outputs.atlas_public_key_secret_id
atlas_private_key_secret_id = data.ns_connection.atlas-project.outputs.atlas_private_key_secret_id
}

data "aws_secretsmanager_secret_version" "atlas_public_key" {
secret_id = local.atlas_public_key_secret_id
}
data "aws_secretsmanager_secret_version" "atlas_private_key" {
secret_id = local.atlas_private_key_secret_id
}
17 changes: 0 additions & 17 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
variable "atlas_public_key" {
type = string
sensitive = true
description = "The public key used to authenticate to your MongoDB Atlas account"
}

variable "atlas_private_key" {
type = string
sensitive = true
description = "The private key used to authenticate to your MongoDB Atlas account"
}

variable "atlas_project_id" {
type = string
description = "The ID of the Atlas project to create the cluster in"
}

variable "mongodb_major_version" {
type = string
default = "6"
Expand Down