Skip to content

Instantly share code, notes, and snippets.

@pizofreude
Last active April 17, 2025 17:31
Show Gist options
  • Save pizofreude/df82d35cb02088aecd5bd1008b62f2f1 to your computer and use it in GitHub Desktop.
Save pizofreude/df82d35cb02088aecd5bd1008b62f2f1 to your computer and use it in GitHub Desktop.
All things Terraform commands

terraform init

Consider that under terraform folder, there are dev/ prod/ global/. So how many times do we need to run terraform init ?

Answer

Based on the transcript, you have the following folders under your terraform folder:

  • dev/
  • prod/
  • global/

You also have a V2 folder that represents a single Git repository, which contains subfolders for environments (dev, prod, global) and modules.

To answer your question, you would need to run terraform init in each environment folder (dev, prod, global) because each environment folder has its own Terraform state file.

However, in the V2 folder, you have a more advanced structure where each module is in its own Git repository. In this case, you would need to run terraform init in each environment folder (dev, prod, global) as well as in each module repository.

So, in total, you would need to run terraform init at least 5 times:

  • 3 times in the environment folders (dev, prod, global)
  • 2 times in the module repositories (VPC and subnet)

But, if you have more modules, the number of terraform init commands would increase accordingly.

@pizofreude
Copy link
Author

pizofreude commented Apr 17, 2025

Common Terraform Execution Steps

  1. terraform init:
    • Initializes & configures the backend, installs plugins/providers, & checks out an existing configuration from a version control
  2. terraform plan:
    • Matches/previews local changes against a remote state, and proposes an Execution Plan.
  3. terraform apply:
    • Asks for approval to the proposed plan, and applies changes to cloud
  4. terraform destroy
    • Removes your stack from the Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment