Difficulty: Beginner
Estimated Time: 1

Terraform in 60 Seconds

Learn to use Terraform to provision an Nginx web server within Docker.

In 60 seconds, you'll use Terraform to apply, change, and destroy a live webserver.

Let's get started!

Terraform in 60 Seconds

Learn more about Terraform and the rich ecosystem of providers at HashiCorp Learn

Terraform Tutorial

Terraform in 60 Seconds

A Terraform configuration is a series of code blocks that define your intended infrastructure. You'll run the terraform command against this file to create an Nginx webserver and view the default Nginx web page.

View code

First, open the main.tf file in the text editor by clicking this link.


You don't have to edit or even understand the code. It defines two resources: a Docker disk image that packages the Nginx webserver, and a Docker container that gives it a name and runs it on port 80.


All Terraform workflows start with the init command. Terraform searches the configuration for both direct and indirect references to providers (such as Docker). Terraform then attempts to load the required plugins.

terraform init


Now provision the webserver by running apply.

terraform apply

You will be asked to confirm. Type yes and press ENTER. It may take up to 30 seconds. A message will display confirmation that it succeeded.


Visit this URL to view the default Nginx web page which is now live:

Alternatively, you can examine Docker's process list. You will see the tutorial container which is running Nginx.

docker ps


To remove the Nginx webserver as defined in main.tf, run the destroy command.

terraform destroy

You will be prompted to confirm. Type yes and press ENTER.


You have now created and destroyed your first Terraform resources! Terraform supports hundreds of ecosystem providers, from major cloud resources to content delivery networks and more.

Continue learning at HashiCorp Learn and the Terraform API documentation or discuss with others on the Terraform forum.