part two Flashcards
(10 cards)
what is a resource block in terraform ?
It defines a specific infrastructure component, such as a virtual machine, storage bucket, or a database, that Terraform will manage.
how do you run the terraform destroy command to destroy just a specific resource ?
use the -target flag. (terraform destroy -target resource_type.local_resource_name)
what is an attribute in terraform ?
Attributes define the details or configuration of a resource and can also include information Terraform retrieves after the resource is created
what is string interpolation ?
string interpolation is used when you want to merge or combine variables (or expressions) with plain text (defined directly in the string).
eg variable “username” {
default = “Alice”
}
“Welcome, ${var.username}!”
what is the function of an output block in terraform ?
it makes information about your infrastructure available on the command.
what are variables in terraform ?
A variable in Terraform is like a container for storing data that can be reused throughout your configuration
what are the different ways you can define variables in terraform ?
- variable defaults
- variable definition file (*.tfvars)
- Environment variables
- setting variables in the command line
which variable takes precedence in terraform ?
- Command-line flags (-var or -var-file)
- Environment variables (TF_VAR_)
- terraform.tfvars or terraform.tfvars.json
- Automatically loaded .auto.tfvars files
- Default values in variables.tf (Lowest Priority)
what is data type in terraform ?
In Terraform, data types define the kind of values a variable or output can hold. eg string bool number list set map null
what are the different meta arguments in terraform ?
- depends_on : Specifies that a resource or module depends on another resource or module.
- count: Lets you create multiple instances of a resource or module based on a number.
- for_each : Allows you to create multiple instances of a resource or module based on a map or set, with each item being unique.
- provider : Specifies which provider configuration to use for a resource or module.
- lifecycle: Manages the lifecycle behavior of a resource (e.g., prevent deletion, ignore changes, etc.).
create_before_destroy: Ensures a new resource is created before destroying the old one.
prevent_destroy: Protects a resource from being destroyed accidentally.
ignore_changes: Tells Terraform to ignore changes to certain attributes.
- timeouts: Configures how long Terraform should wait for a resource operation to complete.