Terraform: quickstart
The basic cycle for deploying infrastructure: init, plan, then apply.
1. Initialize
Downloads the providers and configures the backend. Run it once, then again after every provider or backend change.
terraform init2. Plan
Computes the changes to apply without modifying anything. The plan file guarantees that what gets applied is exactly what was reviewed.
terraform plan -out=tfplan3. Deploy
Applies the saved plan.
terraform apply tfplanTerraform has no deploy command: apply is what deploys.
Example configuration
terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 6.0" } }}
provider "aws" { region = "eu-west-3"}
resource "aws_s3_bucket" "docs" { bucket = "my-docs-bucket"}Export and read the plan
Optional, outside the basic cycle. The tfplan file is binary: use terraform show to display it in a human-readable format.
terraform show tfplanAdd -no-color to get plain text, for example to paste it in a merge request or a log.
terraform show -no-color tfplan > plan.txtExport as JSON
For tooling and automation, export the plan in a machine-readable format.
terraform show -json tfplan > plan.jsonThen use jq to extract what matters, such as one line per resource with its planned actions.
jq -r '.resource_changes[] | select(.change.actions != ["no-op"]) | "\(.change.actions | join(",")) \(.address)"' plan.jsonThe plan can contain sensitive values in clear text. Do not commit tfplan or plan.json.
Destroy
terraform destroy