Terraform: Difference between revisions
Jump to navigation
Jump to search
Line 80: | Line 80: | ||
* Those files follow a naming format of <code>*.auto.tfvars</code> or <code>*.auto.tfvars.json</code>. The former follow the same formatting rules as <code>terraform.tfvars</code>, whereas the latter need to follow standard JSON notation. | * Those files follow a naming format of <code>*.auto.tfvars</code> or <code>*.auto.tfvars.json</code>. The former follow the same formatting rules as <code>terraform.tfvars</code>, whereas the latter need to follow standard JSON notation. | ||
* '''A good example | * '''A good example:''' | ||
** Would be a file named <code>mypasswords.auto.tfvars</code> | |||
** This allows you to have local password definitions that don't get checked into git/GitHub, whereas checking <code>terraform.tfvars</code> into the repo, while perhaps being too specific to your particular usage, won't end up compromising your deployments with an accidentally shared set of credentials. It could even contain a set of reasonable defaults that you and your team may want to change, depending on needs. | ** This allows you to have local password definitions that don't get checked into git/GitHub, whereas checking <code>terraform.tfvars</code> into the repo, while perhaps being too specific to your particular usage, won't end up compromising your deployments with an accidentally shared set of credentials. It could even contain a set of reasonable defaults that you and your team may want to change, depending on needs. | ||
Revision as of 20:24, 16 July 2024
# wget -qO - terraform.gpg https://apt.releases.hashicorp.com/gpg\
# | sudo gpg --dearmor -o /usr/share/keyrings/terraform-archive-keyring.gpg
#
# sudo echo "deb [arch=$(dpkg --print-architecture)\
# signed-by=/usr/share/keyrings/terraform-archive-keyring.gpg]\
# https://apt.releases.hashicorp.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/terraform.list
curl -fsSL https://apt.releases.hashicorp.com/gpg\
| sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
cat << EOF | sudo tee /etc/apt/sources.list.d/hashicorp.list >/dev/null
deb [arch=$(dpkg --print-architecture)\
signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg]\
https://apt.releases.hashicorp.com $(lsb_release -cs) main
EOF
sudo apt update && sudo apt list --upgradeable
sudo apt upgrade && sudo apt install terraform
terraform version
Structure
sdlc/
├─ main.tf # Main Terraform config file
├─ variables.tf # Variable declarations
├─ terraform.tfvars # Variable assigned
├─ outputs.tf # Output definitions
├─ provider.tf # Provider-specific config
├─ terraform.tfstate # Terraform state file
├─ dev.tf # Dev Env config for development
├─ prod.tf # Prod Env config for production
├─ modules/ # Directory for custom modules
│ ├─ module1/ # Custom module 1
│ │ ├─ main.tf # Module-specific Terraform config
│ │ ├─ variables.tf # Module-specific variables
│ │ └─ outputs.tf # Module-specific outputs
│ └─ module2/ # Custom module 2
│ ├─ main.tf
│ ├─ variables.tf
│ └─ outputs.tf
├─ environments/ # Directory for env
│ ├─ dev/ # Development env
│ │ ├─ main.tf # Env specific Terraform config
│ │ ├─ variables.tf
│ │ └─ outputs.tf
│ └─ prod/ # Production env
│ ├─ main.tf
│ ├─ variables.tf
│ └─ outputs.tf
├─ scripts/ # Scripts or utility for IaC
└── README.md
Summary
Playground
References |