title, description, category, tags, resources
| title | description | category | tags | resources | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Nginx Web Server | Deploy a VPC with a public subnet and an EC2 instance running Nginx using Terraform on Spinifex. | Terraform Workbooks |
|
|
Terraform: Nginx Web Server
Deploy a VPC with a public subnet and an EC2 instance running Nginx using Terraform on Spinifex.
Table of Contents
Overview
Deploy a complete Nginx web server on Spinifex using Terraform/OpenTofu. This workbook provisions a VPC, public subnet, internet gateway, route table, security group, SSH key pair, and an EC2 instance with cloud-init user-data that installs and starts Nginx.
What you'll learn:
- Configuring the AWS Terraform provider to target Spinifex
- Creating a VPC with public internet access
- Provisioning an EC2 instance with cloud-init user-data
- Generating SSH key pairs with the TLS provider
Prerequisites:
- Spinifex installed and running (see Installing Spinifex)
- A Debian 12 AMI imported (see Setting Up Your Cluster)
- OpenTofu or Terraform installed
AWS_PROFILE=spinifexconfigured
Instructions
Step 1. Get the Template
Clone the Terraform examples from the Spinifex repository:
git clone --depth 1 --filter=blob:none --sparse https://github.com/mulgadc/spinifex.git spinifex-tf
cd spinifex-tf
git sparse-checkout set docs/terraform
cd docs/terraform/nginx-webserver
Or create a main.tf file and paste the full configuration below.
Step 2. Deploy
export AWS_PROFILE=spinifex
tofu init
tofu apply
Step 3. Verify
Note: EC2 instances can take 30+ seconds to boot after apply. If SSH or HTTP is unreachable, wait and retry.
After apply completes, use the outputs to test:
curl http://<public_ip>
ssh -i nginx-demo.pem ec2-user@<public_ip>
Open the web_url output in your browser to see the Nginx welcome page.
Clean Up
tofu destroy
Troubleshooting
AMI Not Found
Ensure you have imported a Debian 12 image. Check available AMIs:
aws ec2 describe-images --owners 000000000000 --profile spinifex
Provider Connection Refused
Verify Spinifex services are running:
sudo systemctl status spinifex.target
curl -k https://localhost:9999/
SSH Connection Timeout
Check that the security group allows inbound SSH (port 22) and that the instance has a public IP assigned. Verify the instance is running:
aws ec2 describe-instances --profile spinifex
Nginx Not Responding
SSH into the instance and check cloud-init logs:
ssh -i nginx-demo.pem ec2-user@<public_ip>
sudo journalctl -u cloud-init --no-pager
sudo systemctl status nginx