From bacce6ddf3b01def46c8d6fc1de0bbe061ede4ea Mon Sep 17 00:00:00 2001 From: CloudNinjaDev Date: Mon, 2 Mar 2026 18:09:53 +0530 Subject: [PATCH 1/2] Add user data script for MongoDB installation and update AMI ID for production and staging environments --- terraform/modules/ec2/main.tf | 31 ++++++++++++++++++++ terraform/stacks/production/terraform.tfvars | 2 +- terraform/stacks/staging/terraform.tfvars | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf index 6ba3433..2e47067 100644 --- a/terraform/modules/ec2/main.tf +++ b/terraform/modules/ec2/main.tf @@ -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 diff --git a/terraform/stacks/production/terraform.tfvars b/terraform/stacks/production/terraform.tfvars index 391204e..1148dfc 100644 --- a/terraform/stacks/production/terraform.tfvars +++ b/terraform/stacks/production/terraform.tfvars @@ -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 diff --git a/terraform/stacks/staging/terraform.tfvars b/terraform/stacks/staging/terraform.tfvars index f5e015d..0459b98 100644 --- a/terraform/stacks/staging/terraform.tfvars +++ b/terraform/stacks/staging/terraform.tfvars @@ -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 From 7489ff5d26dae0f08825c4e50e7c0a680aaf7386 Mon Sep 17 00:00:00 2001 From: CloudNinjaDev Date: Mon, 2 Mar 2026 18:11:32 +0530 Subject: [PATCH 2/2] Fix formatting of AMI ID comments in Terraform variable files for production and staging environments --- terraform/stacks/production/terraform.tfvars | 2 +- terraform/stacks/staging/terraform.tfvars | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/terraform/stacks/production/terraform.tfvars b/terraform/stacks/production/terraform.tfvars index 1148dfc..676039a 100644 --- a/terraform/stacks/production/terraform.tfvars +++ b/terraform/stacks/production/terraform.tfvars @@ -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-075b5421f670d735c" # Amazon Linux 2023 +ami_id = "ami-075b5421f670d735c" # Amazon Linux 2023 root_volume_size = 20 diff --git a/terraform/stacks/staging/terraform.tfvars b/terraform/stacks/staging/terraform.tfvars index 0459b98..f2f6dfe 100644 --- a/terraform/stacks/staging/terraform.tfvars +++ b/terraform/stacks/staging/terraform.tfvars @@ -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-075b5421f670d735c" # Amazon Linux 2023 +ami_id = "ami-075b5421f670d735c" # Amazon Linux 2023 root_volume_size = 10