TestDrive Terraform system to learn about the advantages of Infrastructure as Code (IaC)
Promising aspects of the Terraform tool:
- options to define computing infrastructure in human and machine-readable code
- transparency and flexibility through open source
- no vendor lock-in for cloud service provider
following the tutorial: https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started
-
I used a test machine under Ubuntu 20.04 with already installed docker engine
-
Ensure that system is up to date, and required packages installed (in my case all already at the newest version :)
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
-
Add the HashiCorp GPG key
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
-
Add the official HashiCorp Linux repository (-> deactivate after test ...)
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
-
install the Terraform CLI
sudo apt-get update && sudo apt-get install terraform
-
Verify that the installation worked by listing Terraform's available subcommands
terraform -help
-
install the autocomplete package
terraform -install-autocomplete
-
you may want to become a user dedicated to manage docker as non-root user
in my case I created earlier a user docker (https://askubuntu.com/questions/477551/how-can-i-use-docker-without-sudo)
su docker
change into the home directory of this user
cd ~/
-
clone this repo containing the Terraform configuration file
main.tf
git clone [email protected]:schmidchr/TestDrive-Terraform.git
-
change into the directory containing the configuration file
cd learn-terraform-docker-container
-
Initialize the project, which downloads a plugin that allows Terraform to interact with Docker
terraform init
-
Provision the NGINX server container. When Terraform asks you to confirm type yes and press ENTER
terraform apply
-
verify the existence of the NGINX container by visiting
http://localhost:8000/
- to clean up, stop the container
terraform destroy