Skip to content

Terraform module to manage MongoDB Atlas Project and VPC peering between MongoDB Atlas and AWS

License

Notifications You must be signed in to change notification settings

tx-pts-dai/terraform-aws-mongodbatlas

Repository files navigation

MongoDB Atlas made easy

Easy way to setup an Atlas MongoDB project with its network peering with an AWS account.

Core concepts

This Module covers the use case of managing:

  • a MongoDB Atlas project
  • it's network peering with an AWS account

Usage

locals {
  # Mongdb Atlas IDs can be found by checking the URL when navigating
  # the web console https://cloud.mongodb.com.
  # ORG_ID = part after `/orgs/` on the home page
  # TEAM_ID  = part after the `/teams/` when checking Team's details
  mongodb_atlas_org_id = "24_hexchar"

  # List of AWS private subnet IDs to peer to
  private_subnets = ["subnet-17_hexchar", "subnet-17_hexchar", "..."]

  # Name you wantn to have for your Atlas MongoDB Project
  project_name = "Module Sandbox"

  # Teams you want to allow using the VPC
  # See TEAM_ID above
  teams_ids = [
    { team_id = TEAM_ID1, team_role = ["GROUP_OWNER"] },
    { team_id = TEAM_ID2, team_role = ["GROUP_DATA_ACCESS_READ_ONLY"] },
  ]

  # AWS VPC ID
  vpc_idf = "vpc-17_hexchar"

  # List of AWS NAT Gateway public IPs
  vpc_public_ips = ["1.1.1.1", "1.2.2.1", "..."]
}

module "mongodb" {
  source  = "tx-pts-dai/mongodbatlas/aws"
  version = "v0.0.1"

  atlas_cidr_block      = "10.8.0.0/21"
  aws_region            = "eu-central-1"
  create_vpc_peering    = true
  mongodb_atlas_org_id  = local.mongodb_atlas_org_id
  override_peering_cidr = null
  private_subnets       = local.private_subnets
  project_name          = local.project_name
  provider_name         = "AWS"
  team_ids              = local.teams_ids
  vpc_id                = local.vpc_id
  vpc_public_ips        = local.vpc_public_ips
}

Will manage the following resources:

  • An MongoDB Atlas Project
  • MongoDB Atlas IP Access Lists
  • MongoDB Atlas Network Container
  • MongoDB Atlas Network Peering
  • AWS VPC Peering Accepter
  • AWS Route

Contributing

< issues and contribution guidelines for public modules >

Pre-Commit

Installation: install pre-commit and execute pre-commit install. This will generate pre-commit hooks according to the config in .pre-commit-config.yaml

Before submitting a PR be sure to have used the pre-commit hooks or run: pre-commit run -a

The pre-commit command will run:

  • Terraform fmt
  • Terraform validate
  • Terraform docs
  • Terraform validate with tflint
  • check for merge conflicts
  • fix end of files

as described in the .pre-commit-config.yaml file

Requirements

Name Version
terraform >=1.1
aws >= 4.0
mongodbatlas >= 1.0

Providers

Name Version
aws >= 4.0
mongodbatlas >= 1.0

Modules

No modules.

Resources

Name Type
aws_route.atlas_route resource
aws_security_group.this resource
aws_vpc_endpoint.this resource
aws_vpc_peering_connection_accepter.atlas resource
mongodbatlas_network_container.container resource
mongodbatlas_network_peering.peering resource
mongodbatlas_privatelink_endpoint.this resource
mongodbatlas_privatelink_endpoint_service.this resource
mongodbatlas_project.project resource
mongodbatlas_project_ip_access_list.additional_cidr resource
mongodbatlas_project_ip_access_list.public_ips resource
mongodbatlas_project_ip_access_list.vpc resource
aws_caller_identity.current data source
aws_route_tables.private_routing_tables data source
aws_vpc.this data source
mongodbatlas_project.this data source

Inputs

Name Description Type Default Required
atlas_cidr_block CIDR block for MongoDB resources string "10.8.0.0/21" no
aws_region Region for AWS and for Mongodb resources string n/a yes
create_privatelink Create a PrivateLink Connection if set to True for instances that are M10 size or higher bool false no
create_project Create a project on Atlas if set to True bool true no
create_vpc_peering Create a Vpc Peering Connection if set to True for instances that are M10 size or higher bool n/a yes
mongodb_atlas_org_id ID of the Organization on Atlas string n/a yes
override_peering_cidr Manually overrides the network peering cidr block string null no
private_subnets AWS private subnet ids which can connect to the db and which enable HA list(string) n/a yes
project_name Name of the Mongodb project string n/a yes
provider_name Provider name for Atlas Mongodb resources string "AWS" no
team_ids Id of the infra team of the Organization on Atlas
list(object({
team_id = string
team_role = list(string)
}))
[] no
vpc_id VPC of Atlas MongoDB resources string n/a yes
vpc_public_ips List of public IP addresses of the VPC list(string) [] no

Outputs

Name Description
peering_id Network peering
private_link_endpoint Private link
project_id Mongodb project id
region_name Mongodb region name

Authors

Module is maintained by Alfredo Gottardo, David Beauvererd, Davide Cammarata, Demetrio Carrara and Roland Bapst

License

Apache 2 Licensed. See LICENSE for full details.

About

Terraform module to manage MongoDB Atlas Project and VPC peering between MongoDB Atlas and AWS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages