liveBook · Manning

Terraform apply

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

terraform apply is the Terraform command that compares configuration with recorded state and applies the required infrastructure changes.

terraform apply executes the Terraform configuration in a project and creates or updates infrastructure in the cloud. Terraform generates an execution plan, shows the resources it will add, change, or destroy, and normally waits for an explicit yes before continuing. section 7.8.6 section 7.16

A practical apply workflow is:

  • Initialize the Terraform project with terraform init before executing it. section 7.8.9
  • Run terraform apply from the directory containing the Terraform files. section 7.8.6
  • Review the proposed changes and enter yes to approve them. section 7.8.6
  • Use terraform apply again after changing configuration; repeated applies support incremental infrastructure development. section 7.8.8
  • Use -auto-approve for unattended execution, such as an automated deployment pipeline. section 7.9.2

Creating and rebuilding infrastructure

A first terraform apply creates an Azure resource group and reports a result such as “Apply complete! Resources: 1 added, 0 changed, 0 destroyed.” After adding a container registry, terraform apply -auto-approve applies the linked resources in dependency order. For practice or cleanup, terraform destroy removes the managed infrastructure, after which terraform apply recreates it. section 7.8.6 section 7.9.2 section 7.8.8

Terraform used the selected providers to generate the following 
execution plan. Resource actions are indicated with the
following symbols:
  + create
 
Terraform will perform the following actions:
 
  # azurerm_resource_group.flixtube will be created
  + resource "azurerm_resource_group" "flixtube" {
      + id       = (known after apply)
      + location = "eastus"
      + name     = "flixtube"
    }
 
Plan: 1 to add, 0 to change, 0 to destroy.
 
Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.
 
  Enter a value:

Inspect a representative execution plan showing a resource addition, the approval prompt, and the planned resource count. section 7.8.6

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Explains plan generation, approval, completion output, auto-approval, dependencies, and repeated application, but not command internals.
Examples
Demonstrates Azure resource groups, container registries, Kubernetes clusters, approval prompts, and destroy-and-recreate experiments.
What it assumes
Assumes Terraform configuration and provider setup, and teaches project initialization, plan approval, variables, and incremental execution.
What you can do after
Operate Terraform to review and approve infrastructure changes, automate applies, and rebuild cloud resources from configuration.
How it connects
Connects Terraform apply with Terraform plan, terraform init, terraform destroy, Terraform state, infrastructure as code, and resource graphs.

Also explained in

Compare how 2 books explain terraform apply →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.