Skip to content

Commit 6495862

Browse files
Merge pull request #3 from CloudNinjaDev/infra
Add user data script for MongoDB installation and update AMI ID for p…
2 parents 6e30089 + 7489ff5 commit 6495862

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

terraform/modules/ec2/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,37 @@ resource "aws_instance" "mongodb" {
4545
volume_type = "gp3"
4646
}
4747

48+
user_data = <<-EOF
49+
#!/bin/bash
50+
set -e
51+
52+
# Update system
53+
yum update -y
54+
55+
# Add MongoDB repository
56+
cat > /etc/yum.repos.d/mongodb-org-7.0.repo <<'REPO'
57+
[mongodb-org-7.0]
58+
name=MongoDB Repository
59+
baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/7.0/x86_64/
60+
gpgcheck=1
61+
enabled=1
62+
gpgkey=https://pgp.mongodb.com/server-7.0.asc
63+
REPO
64+
65+
# Install MongoDB
66+
yum install -y mongodb-org
67+
68+
# Configure MongoDB to listen on all interfaces
69+
sed -i 's/bindIp: 127.0.0.1/bindIp: 0.0.0.0/' /etc/mongod.conf
70+
71+
# Start and enable MongoDB
72+
systemctl start mongod
73+
systemctl enable mongod
74+
75+
# Log completion
76+
echo "MongoDB installation completed" > /var/log/mongodb-install.log
77+
EOF
78+
4879
tags = {
4980
Name = "MongoDB-${var.environment}"
5081
Environment = var.environment

terraform/stacks/production/terraform.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ aws_region = "us-west-2"
33
instance_type = "t3.large"
44
key_name = "ashish-test-kp"
55
vpc_id = "vpc-0c4669393c94b8f86"
6-
ami_id = "ami-001fbc42d7df13f78"
6+
ami_id = "ami-075b5421f670d735c" # Amazon Linux 2023
77
root_volume_size = 20

terraform/stacks/staging/terraform.tfvars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ aws_region = "us-west-2"
33
instance_type = "t3.small"
44
key_name = "ashish-test-kp"
55
vpc_id = "vpc-0c4669393c94b8f86"
6-
ami_id = "ami-001fbc42d7df13f78"
6+
ami_id = "ami-075b5421f670d735c" # Amazon Linux 2023
77
root_volume_size = 10

0 commit comments

Comments
 (0)