Terraform Guide
- Installation Link
- Click the "Chocolatey on Windows" tab. Manual installation did not work for me
- Make sure to run as Administrator using Command Prompt
Chocolaty install
- Installation link
- Install in PowerShell. Run as Administrator
Install terraform-docs
-
Use Chocolaty to install. Run on Command Prompt. Link
choco install terraform-docs
- Run
terraform init
in each environment's folder - Run
terraform get
in the environment's folder to register the local modules - Run
terraform validate
to check for syntax errors. Runterraform fmt
to format code - Run
terraform plan
to understand the changes made - Run
terraform apply -var-file="terraform.tfvars"
to run with the variables file (Create this file based onterraform.template.tfvars
provided) Note: If we want to skip the prompt doterraform apply -var-file="terraform.tfvars" -auto-approve
Note: If we want to target only certain resources, we can doterraform apply -var-file="terraform.tfvars" -target module.eks
- Run
terraform destroy
after deployment if used for testing
The following links were used to provide guidance on the Directory Structure
- Medium: Using Terraform at a Production Level
- Terraform docs: Creating Modules
- GitHub repo: Large-size infrastructure using Terraform
Best practices for naming conventions
Code Styling
- Terraform docs: Code styling
- GitHub: terraform-docs
- Article: Automatic Terraform documentation with terraform-docs
- Run
terraform-docs markdown . > README.md
to generate documentation - For the main file I use
terraform-docs markdown . --no-providers > README.md
because somehow my provider was showing up in requirements instead - For modules I use
terraform-docs markdown . --no-providers --no-requirements > README.md
Using modules
Getting part of the output of a command in bash
Refer to this link
Example: This command refers to the first output of the second line
kubectl get secrets | awk 'NR==2{print $1}'
Storing the output of a command in bash in a variable to be referenced elsewhere in a bash file
Refer to this link
Example
token_name=$(kubectl get secrets | awk 'NR==2{print $1}')