This project deploys a static dice game web app with Terraform and Docker. Terraform builds an Nginx-based image from the local site files and runs it as a container.
The app is a simple two-dice roller served as static assets.
Features:
- Roll two dice and display each value.
- Display running total (
Total: X). - Accessible UI with labeled controls and live-updating total.
- Responsive layout for mobile and desktop viewports.
Key files:
image/site/index.html: Semantic markup and accessibility attributes.image/site/styles.css: Visual styles and responsive behavior.image/site/app.js: Dice roll logic, initialization, and DOM safety checks.image/Dockerfile: Nginx image definition and static-file permission hardening.main.tf: Terraform resources for image build, network, and container runtime.
Install the following on your machine:
- Docker Engine (daemon running)
- Terraform >= 1.6.0
Verify:
docker --version
terraform --version.
├── image/
│ ├── Dockerfile
│ └── site/
│ ├── app.js
│ ├── index.html
│ └── styles.css
├── main.tf
└── README.md
From the project root:
- Initialize Terraform providers:
terraform init- Validate configuration:
terraform validate- Preview what will be created:
terraform plan- Build and start the application:
terraform applyWhen prompted, type yes.
- Open the app:
http://localhost:8080/
Terraform outputs include:
url: local endpointimage_built: built image name and tagcontainer_id: running container ID
You can override defaults at apply time:
terraform apply \
-var='host_port=9090' \
-var='image_name=my-dice-app' \
-var='image_tag=v1.2'Then open http://localhost:9090/.
Destroy all Terraform-managed Docker resources:
terraform destroyAfter startup, verify from terminal:
curl -I http://localhost:8080/Expected result includes HTTP/1.1 200 OK.
- Docker connection errors: Ensure Docker daemon is running and your user can access it.
- Port already in use:
Use a different
host_portvariable value. - Terraform provider issues:
Re-run
terraform init -upgrade.
- Terraform state files are ignored by
.gitignoreand should not be committed. - Image rebuilds are triggered when files in
image/site/change via a Terraform content hash.