This project contains a basic terraform definition for an NGINX web server, provisioned an accounts default VPC allowing HTTP traffic from anywhere.
The following variables are required to provision the server:
aws_region
- The AWS region to provision the server in, defaults tous-east-1
instance_type
- EC2 instance type, defaults tot3.micro
ami
The Amazon Machine Image ID to use when provisioning the server.
- Configure your ami in the
terraform.tfvars
file - Run
terraform init
- Run
terraform apply
- Visit the
server_url
output from provisioning (note: The user script may take a short while to finish installation)
The terraform definition provisions an EC2 instance in the default VPC for the account, using the specified AMI and instance type. The instance is provisioned with a user data script that installs nginx and starts the service.
- Using the default VPC is not recommended for production environments, in an actual environment it would be better to provision a bespoke VPC that only accepts traffic for the intended purposes.
- This approach does not allow access to the server using SSH. In an actual environment it would be better to allow SSH access via a bastion host or VPN connection, allowing for maintenance activities.
- By provisioning with Terraform, it is more difficult for us to verify the nginx installation was successfully completed, whereas using CloudFormation we could make use of
cfn-signal