A repo to demo the different Terraform CLI commands
main.tf
variables.rf
terraform.tfvars
outputs.tf
- Lock file creation
- tree structure with
.terraform
folder with providers and modules - The
-upgrade
flag. Upgrade thekreuzwerker/docker
provider to3.0.1
- Show a successful output
- Comment out the
docker_image
resource inmain.tf
to show a failed output
- Show the changes that are about to happen
- Discuss the
-out
flag
- Show the plan and the prompt
- Show the NGINX welcome page
- Run
docker ps
- Talk about the
-auto-approve
flag - Show the state file created
- Show the plan and the prompt
- Discuss the
-auto-approve
flag - Discuss the alternative to run
terraform apply -destroy
- Show the state file
- First show the
terraform state list
command - Try these commands:
- var.image_name
- "${var.image_name}:${var.image_tag}"
- docker_image.nginx_image
- Break the formatting in some of the files and run the command
- Run:
terraform taint docker_container.nginx_container
- Warning: This command is deprecated. The recommendation is to use the
-replace
option with terraform plan and apply instead. Using the-replace
option gives you more visibility into the impact of the change before you apply it. With taint, you risk having another person run a new plan on your tainted object without your knowledge of the outcomes. - Run
terraform plan -replace docker_container.nginx_container
- Run
terraform apply -replace docker_container.nginx_container
- The terraform workspace command is used to manage workspaces. Workspaces are named containers for Terraform state that allow you to isolate and switch between different configurations and environments.
- Run
terraform workspace list
- Run
terraform workspace new dev
- Run
terraform workspace new prod
- Run
terraform workspace list
- Make sure no containers exist otherwise run
terraform destroy
- Run the following:
terraform workspace select dev
terraform init
terraform apply -auto-approve
terraform workspace select prod
terraform init
terraform apply -auto-approve
- Notice the file structure
- Run
docker ps
to see the container names and the external ports