Skip to content

Instantly share code, notes, and snippets.

@pizofreude
Created April 17, 2025 17:10
Show Gist options
  • Save pizofreude/1d77dc0a217d175fa195988e62b0146e to your computer and use it in GitHub Desktop.
Save pizofreude/1d77dc0a217d175fa195988e62b0146e to your computer and use it in GitHub Desktop.
Terraform Code Artifacts and Descriptions

Terraform Code Artifacts and Descriptions

  • providers.tf
    Description: The providers.tf file is used to configure and declare provider settings in Terraform. Providers enable Terraform to interact with cloud platforms (e.g., AWS, Azure, GCP) or other services. This file specifies provider versions, regions, and authentication methods.

  • variables.tf
    Description: The variables.tf file defines input variables for Terraform configurations. These variables allow parameterization of values like resource names, regions, or instance types, making configurations more reusable and dynamic.

  • outputs.tf
    Description: The outputs.tf file is used to expose the results of a Terraform run. It outputs values, such as IP addresses, URLs, or resource attributes, for use by other configurations, tools, or workflows.

  • main.tf
    Description: The main.tf file serves as the core configuration file in Terraform. It typically contains the main resource definitions and logic for creating and managing infrastructure resources.

  • terraform.tfvars
    Description: The terraform.tfvars file is used to define variable values for Terraform configurations. By separating variable values from the configuration files, it allows for better management and flexibility across different environments.

  • backend.tf
    Description: The backend.tf file configures the backend for Terraform's state management. It specifies where the state file is stored, such as in an S3 bucket or a local file, ensuring proper tracking and collaboration.

  • data.tf
    Description: The data.tf file is used to define data sources in Terraform. Data sources allow Terraform to fetch or reference existing resources without creating new ones, enabling integration with pre-existing infrastructure.

  • locals.tf
    Description: The locals.tf file is used to define local values that simplify and group expressions in Terraform. These local values are reusable throughout the configuration for better readability and maintainability.

  • modules/
    Description: The modules/ directory contains reusable modules in Terraform. Modules encapsulate groups of resources and logic, enabling modular, DRY (Don't Repeat Yourself) practices for complex configurations.

  • versions.tf
    Description: The versions.tf file is used to specify required versions for Terraform and its providers. This ensures compatibility and avoids unintended behavior caused by version mismatches.

  • environment.tfvars
    Description: The environment.tfvars file is typically used to define environment-specific variable overrides. It allows configurations to adapt to environments like development, staging, or production.

  • terraform.lock.hcl
    Description: The terraform.lock.hcl file is an auto-generated dependency lock file. It ensures that Terraform uses the same dependency versions across runs, improving consistency and reducing unexpected changes.

  • init.sh
    Description: The init.sh file is a custom script that may be used to automate the initialization of Terraform configurations, including commands like terraform init and setting up required environment variables.

@pizofreude
Copy link
Author

pizofreude commented Apr 17, 2025

.gitignore for Terraform

When working with Terraform, you should include the following items in your .gitignore file to avoid committing sensitive data, temporary files, and unnecessary state-related files to your repository:

# IaC - Terraform
## Local Terraform directories
.terraform/
.terraform.lock.hcl

## Terraform state files
*.tfstate
*.tfstate.backup

## Crash logs
crash.log

## Override files (used for local configurations)
*.tfvars
*.tfvars.json

## Sensitive files
*.auto.tfvars
*.auto.tfvars.json

## Plan output files
*.tfplan

## Ignore editor or system-specific files
.DS_Store
Thumbs.db
*.swp
*.bak
*.tmp

Explanation of the entries:

  1. .terraform/: The directory where Terraform downloads provider plugins and stores temporary files. This is system-specific and should not be committed.
  2. .terraform.lock.hcl: The dependency lock file. While optional, it is generally a good practice to commit this file to ensure consistent provider versions, but you may choose to ignore it in specific cases.
  3. *.tfstate and *.tfstate.backup: State files that store the current state of your infrastructure. These files often contain sensitive information (e.g., secrets, IDs) and should never be committed.
  4. crash.log: Logs generated when Terraform crashes. Useful for debugging but not relevant to version control.
  5. *.tfvars and *.tfvars.json: Files used to define variable values, often containing sensitive data like passwords or API keys.
  6. *.auto.tfvars and *.auto.tfvars.json: Automatically loaded variable files, often containing sensitive configuration data.
  7. *.tfplan: Files generated by terraform plan commands for storing execution plans. These are ephemeral and not required for version control.
  8. Editor/OS-specific files: Files like .DS_Store, Thumbs.db, or *.swp are generated by text editors or operating systems and should be ignored.

This .gitignore ensures that sensitive information and unnecessary files are excluded from your repository. Let me know if you'd like any clarifications or additions!

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