This example provision mongodb server in a given VPC and in a private subnet.
- Configure AWS Credentials as environment variables:
export AWS_ACCESS_KEY_ID="ACCESS_KEY_HERE"
export AWS_SECRET_ACCESS_KEY="SECRET_ACCESS_KEY_HERE"
export AWS_DEFAULT_REGION="REGION_HERE"
- If you don't have any existing EBS volume, Bastion Host then create EBS volume, Bastion Host in a new VPC using terraform script in prerequisite.
cd terraform-mongodb-provisioning-ec2/examples/mongodb-in-private-subnet/prerequisite
terraform init
terraform plan
terraform apply
- Provision MongoDB:
Configure the existing/created
ebs_volume_id
(s) and availability_zone
(s) asdata_volumes
variable inmongodb-in-private-subnet/main.tf
.
Instead of changing the variable values in
main.tf
you can renameterraform.tfvars.sample
toterraform.tfvars
and provide input values.
variable "data_volumes" {
type = list(object({
ebs_volume_id = string
availability_zone = string
}))
description = "List of EBS volumes"
default = [
{
ebs_volume_id = "EBS_VOLUME_ID_HERE"
availability_zone = "AZ_HERE"
},
{
ebs_volume_id = "EBS_VOLUME_ID_HERE"
availability_zone = "AZ_HERE"
}
]
}
Now you can provision MongoDB as follows:
cd terraform-mongodb-provisioning-ec2/examples/mongodb-in-private-subnet
terraform init
terraform plan
terraform apply
- Destroy:
cd terraform-mongodb-provisioning-ec2/examples/mongodb-in-private-subnet
terraform destroy