Skip to content
Merged
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
31 changes: 31 additions & 0 deletions terraform/modules/ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,37 @@ resource "aws_instance" "mongodb" {
volume_type = "gp3"
}

user_data = <<-EOF
#!/bin/bash
set -e

# Update system
yum update -y

# Add MongoDB repository
cat > /etc/yum.repos.d/mongodb-org-7.0.repo <<'REPO'
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-7.0.asc
REPO

# Install MongoDB
yum install -y mongodb-org

# Configure MongoDB to listen on all interfaces
sed -i 's/bindIp: 127.0.0.1/bindIp: 0.0.0.0/' /etc/mongod.conf

# Start and enable MongoDB
systemctl start mongod
systemctl enable mongod

# Log completion
echo "MongoDB installation completed" > /var/log/mongodb-install.log
EOF

tags = {
Name = "MongoDB-${var.environment}"
Environment = var.environment
Expand Down
2 changes: 1 addition & 1 deletion terraform/stacks/production/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ aws_region = "us-west-2"
instance_type = "t3.large"
key_name = "ashish-test-kp"
vpc_id = "vpc-0c4669393c94b8f86"
ami_id = "ami-001fbc42d7df13f78"
ami_id = "ami-075b5421f670d735c" # Amazon Linux 2023
root_volume_size = 20
2 changes: 1 addition & 1 deletion terraform/stacks/staging/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ aws_region = "us-west-2"
instance_type = "t3.small"
key_name = "ashish-test-kp"
vpc_id = "vpc-0c4669393c94b8f86"
ami_id = "ami-001fbc42d7df13f78"
ami_id = "ami-075b5421f670d735c" # Amazon Linux 2023
root_volume_size = 10