DEV Community

Cover image for πŸš€ Deploying Sonatype Nexus on AWS EC2 using Terraform
Himanshu Singh Tomar
Himanshu Singh Tomar

Posted on

πŸš€ Deploying Sonatype Nexus on AWS EC2 using Terraform

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

4. βœ… Validate the Configuration

Make sure everything is correct:

terraform validate
Enter fullscreen mode Exit fullscreen mode

5. πŸ” Preview the Deployment

Check what Terraform is going to create:

terraform plan
Enter fullscreen mode Exit fullscreen mode

6. πŸš€ Apply the Terraform Plan

Create the resources:

terraform apply
Enter fullscreen mode Exit fullscreen mode

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 = <YOUR_PUBLIC_IP>
Enter fullscreen mode Exit fullscreen mode

You can then open your browser and access Nexus:

http://<YOUR_PUBLIC_IP>:8081
Enter fullscreen mode Exit fullscreen mode

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

sudo cat /opt/sonatype-work/nexus3/admin.password
Enter fullscreen mode Exit fullscreen mode

🧹 Optional: Destroy the Infrastructure

To delete the resources when you're done:

terraform destroy
Enter fullscreen mode Exit fullscreen mode

Happy DevOpsing! πŸŽ‰

Top comments (0)