Terraform - kimschles/schlesinger-knowledge GitHub Wiki
Terraform is used to create and change infrastructure resources like physical servers, VMs, containers, etc.
Terraform generates configuration files with the following extensions: .tf
, .tfplan
, tfstate
.
1
Glossary
- provider: Infrastructure software like Kuberenetes, Chef, AWS, GCP
- From the docs: "A Provider is the logical abstraction of an upstream API"
- resources: A component of your infrastructure like an image or container
terraform
shows the most commonly used commands
A common workflow
terraform init
terraform plan -out config.tfplan
- Compares your prior state with the changes you've made
+
indicates the new resources that have been created- Nothing is run, but a summary of changes is created
- The changes show in the command line and in the
config.tfplan
file
terraform apply
- Does the things
- Generates or changes the
terraform.tfstate
file - Pulls images and launches containers, etc.
terraform show
Import
- Use
import
when you are importing existing resources that were created without terraform (the AWS Console, GCP, etc), and bring it under management by Terraformterraform import
- If you have an s3 bucket, you will declare that information in another file like
backend.tf
Tainting a Resource
- When you 'taint' a resource, you force it to be destroyed and recreated on the next apply
terraform taint aws_security_group.allow_all