Terraform (.tf) Flashcards
(9 cards)
What is Terraform?
Terraform (.tf) is a cloud-agnostic idempotent declarative virtual resource provisioning and defining IaC tool.
Declarative: You describe what you want, and Terraform figures out how to do it.
Idempotent: Run it multiple times, and it won’t create duplicates.
Cloud Agnostic: Works with Azure, AWS, GCP, etc. using providers (like azurerm for Azure).
What is a provider in Terraform?
A. A cloud support agent
B. A plugin that defines resources for a specific platform
C. A billing feature
D. A backup service
B. A plugin that defines resources for a specific platform = a provider in TF.
What’s the purpose of terraform apply (cmd)?
A. Show current config
B. Run tests
C. Deploy the planned changes
D. Remove all resources
C. Deploy the planned changes = terraform apply
What happens if you manually change a resource in the Azure portal after using Terraform?
A. Terraform deletes the resource
B. Nothing changes
C. Terraform ignores manual edits
D. Terraform may detect drift and update it on next plan/apply
D. Terraform may detect drift and update it on next plan/apply
What does terraform destroy do?
A. Deletes the working directory
B. Uninstalls Terraform
C. Deletes all resources defined in your config
D. Erases the state file only
C. Deletes all resources defined in your config = terraform destroy
What is the purpose of terraform refresh?
A. Applies new changes
B. Updates the state file to match real infrastructure
C. Deletes old resources
D. Clears the config cache
B. Updates the state file to match real infrastructure - terraform refresh
Which of the following best describes the Terraform state file (terraform.tfstate)?
A) A log of Terraform command history
B) A backup of your config files
C) A JSON file tracking real infrastructure and config
D) A temporary file used only during apply
C) A JSON file tracking real infrastructure and config = .tfstate
How do you create reusable groups of resources in Terraform?
A) Using providers
B) Using modules
C) Using variables
D) Using plans
B) Using modules creates reusable groups of resources.
Terraform Example
# Configure the Azure provider
provider “azurerm” {
features {} # Required block, can be empty
}
Define a resource group
resource “azurerm_resource_group” “example” {
name = “example-resources” # Name of the resource group
location = “eastus” # Azure region
}
Output the resource group name
output “resource_group_name” {
value = azurerm_resource_group.example.name
}
Configure the Azure provider
provider “azurerm” {
features {} # Required block, can be empty
}
Define a resource group
resource “azurerm_resource_group” “example” {
name = “example-resources” # Name of the resource group
location = “eastus” # Azure region
}
Output the resource group name
output “resource_group_name” {
value = azurerm_resource_group.example.name
}