Terraform Commands/Random Features Flashcards
(35 cards)
What does the terraform fmt command do
It is used to rewrite Terraform config files to take care of the overall formatting.
How does Terraform load config files if there are a number of them in the working directory?
Terraform loads the config files in the same directory in alphabetical order.
What file format will Terraform load using alphabetical order?
The files loaeded must end in either .tf or .tf.json to specify the format that is in use.
How can you report Terraform bugs?
You can report bugs in the Terraform Core Github or appropriate provider page
Whats debugging?
The process of finding the root cause of a specific issue.
What’s an important requirement for debugging?
Getting detailed log information.
Depending on the app, the approach to get detailed logs will differ.
What flag do you add to Terraform to output log information?
-v
If you need more log info you’d add more v’s.
Ex. -vvvv
How to get detailed logs?
You can set the TF_LOG environment variable to any value.
The value for TF_LOG can be set to the values below where TRACE is the most verbose and ERROR is the least verbose.
TRACE
DEBUG
INFO
WARN
ERROR
Can you store log from Terraform to a file?
Yes, you can set the TF_LOG_PATH environment variable to force the log to always be appended to a specific file when logging is enabled.
How to set the TF_VAR env variable in Windows?
The command,
set TF_LOG=VALUE
where VALUE is the log level (TRACE,DEBUG,etc)
The command
set TF_LOG_PATH=file.txt
saves the information to a text file
How to set the TF_VAR env variable in Linux?
export TF_LOG=VALUE
where VALUE is the log level (TRACE,DEBUG,etc)
How do you output to terraform?
output “name” {
value = resource
}
Ex:
output “iam_names” {
value = aws_iam_user.lb[*].name
}
Whats the purpose of the terraform output command?
It’s used to extract the value of an output variable from the state file.
terraform output variable
Ex: terraform output iam_names
What are terraform settings used for?
Terraform settings are used to configure project specific terraform behaviors, such as requiring a minimum terraform version to apply to your configuration.
Terraform settings are gattered in a “terraform block”
What is a terraform block used for?
To configure specific figures.
Ex:
terraform {
required_version = “1.8.1”
}
How do you specify a specific terraform version in code?
If your coat is compatible with specific version of terraform, you can use the “required_aversion “block to add your constraints.
Ex:
required_version = “1.8.1”
What use cases are best in using terraform blocks?
- Specificying certain provider versions (using required_version command)
- Specifying provider requirements (using the required_providers block)
- Backend configuration setttings
- Experimental features settings
Whats the required_providers block used for?
It can be used to specific certain provider requirements.
Ex:
required_providers {
aws = {
version = “5.6.0”
source = “hashicorp/aws”
}
}
What is resource targeting in Terraform used for?
If you only want to create a specific resource even though they may be defined in a .tf file it allows to apply changes to a specific subset of resources rather than applying changes to your entire infrastructure through a terraform plan/apply/destroy
The flag tied to this concept is “-target”
Ex: terraform plan -target resource.name
…
terraform plan -target aws_iam_user.dev
Whats a great use case of terraform resource targeting?
Occasionally, you may want to apply only part of a plan, such as when terraform state is become out of sync with your resources due to a network failure, a problem with the upstream cloud platform, or a bug and terraform or its providers.
Targeting individual resources can be useful for troubleshooting errors, but it should not be part of your normal workflow
What are some solutions to large infrastructure with Terraform?
Using a cloud provider does not mean you have access to a limited resources, there are some limits that apply to all of the services
One thing you have to be careful of when using architecture for the cloud is API throttling, particularly the types of calls in the frequency with which they are called
When allotted rate limit for an API call is exceeded, youll receive an error response and the call with be throttled.
What are some workarounds for large-infra and possible issues?
- Convert a big project into multiple smaller projects and when you run terraform commands.
- Make use of resource targeting
- Setting refresh=false
Whats the zipmap function in Terraform?
The zip map function constructs a map from a list of keys and a corresponding list of values
Ex
zipmap(keyslist, valueslist)
zipmap([“a”, “b”], [1,2])
Output
“a” = 1
“b” = 2
What’s a simple used case for zip map function?
When creating multiple EAM users, you need output, which contains direct mapping of IAM names and ARNs