File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -3,5 +3,5 @@ aws_region = "us-west-2"
33instance_type = " t3.large"
44key_name = " ashish-test-kp"
55vpc_id = " vpc-0c4669393c94b8f86"
6- ami_id = " ami-001fbc42d7df13f78 "
6+ ami_id = " ami-075b5421f670d735c " # Amazon Linux 2023
77root_volume_size = 20
Original file line number Diff line number Diff line change @@ -3,5 +3,5 @@ aws_region = "us-west-2"
33instance_type = " t3.small"
44key_name = " ashish-test-kp"
55vpc_id = " vpc-0c4669393c94b8f86"
6- ami_id = " ami-001fbc42d7df13f78 "
6+ ami_id = " ami-075b5421f670d735c " # Amazon Linux 2023
77root_volume_size = 10
You can’t perform that action at this time.
0 commit comments