Installation
Terraform Installation for Ubuntu 22.04 (My Personal Machine)
Resources Used: Terraform Docs
sudo apt update && sudo apt install -y gnupg software-properties-common curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt update && sudo apt install terraform
Verify Installation
terraform -help
Start and Destroy Nginx server per tutorial
mkdir terraform-container
cd terraform-container
Create new file called main.tf
and add the following code:
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 2.13.0"
}
}
}
provider "docker" {}
resource "docker_image" "nginx" {
name = "nginx:latest"
keep_locally = false
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "tutorial"
ports {
internal = 80
external = 8000
}
}
initialize project with terraform init
terraform init
terraform apply
Validation
Check localhost:8000 in your browser to verify the nginx server is up and running
Remove Container and Shutdown Nginx Server
terraform destroy