Skip to content

A script to deploy infrastructure across AWS and MongoDB Atlas using Terraform

Notifications You must be signed in to change notification settings

cbaird-1337/aws-atlas-terraform

Repository files navigation

Deploying AWS and MongoDB Atlas Resources with Terraform

This script provides a simple example of deploying infrastructure as code using Terraform.

Dependencies

  • Terraform v0.12
  • An AWS account - provider.aws: version = "~> 2.39"
  • A MongoDB Atlas account - provider.mongodbatlas: version = "~> 0.3"

Usage

1. Ensure your AWS credentials are set up.

This can be done using environment variables:

$ export AWS_SECRET_ACCESS_KEY='your secret key'
$ export AWS_ACCESS_KEY_ID='your key id'

... or the ~/.aws/credentials file.

$ cat ~/.aws/credentials
[default]
aws_access_key_id = your key id
aws_secret_access_key = your secret key

... or follow as in the variables.tf file and create terraform.tfvars file with all the variable values and make sure not to commit it.

2. Review the Terraform plan.

Execute the below command and ensure you are happy with the plan.

$ terraform plan

This project currently does the below deployments:

  • MongoDB cluster - M10
  • MongoDB User (Pass the values when asked)
  • AWS Custom VPC, Internet Gateway, Route Tables, Subnets with Public and Private access and appropriate resource tags
  • AWS-MongoDB Atlas VPC Peering
  • An optional (commented out) script to deploy an EC2 instance

3. Execute the Terraform apply.

Now execute the plan to provision the AWS resources.

$ terraform apply

4. Destroy the resources.

Once you are finished your testing, ensure you destroy the resources to avoid unnecessary AWS charges.

$ terraform destroy

About

A script to deploy infrastructure across AWS and MongoDB Atlas using Terraform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages