This guide will walk you through the steps to deploy a Nexus Repository Manager on an AWS EC2 instance using a Terraform script.


📁 Prerequisites

Make sure you have the following installed:

  • Terraform
  • AWS CLI
  • An AWS account with credentials configured (via aws configure)
  • A valid SSH key pair created in your AWS account (needed to access EC2)

📄 Step-by-Step Instructions

1. 🔑 Update Your Key Pair Name

In the aws_instance block, replace:

key_name = "your-ssh-key"

with the actual name of your AWS EC2 key pair.


2. 📦 Save the Terraform Code

Save the entire provided Terraform code into a file named main.tf in a directory of your choice.


3. 📂 Initialize Terraform

Open a terminal, navigate to the directory containing [main.tf](https://github.com/Himanshusinghtomar/Sontype-Nexus/blob/main/sontype-nexus-aws-setup.tf), and run:

terraform init

4. ✅ Validate the Configuration

Make sure everything is correct:

terraform validate

5. 🔍 Preview the Deployment

Check what Terraform is going to create:

terraform plan

6. 🚀 Apply the Terraform Plan

Create the resources:

terraform apply

Type yes when prompted to proceed.


7. 🌐 Access Nexus

Once the infrastructure is deployed, Terraform will output the public IP of the EC2 instance:

nexus_public_ip =

You can then open your browser and access Nexus:

http://:8081

The default admin password will be available in the instance at:

sudo cat /opt/sonatype-work/nexus3/admin.password

🧹 Optional: Destroy the Infrastructure

To delete the resources when you're done:

terraform destroy

Happy DevOpsing! 🎉