---
tags:
- devops
- l1
- flashcard-deck
- terraform-basics
---
<!-- wiki:breadcrumb:start -->
[Portal](../../../../library/portal/index.md) | **Level:** [L1: Foundations](../../../../library/portal/levels.md) | **Topics:** [Terraform](../../../../library/portal/topics.md) | **Domain:** DevOps & Tooling
<!-- wiki:breadcrumb:end -->

id	category	difficulty	tags	question	answer	source_path
terraform-basics/00a8711ff36b	terraform-basics	easy	terraform, resource, output, hcl-syntax	What is the purpose of output in Terraform?	Outputs in Terraform allow you to expose selected values or computed results from your infrastructure configuration. These values can be useful for understanding the outcome of a Terraform run or for sharing specific information with other Terraform configurations. Outputs are declared using the output block, and their values can be referenced in other Terraform configurations or scripts. For example, you might define an output to expose the public IP address of a provisioned resource for external use.	projects/knowledge/interview/terraform/204-what-is-the-purpose-of-output-in-terraform.txt
terraform-basics/00cad2577b3d	terraform-basics	hard	terraform, resource, variable, hcl-syntax	Discuss the concept of "Terraform HCL" and its syntax.	Terraform HashiCorp Configuration Language (HCL) is a domain-specific language used for writing Terraform configurations. Key syntax features include:\n* Blocks: Defined by braces {} and contain configurations for resources, variables, etc.\n* Arguments: Key-value pairs within blocks, defining resource attributes or variable values.\n* Variables: Declared using the variable block and referenced using interpolation syntax.\n* Providers: Declared using the provider block to specify the infrastructure platform.\n* Expressions: Interpolation syntax ${} for referencing variables or performing computations.	projects/knowledge/interview/terraform/234-discuss-the-concept-of-terraform-hcl-and-its-synta.txt
terraform-basics/060cd0764398	terraform-basics	hard	terraform, resource, count, for-each	Discuss the use of Terraform's "count" and "for_each" meta-arguments.	Both count and for_each are meta-arguments in Terraform used to create multiple instances of a resource.\ncount: Specifies the number of resource instances to create based on an integer value. For example, count = 3 creates three instances of the resource.\nfor_each: Allows you to create multiple instances based on a map or set of strings. Each key-value pair or string in the set represents a unique instance. This is more flexible than count as it allows dynamic creation of instances based on the elements in the map or set.	projects/knowledge/interview/terraform/209-discuss-the-use-of-terraforms-count-and-foreach-me.txt
terraform-basics/081d6500210b	terraform-basics	easy	terraform, variable, locals	What are locals in Terraform and how do they simplify configurations?	Similarly to variables they serve as placeholders for data and values. Differently from variables, users can't override them by passing different values.\n\nRemember: "HCL = HashiCorp Configuration Language." It's declarative — you describe the end state, Terraform figures out how to get there.	projects/knowledge/interview/terraform/043-what-are-locals.txt
terraform-basics/084fd59f48a6	terraform-basics	medium	terraform, variable	You have a list variable called "users" with an object containing a name attribute like this:	`users[1].name`\n\nRemember: "Terraform has five core commands: init, plan, apply, destroy, and fmt."\n\nExample: terraform init downloads providers, terraform plan shows changes, terraform apply executes them.	projects/knowledge/interview/terraform/100-you-have-a-list-variable-called-users-with-an-obje.txt
terraform-basics/0af17a030c80	terraform-basics	medium	terraform, variable, output	You have a map variable, called "users", with the keys "name" (string) and "age" (number). Define an output map variable with the key being name in uppercase and value being age in the closest whole number	```\noutput "name_and_age" {\n  value = {for name, age in var.users : upper(name) => floor(age)\n}\n```\n\nRemember: "terraform init = download providers + initialize backend." Always run init first in a new directory or after adding providers.	projects/knowledge/interview/terraform/117-you-have-a-map-variable-called-users-with-the-keys.txt
terraform-basics/1024a182df08	terraform-basics	medium	terraform, count, for-each, hcl-syntax	What's a for_each loop? How is it different from "count"?	- for_each can applied only on collections like maps or sets (as opposed to count that can be applied on lists)\n- for_each helps to deal with the limitation of `count` which isn't optimal for use cases of modifying lists\n- for_each supports inline blocks as opposed to `count`	projects/knowledge/interview/terraform/107-whats-a-foreach-loop-how-is-it-different-from-coun.txt
terraform-basics/124ce6cdd9b6	terraform-basics	medium	terraform, locals	Demonstrate how to define locals	```\nlocals {\n  x = 2\n  y = "o"\n  z = 2.2\n}\n```\n\nRemember: "terraform plan = dry run." It shows what will be created, changed, or destroyed WITHOUT making changes.\n\nExample: + means create, ~ means modify, - means destroy in plan output.	projects/knowledge/interview/terraform/051-demonstrate-how-to-define-locals.txt
terraform-basics/15aa25c6a127	terraform-basics	hard	terraform, resource, variable, hcl-syntax	Explain the concept of Terraform interpolation syntax.	Terraform interpolation syntax allows you to embed expressions within strings or configurations. It is denoted by ${}. Interpolation is commonly used for referencing variables, attributes of resources, or performing calculations. For example:\n```resource "aws_instance" "example" {\n  ami           = var.ami_id\n  instance_type = "t2.micro"\n  tags = {\n    Name = "Example Instance - ${var.environment}"\n  }\n}\n```\nIn this example, ${var.environment} is an interpolation that references the value of the environment variable within the string.\n\nGotcha: Always review the plan before applying. terraform apply -auto-approve skips confirmation (use in CI only, never interactively).	projects/knowledge/interview/terraform/219-explain-the-concept-of-terraform-interpolation-syn.txt
terraform-basics/1c8c6a84fa49	terraform-basics	easy	terraform, resource	What is the Terraform Registry?	The Terraform Registry provides a centralized location for official and community-managed providers and modules.\n\nRef: https://registry.terraform.io/ — hosts 3,000+ providers and 15,000+ modules. Verified modules have a blue checkmark from HashiCorp.\n\nRemember: "Variables go in variables.tf, outputs go in outputs.tf, main resources go in main.tf." This is convention, not requirement.	projects/knowledge/interview/terraform/028-what-is-the-terraform-registry.txt
terraform-basics/1cabd505a15a	terraform-basics	medium	terraform, resource, variable, output	Explain the "depends" parameter of output variable	It is used to set explicitly dependency between the output variable and any other resource. Use case: some piece of information is available only once another resource is ready.\n\nRemember: "Outputs expose values after apply." Useful for passing info between modules or to other tools.\n\nExample: output "instance_ip" { value = aws_instance.web.public_ip }	projects/knowledge/interview/terraform/042-explain-the-depends-parameter-of-output-variable.txt
terraform-basics/1d53cb232e16	terraform-basics	easy	terraform, resource, lifecycle, count	What are meta-arguments in Terraform?	Arguments that affect the lifecycle of a resources (its creation, modification, ...) and supported by Terraform regardless to the type of resource in which they are used.\n\nSome examples:\n\n- count: how many resources to create out of one definition of a resource\n- lifecycle: how to treat resource creation or removal	projects/knowledge/interview/terraform/123-what-are-meta-arguments-in-terraform.txt
terraform-basics/1dd196413c3f	terraform-basics	medium	terraform, resource, lifecycle	You would like to change the name of a resource but afraid to cause downtime. What can be done?	If it's a matter of changing a resource name, you could make use of `terraform state mv <ORIGINAL_RESOURCE_NAME> <NEW_RESOURCE_NAME>`\n\nUnder the hood: state mv updates the state file's resource address without modifying real infrastructure. Use it when refactoring code (renaming resources or moving into modules).\n\nGotcha: always back up state before state operations. Use terraform state pull > backup.json.	projects/knowledge/interview/terraform/174-you-would-like-to-change-the-name-of-a-resource-bu.txt
terraform-basics/1eb7637f15ab	terraform-basics	medium	terraform, depends-on	Explain what depends_on used for and given an example	`depends_on` used to create an explicit dependency between resources in Terraform. For example, there is an application you would like to deploy in a cluster. If the cluster isn't ready (and also managed by Terraform of course) then you can't deploy the app. In this case, you will define "depends_on" in the app configuration and its value will be the cluster resource.	projects/knowledge/interview/terraform/130-explain-what-dependson-used-for-and-given-an-examp.txt
terraform-basics/1fa87fa791a5	terraform-basics	medium	terraform, variable	How to define an input variable which is an object with attributes "model" (string), "color" (string), year (number)?	```\nvariable "car_model" {\n  description = "Car model object"\n  type        = object({\n    model   = string\n    color   = string\n    year    = number\n  })\n}\n```\n\nNote: you can also define a default for it.\n\nGotcha: create_before_destroy prevents downtime during replacement but can cause name conflicts. prevent_destroy stops accidental deletion.	projects/knowledge/interview/terraform/046-how-to-define-an-input-variable-which-is-an-object.txt
terraform-basics/247a3304d779	terraform-basics	hard	terraform, commands, resource	How do you initialize a Terraform configuration?	To initialize a Terraform configuration, you use the terraform init command. This command initializes the working directory, downloads the required providers and modules specified in the configuration, and sets up the backend. Running terraform init is typically the first step after creating or cloning a Terraform configuration. It ensures that the necessary dependencies are in place before applying any changes.	projects/knowledge/interview/terraform/198-how-do-you-initialize-a-terraform-configuration.txt
terraform-basics/24a8dee69681	terraform-basics	medium	terraform, variable	The same variable is defined in the following places:	Terraform loads variables in the following order, with later sources taking precedence over earlier ones:\n\n- Environment variable\n- The file `terraform.tfvars`\n- Using `-var` or `-var-file`\n\nRemember: "for_each > count for named resources." count creates indexed resources; for_each creates named resources (aws_instance.web["app1"]).	projects/knowledge/interview/terraform/038-the-same-variable-is-defined-in-the-following-plac.txt
terraform-basics/2646f866d338	terraform-basics	easy	terraform, commands	What is the Terraform plan command used for?	The terraform plan command is used to preview the changes that Terraform will make to the infrastructure based on the current configuration. It analyzes the configuration files, compares the desired state with the existing state, and generates an execution plan. The plan includes details such as which resources will be added, modified, or destroyed. Running terraform plan allows users to review potential changes before applying them, providing an opportunity to catch errors or unintended modifications.	projects/knowledge/interview/terraform/199-what-is-the-terraform-plan-command-used-for.txt
terraform-basics/28033e54fe62	terraform-basics	medium	terraform, data-source, variable, resource	What is a data source? In what scenarios for example would need to use it?	Data sources lookup or compute values that can be used elsewhere in terraform configuration.\n\nThere are quite a few cases you might need to use them:\n\n- you want to reference resources not managed through terraform\n- you want to reference resources managed by a different terraform module\n- you want to cleanly compute a value with typechecking, such as with `aws_iam_policy_document`	projects/knowledge/interview/terraform/065-what-is-a-data-source-in-what-scenarios-for-exampl.txt
terraform-basics/287537436252	terraform-basics	medium	terraform, provisioner	What are "Provisioners"? What they are used for?	Provisioners can be described as plugin to use with Terraform, usually focusing on the aspect of service configuration and make it operational.\n\nFew example of provisioners:\n\n- Run configuration management on a provisioned instance using technology like Ansible, Chef or Puppet.\n- Copying files\n- Executing remote scripts	projects/knowledge/interview/terraform/060-what-are-provisioners-what-they-are-used-for.txt
terraform-basics/2997cb6f9b08	terraform-basics	hard	plan, apply, workflow	Explain the difference between `terraform plan` and `terraform apply`.	These are the two main commands in Terraform's workflow:\n\nterraform plan:\n- Shows what changes will be made WITHOUT executing them\n- Compares current state with desired configuration\n- Output shows: create, update, or destroy actions\n- Safe to run repeatedly\n- Can save plan to file with -out flag\n\nterraform apply:\n- Actually creates/modifies/destroys resources\n- By default, shows plan first and asks for confirmation\n- Can skip confirmation with -auto-approve (use cautiously)\n- Can apply a saved plan file	projects/knowledge/interview/terraform/002-plan-vs-apply.txt
terraform-basics/2ca5bf6c7370	terraform-basics	medium	terraform, hcl-syntax, commands	How do you test terraform syntax?	A valid answer could be "I write Terraform configuration and try to execute it" but this makes testing cumbersome and quite complex in general.\n\nThere is `terraform console` command which allows you to easily execute terraform functions and experiment with general syntax.	projects/knowledge/interview/terraform/127-how-do-you-test-terraform-syntax.txt
terraform-basics/2db802277b91	terraform-basics	medium	terraform, variable	What type of input variables are supported in Terraform?	```\nstring\nnumber\nbool\nlist(<TYPE>)\nset(<TYPE>)\nmap(<TYPE>)\nobject({<ATTR_NAME> = <TYPE>, ... })\ntuple([<TYPE>, ...])\n```\n\nRemember: "Provisioners are a last resort." Use user_data, cloud-init, or config management (Ansible) instead when possible.	projects/knowledge/interview/terraform/033-what-type-of-input-variables-are-supported-in-terr.txt
terraform-basics/2ee703f1c3f1	terraform-basics	medium	terraform, lifecycle	What happens if you update user_data in the following case and apply the changes?	Nothing, because user_data is executed on boot so if an instance is already running, it won't change anything.\n\nTo make it effective you'll have to use `user_data_replace_on_change = true`.\n\nRemember: "terraform fmt = auto-format HCL." Run it before every commit. terraform fmt -check in CI verifies formatting.	projects/knowledge/interview/terraform/154-what-happens-if-you-update-userdata-in-the-followi.txt
terraform-basics/2f53445c5d77	terraform-basics	medium	terraform, hcl, configuration	What language do Terraform configuration files use?	The HashiCorp Configuration Language (HCL), which is declarative and human-readable (usually files with .tf extension). Terraform can also optionally accept JSON configuration, but HCL is most common.\n\nRemember: "terraform validate = syntax check." It catches typos, invalid references, and type errors without contacting any provider API.	projects/knowledge/interview/terraform/274-terraform-language.txt
terraform-basics/32df6f30ff9b	terraform-basics	medium	terraform, hcl-syntax, resource	What makes a Terraform code module? In other words, what a module is from practical perspective?	Basically any file or files in a directory is a module in Terraform. There is no special syntax to use in order to define a module. The root configuration is itself a module, and any module that is called from it is considered a child module.	projects/knowledge/interview/terraform/132-what-makes-a-terraform-code-module-in-other-words-.txt
terraform-basics/3525363391df	terraform-basics	hard	terraform, resource, variable, hcl-syntax	How do you reference variables in Terraform configuration files?	Variables are referenced in Terraform configuration files using the syntax ${var.variable_name}. For example, if you have a variable named environment in your configuration, you can reference it in a resource block like this:\n```\nresource "aws_instance" "example" {\n  ami           = "ami-abc123"\n  instance_type = var.instance_type\n  tags = {\n    Name = "Example Instance - ${var.environment}"\n  }\n}\n```\nIn this example, var.instance_type references the value of the instance_type variable, allowing for dynamic configuration based on the provided variable values.	projects/knowledge/interview/terraform/203-how-do-you-reference-variables-in-terraform-config.txt
terraform-basics/364f5e14a7fc	terraform-basics	medium	terraform, for-each	What loops are useful for in Terraform?	The most common use case is when you need to create multiple resources with only a slight difference (like different name). Instead of defining multiple separate resources, you can define it once and create multiple instances of it using loops.	projects/knowledge/interview/terraform/102-what-loops-are-useful-for-in-terraform.txt
terraform-basics/36a49d61ca56	terraform-basics	medium	terraform, variable, hcl-syntax, lifecycle	How to reference variable from inside of string literal? (bonus question: how that type of expression is called?)	Using the syntax: `"${var.VAR_NAME}"`. It's called "interpolation".\n\nVery common to see it used in user_data attribute related to instances.\n\n```\nuser_data = <<-EOF\n            This is some fabulos string\n            It demonstrates how to use interpolation\n            Yes, it's truly ${var.awesome_or_meh}\n            EOF\n```	projects/knowledge/interview/terraform/048-how-to-reference-variable-from-inside-of-string-li.txt
terraform-basics/37e8a85bc4eb	terraform-basics	medium	terraform, commands, resource	Describe in high level what happens behind the scenes when you run terraform init on on the following Terraform configuration	1. Terraform checks if there is an aws provider in this address: `registry.terraform.io/hashicorp/aws`\n2. Installs latest version of aws provider (assuming the URL exists and valid)\n\nRemember: "Locals = computed constants." Use them to avoid repeating expressions.\n\nExample: locals { env_prefix = "${var.project}-${var.env}" }	projects/knowledge/interview/terraform/030-describe-in-high-level-what-happens-behind-the-sce.txt
terraform-basics/38b844ccb884	terraform-basics	hard	terraform, resource	Explain the concept of resources in Terraform.	In Terraform, resources represent the infrastructure components that you want to manage. Resources are declared in Terraform configuration files and correspond to entities such as virtual machines, networks, databases, and more. Each resource type is associated with a specific provider, and its configuration defines the desired characteristics of that resource. Terraform uses the configurations to create, update, or destroy the corresponding resources in the target environment.	projects/knowledge/interview/terraform/201-explain-the-concept-of-resources-in-terraform.txt
terraform-basics/395e9d10271a	terraform-basics	easy	terraform, fundamentals	What is a "data source" in Terraform?	Allows fetching information from external systems to use in code.\n\nExample: data "aws_ami" "ubuntu" { filter { name = "name" values = ["ubuntu/images/*22.04*"] } } fetches the latest Ubuntu AMI without creating any resources.	projects/knowledge/interview/terraform/287-data-source.txt
terraform-basics/3b8ebb703908	terraform-basics	medium	terraform, lifecycle	How do you rename an existing resource?	`terraform state mv`\n\nUnder the hood: state mv updates the state file's resource address without modifying real infrastructure. Use it when refactoring code (renaming resources or moving into modules).\n\nGotcha: always back up state before state operations. Use terraform state pull > backup.json.\n\nRemember: "Data sources READ existing resources, Resources CREATE/MANAGE them."	projects/knowledge/interview/terraform/095-how-do-you-rename-an-existing-resource.txt
terraform-basics/3f89eca55deb	terraform-basics	medium	terraform, commands	Discuss the differences between "Terraform Apply" and "Terraform Plan."	* terraform plan: Generates an execution plan describing the changes Terraform will make without applying them. It's a dry run to preview changes.\n* terraform apply: Executes the changes described in the execution plan, applying the proposed modifications to the infrastructure.	projects/knowledge/interview/terraform/251-discuss-the-differences-between-terraform-apply-an.txt
terraform-basics/420651bd9978	terraform-basics	easy	terraform, variable	How to list resources created with Terraform?	`terraform state list`\n\nUnder the hood: reads the state file and lists all resource addresses Terraform manages. Use terraform state show <address> for full details on a specific resource.	projects/knowledge/interview/terraform/094-how-to-list-resources-created-with-terraform.txt
terraform-basics/48890dbf8c24	terraform-basics	medium	terraform, variable, output	There is a list variable called "users". You would like to define an output variable with a value of all users in uppercase. How to achieve that?	```\noutput "users" {\n  value = [for name in var.user_names : upper(name)]\n}\n```\n\nRemember: "depends_on = explicit ordering." Use it when Terraform can't infer the dependency from resource references.\n\nGotcha: Most dependencies are implicit — only use depends_on for hidden dependencies.	projects/knowledge/interview/terraform/111-there-is-a-list-variable-called-users-you-would-li.txt
terraform-basics/4908b2056783	terraform-basics	medium	terraform, resource, depends-on	Does it matter in which order Terraform creates resources?	Yes, when there is a dependency between different Terraform resources, you want the resources to be created in the right order and this is exactly what Terraform does.\n\nTo make it ever more clear, if you have a resource X that references the ID of resource Y, it doesn't makes sense to create first resource X because it won't have any ID to get from a resource that wasn't created yet.\n\nRemember: "terraform destroy = delete everything in state." Always plan before destroy: terraform plan -destroy.	projects/knowledge/interview/terraform/019-does-it-matter-in-which-order-terraform-creates-re.txt
terraform-basics/4de62e60e06a	terraform-basics	easy	terraform, variable	What's the default input variable type in Terraform?	`any`. When no type constraint is specified, Terraform accepts any value type. In practice, always declare explicit types (`string`, `number`, `list`, `map`, `bool`) for safety and documentation.	projects/knowledge/interview/terraform/034-whats-the-default-input-variable-type-in-terraform.txt
terraform-basics/4ebccee38925	terraform-basics	medium	terraform, commands, resource	How do you test a Terraform module?	There are multiple answers, but the most common answer would likely to be using the tool `terratest`, and to test that a module can be initialized, can create resources, and can destroy those resources cleanly. You can also rely on `terraform validate`, `terraform plan` with sample configurations, and linting tools such as `tflint`.	projects/knowledge/interview/terraform/139-how-do-you-test-a-terraform-module.txt
terraform-basics/4f38acf9a11b	terraform-basics	easy	terraform, commands, init	What is terraform init and when do you run it?	terraform init initializes a Terraform working directory – it downloads provider plugins, sets up the backend, and prepares the environment. You run it once per project (or whenever providers/modules change).	projects/knowledge/interview/terraform/279-what-is-terraform-init.txt
terraform-basics/5201c1190589	terraform-basics	medium	terraform, variable, output	There is a variable called "values" with the following value: ["mario", "luigi", "peach"]. How to create an output variable with the string value of the items in the list: "mario, luigi, peach," ?	```\noutput "users" {\n  value = "%{ for name in var.values }${name}, %{ endfor }"\n}\n```\n\nRemember: "Dynamic blocks generate repeated nested blocks." Useful for security group rules, tags, etc.	projects/knowledge/interview/terraform/113-there-is-a-variable-called-values-with-the-followi.txt
terraform-basics/53c91ac3faa0	terraform-basics	hard	terraform, resource, variable, locals	How can you implement conditional logic in Terraform configurations?	Conditional logic in Terraform can be implemented using the count and for_each meta-arguments, as well as the locals block. For example:\n```resource "aws_instance" "example" {\n  count = var.create_instance ? 1 : 0\n  ami   = var.ami_id\n  // other attributes\n}\n```\nHere, the instance is created only if the create_instance variable is true. The locals block can be used for more complex conditions. Terraform doesn't support traditional programming constructs like if-else directly but provides these mechanisms for achieving conditional behavior.\n\nRemember: "terraform console = interactive REPL." Test expressions before putting them in code.	projects/knowledge/interview/terraform/233-how-can-you-implement-conditional-logic-in-terrafo.txt
terraform-basics/542810c106ef	terraform-basics	medium	terraform, data-source	Demonstrate how to use data sources	Data sources let you fetch information from existing infrastructure. \nExample: `data "aws_vpc" "default" { default = true }` reads the default VPC. Reference its attributes with `data.aws_vpc.default.id`. Data sources are read-only — Terraform never modifies the referenced resource. Use them to look up AMI IDs, VPC IDs, or AZ lists dynamically.	projects/knowledge/interview/terraform/054-demonstrate-how-to-use-data-sources.txt
terraform-basics/55808c0fe36b	terraform-basics	medium	terraform, resource, variable, for-each	The following resource tries to use for_each loop on a list of strings but it fails, why?	for_each can applied only on collections like maps or sets so the list should be converted to a set like this: `for_each = toset(var.names)`\n\nRemember: "terraform graph outputs DOT format." Pipe to Graphviz: terraform graph | dot -Tpng > graph.png.	projects/knowledge/interview/terraform/109-the-following-resource-tries-to-use-foreach-loop-o.txt
terraform-basics/567a70e97623	terraform-basics	medium	terraform, data-source	Explain data sources in Terraform	- Data sources used to get data from providers or in general from external resources to Terraform (e.g. public clouds like AWS, GCP, Azure).\n- Data sources used for reading. They are not modifying or creating anything\n- Many providers expose multiple data sources\n\nRemember: "Workspaces = multiple state files in one config." terraform workspace new staging creates a separate state.\n\nGotcha: Many teams prefer separate directories over workspaces for clearer separation.	projects/knowledge/interview/terraform/053-explain-data-sources-in-terraform.txt
terraform-basics/57c853880c27	terraform-basics	hard	terraform, data-source, output, commands	Explain the differences between "Terraform Outputs" and "Terraform Data Sources."	* terraform outputs: Defines values that will be outputted after a successful terraform apply. Used for exposing specific information about the infrastructure.\n* terraform data: Retrieves data from external sources or existing resources. Used for importing data that isn't managed by Terraform.\n*Outputs provide information about the infrastructure, while data sources fetch external information for use within Terraform configurations.	projects/knowledge/interview/terraform/258-explain-the-differences-between-terraform-outputs-.txt
terraform-basics/587668bb0dd1	terraform-basics	medium	terraform, data-source	Is there such a thing as combining data sources? What would be the use case?	Yes, you can define a data source while using another data source as a filter for example.\n\nLet's say we want to get AWS subnets but only from our default VPC:\n\n```\ndata "aws_subnets" "default" {\n  filter {\n    name   = "vpc-id"\n    values = [data.aws_vpc.default.id]\n  }\n}\n```	projects/knowledge/interview/terraform/056-is-there-such-a-thing-as-combining-data-sources-wh.txt
terraform-basics/5a7c4c697b7b	terraform-basics	hard	terraform, commands, plan, apply	What's the difference between terraform plan and terraform apply?	terraform plan creates an execution plan – it shows what changes Terraform would make to match the configuration (adding, changing, destroying resources) without actually performing them. terraform apply actually executes those changes to real infrastructure (and by default will also show a plan and ask for approval before proceeding).	projects/knowledge/interview/terraform/277-plan-vs-apply.txt
terraform-basics/5f596e8908f0	terraform-basics	easy	terraform, variable	What are input variables good for in Terraform?	Variables allow you define piece of data in one location instead of repeating the hardcoded value of it in multiple different locations. Then when you need to modify the variable's value, you do it in one location instead of changing each one of the hardcoded values.	projects/knowledge/interview/terraform/032-what-are-input-variables-good-for-in-terraform.txt
terraform-basics/6120f4e85dea	terraform-basics	medium	terraform, variable, commands	Whenever you run terraform apply, it prompts to enter a value for a given variable. How to avoid being prompted?	While removing the variable is theoretically a correct answer, it will probably fail the execution.\n\nYou can use something like the `-var` option to provide the value and avoid being prompted to insert a value. Another option is to run `export TF_VAR_<VAR_NAME>=<VALUE>`.	projects/knowledge/interview/terraform/039-whenever-you-run-terraform-apply-it-prompts-to-ent.txt
terraform-basics/642b1973e58a	terraform-basics	easy	terraform, commands	What does terraform init do?	Initializes the working directory and downloads provider plugins.\n\nUnder the hood: init downloads providers to .terraform/, initializes the backend (local or remote state), and installs module sources. Must run after any provider or backend change.	projects/knowledge/interview/terraform/275-terraform-init.txt
terraform-basics/643c802c043f	terraform-basics	medium	terraform, variable, output, resource	Explain the role of "Terraform Variables" and their different types.	Terraform variables are parameters that allow users to input values into configurations. Types of Terraform variables include:\n* Input Variables: Defined in configurations and initialized by users when running Terraform commands.\n* Output Variables: Represent values that can be queried and used by other configurations.\n* Local Variables: Defined within a module and used for intermediate computations.\n\nRemember: "Terraform registry = module marketplace." Use verified modules to avoid reinventing the wheel.	projects/knowledge/interview/terraform/245-explain-the-role-of-terraform-variables-and-their-.txt
terraform-basics/64497ed0d23c	terraform-basics	medium	terraform, provisioner	Why is it often recommended to use provisioners as last resort?	Since a provisioner can run a variety of actions, it's not always feasible to plan and understand what will happen when running a certain provisioner. For this reason, it's usually recommended to use Terraform built-in option, whenever's possible.	projects/knowledge/interview/terraform/061-why-is-it-often-recommended-to-use-provisioners-as.txt
terraform-basics/64ac2c9362a4	terraform-basics	medium	terraform, output, variable	How can list all outputs without applying Terraform changes?	`terraform output` will list all outputs without applying any changes\n\nRemember: "Version constraints: ~> 1.5 means >= 1.5.0 and < 2.0.0. ~> 1.5.0 means >= 1.5.0 and < 1.6.0."\n\nGotcha: Pin provider versions to avoid surprise breaking changes.	projects/knowledge/interview/terraform/049-how-can-list-all-outputs-without-applying-terrafor.txt
terraform-basics/693873d09c5f	terraform-basics	medium	terraform, commands	How to cleanup Terraform resources? Why the user should be careful doing so?	`terraform destroy` will cleanup all the resources tracked by Terraform.\n\nA user should be careful with this command because there is no way to revert it. Sure, you can always run again "apply" but that can take time, generates completely new resources, etc.\n\nRemember: "terraform taint is deprecated — use terraform apply -replace=RESOURCE instead (Terraform 0.15.2+)."	projects/knowledge/interview/terraform/017-how-to-cleanup-terraform-resources-why-the-user-sh.txt
terraform-basics/6ac07d6c8873	terraform-basics	medium	terraform, commands	What do you do next after writing the following in main.tf file?	Run `terraform init`. This will scan the code in the directory to figure out which providers are used (in this case AWS provider) and will download them.	projects/knowledge/interview/terraform/013-what-do-you-do-next-after-writing-the-following-in.txt
terraform-basics/6c03508b3429	terraform-basics	medium	terraform, variable, output	You have a map variable, called "users", with the keys "name" and "age". Define an output list variable with the following "my name is {name} and my age is {age}"	```\noutput "name_and_age" {\n  value = [for name, age in var.users : "my name is ${name} and my age is ${age}"]\n}\n```\n\nRemember: "sensitive = true hides values in plan/apply output." But values are still in state file — encrypt your state.	projects/knowledge/interview/terraform/116-you-have-a-map-variable-called-users-with-the-keys.txt
terraform-basics/6f0aed77c4ed	terraform-basics	hard	terraform, resource, depends-on, provisioner	Explain the purpose of "Terraform Null Resources" and when you might use them.	Null Resources in Terraform represent resources with no direct parallel in the target infrastructure. They are used for:\n* Dependency Creation: Establishing dependencies between resources.\n* Local Provisioning: Running local provisioners without creating a tangible resource.\n* Conditional Logic: Implementing conditional logic based on changes or triggers.\nNull Resources are useful for scenarios where a real resource doesn't exist, but some actions need to be performed.\n\nRemember: "Conditional = condition ? true_val : false_val. Splat = resource[*].attribute."\n\nExample: instance_type = var.env == "prod" ? "m5.large" : "t3.micro"	projects/knowledge/interview/terraform/252-explain-the-purpose-of-terraform-null-resources-an.txt
terraform-basics/6fc437661f6e	terraform-basics	easy	terraform, fundamentals	What is the primary language used by Terraform?	HCL (HashiCorp Configuration Language).\n\nFun fact: HCL (HashiCorp Configuration Language) was created specifically for infrastructure-as-code — human-readable like YAML but with first-class support for expressions and blocks.	projects/knowledge/interview/terraform/274-hcl-language.txt
terraform-basics/71cd75e39856	terraform-basics	easy	terraform, resource, variable, count	How to create a number of resources based on the length of a list?	```\nresource "some_resource" "some_name" {\n  count = length(var.some_list)\n}\n```\n\nRemember: "Backend config is in the terraform {} block." Backend determines where state is stored (local, S3, GCS, Consul, etc.).	projects/knowledge/interview/terraform/099-how-to-create-a-number-of-resources-based-on-the-l.txt
terraform-basics/73ee48d74d05	terraform-basics	medium	terraform, variable	Demonstrate input variable definition with type, description and default parameters	```\nvariable "app_id" {\n  type        = string\n  description = "The id of application"\n  default     = "some_value"\n}\n```\n\nUnrelated note: variables are usually defined in their own file (vars.tf for example).\n\nRemember: "terraform import brings existing resources under Terraform management." It adds to state but does NOT generate config.\n\nGotcha: Write the HCL first, then import.	projects/knowledge/interview/terraform/045-demonstrate-input-variable-definition-with-type-de.txt
terraform-basics/74e4210275ef	terraform-basics	easy	terraform, commands	What is the purpose of terraform validate?	Checks the syntax and consistency of configuration files.\n\nGotcha: validate checks syntax and type constraints but does NOT check that resource configurations are valid against the provider API. terraform plan catches those errors.\n\nRemember: "Provider aliases allow multiple provider configurations." Useful for multi-region or multi-account setups.	projects/knowledge/interview/terraform/286-terraform-validate.txt
terraform-basics/765d6a463cab	terraform-basics	easy	terraform, data-source	What is the purpose of Terraform data sources?	Terraform data sources allow you to query and retrieve information from external sources during the Terraform execution. Data sources do not create or manage resources but provide read-only access to external data, such as existing infrastructure details or information from APIs. Examples of data sources include querying AWS AMIs, getting information from external databases, or fetching details from a configuration management database (CMDB).	projects/knowledge/interview/terraform/210-what-is-the-purpose-of-terraform-data-sources.txt
terraform-basics/786b6defc7cd	terraform-basics	medium	terraform, resource, count	Discuss the role of "Terraform Count" and its implications on infrastructure scaling.	terraform count is used to create multiple instances of a resource. Implications include:\n* Dynamic Scaling: Allows dynamic scaling based on the count value.\n* Resource Duplication: Creates multiple resource instances with similar configurations.\n* Consistency: Ensures a consistent approach to scaling infrastructure.	projects/knowledge/interview/terraform/254-discuss-the-role-of-terraform-count-and-its-implic.txt
terraform-basics/79d46f23f030	terraform-basics	medium	terraform, data-source, hcl-syntax, variable	How to get data out of a data source?	The general syntax is `data.<PROVIDER_AND_TYPE>.<NAME>.<ATTRIBUTE>`\n\nSo if you defined the following data source\n\n```\ndata "aws_vpc" "default {\n  default = true\n}\n```\n\nYou can retrieve the ID attribute this way: `data.aws_vpc.default.id`	projects/knowledge/interview/terraform/055-how-to-get-data-out-of-a-data-source.txt
terraform-basics/79f420f45969	terraform-basics	medium	terraform, commands	You've downloaded the providers, seen the what Terraform will do (with terraform plan) and you are ready to actually apply the changes. What should you do next?	Run `terraform apply`. That will apply the changes described in your .tf files.\n\nRemember: "Null resource + triggers = run provisioners on changes." Replaced by terraform_data in Terraform 1.4+.	projects/knowledge/interview/terraform/015-youve-downloaded-the-providers-seen-the-what-terra.txt
terraform-basics/7c02f504087d	terraform-basics	hard	terraform, variable, locals, hcl-syntax	Explain the role of "Terraform Locals" and how they enhance configuration readability.	Terraform Locals allow the definition of named expressions to enhance configuration readability by:\n* Variable Naming: Naming complex expressions for better understanding.\n* Code Reusability: Enabling reuse of computed values across the configuration.\n* Complex Expression Simplification: Breaking down complex expressions into more manageable parts.\n* Reduced Redundancy: Avoiding redundant calculations by storing intermediate values.\n* Improved Maintainability: Enhancing code maintainability by encapsulating logic.\n\nRemember: "moved blocks handle refactoring." moved { from = old to = new } tells Terraform the resource was renamed, not deleted.	projects/knowledge/interview/terraform/263-explain-the-role-of-terraform-locals-and-how-they-.txt
terraform-basics/7c040747127f	terraform-basics	medium	terraform, resource, output, count	What's the result of the following code?	The above code will fail as it's not possible to reference resource outputs with count, because Terraform has to compute count before any resources are created (or modified).	projects/knowledge/interview/terraform/112-whats-the-result-of-the-following-code-resource-ra.txt
terraform-basics/86cde993d17c	terraform-basics	easy	terraform, modules, reusability	What is a Terraform module?	A Terraform module is a set of Terraform configuration files in a directory, encapsulating a logical grouping of resources for reuse. Every Terraform configuration is implicitly a "module" (root module), and you can create child modules to abstract and reuse infrastructure components (like a module for a VPC, a module for a web server cluster).\n\nRemember: "Check blocks validate infrastructure without blocking applies." They warn instead of failing.	projects/knowledge/interview/terraform/280-what-is-module.txt
terraform-basics/87974fd203c8	terraform-basics	medium	terraform, variable	You need to render a template and get it as string. Which function would you use?	The `templatefile` function renders a template file and returns it as a string. \nExample: `templatefile("${path.module}/user-data.sh", { name = var.name })` replaces `${name}` in the template. It replaced the deprecated `template_file` data source. Supports full Terraform expression syntax inside `${}` interpolations.	projects/knowledge/interview/terraform/129-you-need-to-render-a-template-and-get-it-as-string.txt
terraform-basics/88819d8a20b1	terraform-basics	hard	terraform, resource, provisioner	Discuss the role of Terraform "provisioners" in bootstrapping instances.	Terraform provisioners are used to execute scripts or commands on instances after resource creation. They play a crucial role in bootstrapping instances by:\n* Configuration: Setting up software or configuring instances post-creation.\n* Initialization: Running scripts for software installations or customizations.\n* Integration: Coordinating with configuration management tools.\n* Dependencies: Handling dependencies before applications start.\n\nRemember: "terraform.tfvars = default variable values file." Loaded automatically. Use *.auto.tfvars for additional auto-loaded files.	projects/knowledge/interview/terraform/240-discuss-the-role-of-terraform-provisioners-in-boot.txt
terraform-basics/898f99d3a199	terraform-basics	medium	terraform, resource, variable, count	You have the following variable defined in Terraform	Use `count = length(var.users)` with `var.users[count.index]` to create multiple resources from a list variable. \nExample: `resource "aws_iam_user" "user" { count = length(var.users); name = var.users[count.index] }`. Alternative: use `for_each` with a set for more stable resource addresses — count-based resources shift indexes when items are removed.	projects/knowledge/interview/terraform/105-you-have-the-following-variable-defined-in-terrafo.txt
terraform-basics/8ae228ca3e01	terraform-basics	medium	terraform, resource, lifecycle, depends-on	What meta-arguments are you familiar with?	- count: how many resources to create out of one definition of a resource\n- lifecycle: how to treat resource creation or removal\n- depends_on: create a dependency between resources\n\nRemember: "Terraform functions: lookup(map, key, default), merge(map1, map2), join(sep, list), split(sep, string)."	projects/knowledge/interview/terraform/124-what-meta-arguments-are-you-familiar-with.txt
terraform-basics/8d55cf1c4e0f	terraform-basics	medium	terraform, commands	How do you delete all Terraform-managed resources?	terraform destroy.\n\nGotcha: terraform destroy deletes ALL managed resources. In production, use targeted destroys: terraform destroy -target=aws_instance.example. Always review the plan before confirming.\n\nRemember: "Preconditions validate inputs, Postconditions validate results." Both go inside lifecycle or variable blocks.	projects/knowledge/interview/terraform/278-terraform-destroy.txt
terraform-basics/8fbcabe71cec	terraform-basics	hard	terraform, resource, count, for-each	Discuss the use of "count" and "for_each" with modules in Terraform.	count and for_each are meta-arguments in Terraform used for creating multiple instances of resources or modules.\ncount: Specifies the number of resource instances to create, like creating multiple identical instances.\nfor_each: Allows creating instances based on a map or set, enabling more dynamic configurations.\nExample:\n```module "example" {\n  source  = "./modules/example"\n  count   = 3\n  name    = "instance-${count.index}"\n}\n```\nHere, the count meta-argument creates three instances of the "example" module with distinct names.\n\nRemember: "Variable validation blocks enforce constraints before plan." Type + validation = defense in depth.	projects/knowledge/interview/terraform/237-discuss-the-use-of-count-and-foreach-with-modules-.txt
terraform-basics/90e59d5ef84e	terraform-basics	medium	terraform, resource, hcl-syntax	Explain the following block of Terraform code	It's a resource of type "aws_instance" used to provision an instance. The name of the resource (NOT INSTANCE) is "some-instance".\n\nThe instance itself will be provisioned with type "t2.micro" and using an image of the AMI "ami-201720221991yay".	projects/knowledge/interview/terraform/012-explain-the-following-block-of-terraform-code-reso.txt
terraform-basics/910fee6857a1	terraform-basics	hard	terraform, variable, hcl-syntax, for-each	How can you use "Terraform Variables" to achieve dynamic configurations?	Terraform variables can be used dynamically by:\n* Variable Types: Utilizing different variable types, such as string, list, map, or boolean.\n* Conditional Logic: Implementing conditionals based on variable values.\n* Variable Overrides: Allowing users to override default variable values.\n* Dynamic Blocks: Using dynamic blocks to create dynamic configurations.\n* Input Validation: Applying validation rules to ensure proper variable values.	projects/knowledge/interview/terraform/256-how-can-you-use-terraform-variables-to-achieve-dyn.txt
terraform-basics/918a33b2ceb1	terraform-basics	easy	terraform, commands	True or False? Terraform console should be used carefully as it may modify your resources	False. terraform console is ready-only.\n\nUnder the hood: terraform console loads state and variables, letting you test expressions interactively. Great for debugging interpolations: try type(var.my_list) or length(var.my_map).	projects/knowledge/interview/terraform/128-true-or-false-terraform-console-should-be-used-car.txt
terraform-basics/93ce5ea659df	terraform-basics	hard	terraform, variable	What is a variable in Terraform, and how is it defined?	In Terraform, variables are placeholders for values that can be passed into the configuration. They enable the reuse and parameterization of values within Terraform files. Variables can be defined in a separate variable file (e.g., variables.tf) or directly in the main configuration file. Variable definitions include a name, a type, an optional default value, and other attributes. They can be referenced throughout the configuration to provide flexibility and make it easier to customize Terraform deployments for different scenarios.\n\nRemember: "Count creates numbered instances, for_each creates named instances." for_each is safer because removing an item doesn't renumber everything.	projects/knowledge/interview/terraform/202-what-is-a-variable-in-terraform-and-how-is-it-defi.txt
terraform-basics/9426e2897f01	terraform-basics	easy	terraform, variable	What templatefile function does?	Renders a template file and returns the result as string.\n\nExample: templatefile("user_data.sh.tpl", { hostname = var.name }) renders the template with the given variables. Replaces the deprecated template_file data source.	projects/knowledge/interview/terraform/125-what-templatefile-function-does.txt
terraform-basics/9661fe28d196	terraform-basics	medium	terraform, hcl-syntax	How to use conditional expressions in Terraform?	Terraform conditional expression: `condition ? value_if_true : value_if_false`. \nExample: `instance_type = var.env == "prod" ? "m5.large" : "t3.micro"` selects instance size based on environment. \nGotcha: both branches must return the same type. You can nest conditionals but prefer locals for complex logic to maintain readability.	projects/knowledge/interview/terraform/118-how-to-use-conditional-expressions-in-terraform.txt
terraform-basics/9733de1ee64b	terraform-basics	medium	terraform, locals	Demonstrate how to use a local	if we defined something like this\n\n```\nlocals {\n  x = 2\n}\n```\n\nthen to use it, you have to use something like this: `local.x`\n\nRemember: "Heredoc syntax for multi-line strings: <<-EOT content EOT." The - allows indentation stripping.	projects/knowledge/interview/terraform/052-demonstrate-how-to-use-a-local.txt
terraform-basics/975057b90ab0	terraform-basics	hard	terraform, resource, depends-on	How do you handle dependencies between resources in Terraform?	Terraform automatically handles dependencies based on the resource references in the configuration. When one resource references another, Terraform establishes an implicit dependency, ensuring that the referenced resource is created or updated before the dependent resource. You can also use explicit dependencies using the depends_on meta-argument to define custom dependencies between resources. However, it's generally recommended to rely on implicit dependencies for better readability and maintainability.\n\nRemember: "Resource meta-arguments: count, for_each, provider, depends_on, lifecycle." These control how Terraform manages the resource.	projects/knowledge/interview/terraform/211-how-do-you-handle-dependencies-between-resources-i.txt
terraform-basics/a0d8fd21138b	terraform-basics	easy	terraform, hcl-syntax	What language does Terraform uses?	A DSL called "HCL" (Hashicorp Configuration Language). A declarative language for defining infrastructure.\n\nFun fact: HCL was designed to be human-friendly (like YAML) but machine-parseable (like JSON). You can write Terraform in JSON too, but HCL is standard.	projects/knowledge/interview/terraform/008-what-language-does-terraform-uses.txt
terraform-basics/a143bafd611b	terraform-basics	medium	terraform, locals	What's the use case for using locals?	You have multiple hardcoded values that repeat themselves in different sections, but at the same time you don't want to expose them as in, allow users to override values.	projects/knowledge/interview/terraform/044-whats-the-use-case-for-using-locals.txt
terraform-basics/a19baaec8662	terraform-basics	medium	terraform, resource, variable, count	Can conditionals be used with meta-arguments?	Yes, for example the "count" meta-argument:\n\n```\nresource "aws_instance" "server" {\n  count = var.amount ? 1 : 0\n  ...\n}\n```\n\nRemember: "Terraform collection types: list (ordered), map (key-value), set (unique, unordered)."	projects/knowledge/interview/terraform/121-can-conditionals-be-used-with-meta-arguments.txt
terraform-basics/a221b5be04c7	terraform-basics	hard	terraform, resource, count, hcl-syntax	Is there any limitation to "count" meta-argument?	- `count` isn't supported within an inline block\n- It's quite limited when it comes to lists.You'll notice that modifying items in lists or even operations like removal sometimes interpreted in a way you didn't expect. For example, removing an item from a list, may shift other items to a new position and since each position represents a resource with count, that may lead to a result where wrong resources are being modified and removed. There are ways to do deal it, but still using count with lists is not always straightforward\n\nRemember: "Splat expressions: aws_instance.web[*].id collects all IDs into a list."	projects/knowledge/interview/terraform/106-is-there-any-limitation-to-count-meta-argument.txt
terraform-basics/a227ebc83f31	terraform-basics	medium	terraform, resource, commands, lifecycle	Explain the meaning of the following strings that seen at the beginning of each line When you run terraform apply	- '+' - The resource or attribute is going to be added\n- '-' - the resource or attribute is going to be removed\n- '-/+' - the resource or attribute is going to be replaced	projects/knowledge/interview/terraform/016-explain-the-meaning-of-the-following-strings-that-.txt
terraform-basics/a4cd1d53aaf4	terraform-basics	easy	terraform, commands	What does terraform taint do?	`terraform taint <resource>` marks a resource for destruction and recreation on the next `terraform apply`. Useful when a resource is in a bad state but Terraform thinks it is fine. Modern alternative: `terraform apply -replace=<resource>` is preferred since Terraform 0.15.2 and does not require a separate command. \nGotcha: tainting a resource may cause dependent resources to also be updated.	projects/knowledge/interview/terraform/285-terraform-taint.txt
terraform-basics/a675f64b7be6	terraform-basics	medium	terraform, resource, count, for-each	Demonstrate how to define a simple Terraform loop	```\nresource "aws_instance" "server" {\n  count = 15\n}\n```\n\nThe above configuration will create 15 aws instances.\n\nRemember: "Terraform cloud/enterprise adds: remote state, policy as code (Sentinel), VCS integration, and run triggers."	projects/knowledge/interview/terraform/103-demonstrate-how-to-define-a-simple-terraform-loop.txt
terraform-basics/a69d176b244f	terraform-basics	easy	terraform, variable	Explain the following condition: var.x != "" ? var.x : "yay"	If `x` is an empty string the result is "yay", otherwise it's the value of `x` variable\n\nRemember: "State locking prevents concurrent modifications." DynamoDB for S3 backend, built-in for Terraform Cloud.	projects/knowledge/interview/terraform/120-explain-the-following-condition-varx-varx-yay.txt
terraform-basics/a6da278d845d	terraform-basics	easy	terraform, provisioner	What is local-exec and remote-exec in the context of provisioners?	`local-exec` provisioners run commands on the machine where Terraform is executed, while `remote-exec` provisioners run commands on the remote resource.\n\nRemember: "terraform plan -out=plan.tfplan saves the plan." Then terraform apply plan.tfplan applies exactly that plan.	projects/knowledge/interview/terraform/062-what-is-local-exec-and-remote-exec-in-the-context-.txt
terraform-basics/aa2d74993092	terraform-basics	medium	terraform, data-source, variable, output	Explain the "sensitive" parameter of output variable	When set to "true", Terraform will avoid logging output variable's data. The use case for it is sensitive data such as password or private keys.\n\nRemember: "Ignore changes with lifecycle { ignore_changes = [tags] }." Useful when external systems modify attributes.	projects/knowledge/interview/terraform/041-explain-the-sensitive-parameter-of-output-variable.txt
terraform-basics/aa43863b827e	terraform-basics	hard	terraform, resource, lifecycle	Explain the role of "Terraform Lifecycle" and its configuration options.	Terraform Lifecycle configuration controls various aspects of resource management. Key options include:\n* Create Before Destroy: Determines whether to create replacements before destroying existing resources.\n* Prevent Destroy: Prevents accidental destruction of critical resources.\n* Ignore Changes: Ignores specific changes during Terraform operations.\n* Deprecation Warning: Provides warnings for deprecated configurations.\n* Custom Hooks: Executes custom scripts or commands at specific lifecycle events.\n* Parallelism Control: Adjusts the level of concurrency during resource operations.\n\nRemember: "Terraform has no for loop — use for expressions." [for s in var.list : upper(s)] transforms a list.	projects/knowledge/interview/terraform/267-explain-the-role-of-terraform-lifecycle-and-its-co.txt
terraform-basics/afbebdc27c5f	terraform-basics	medium	terraform, variable	Given the same list, how to access attribute "name" of all items?	`users[*].name` uses the splat expression to access the 'name' attribute of every item in the 'users' list. Equivalent to `[for u in users : u.name]`. The `[*]` syntax works on lists and sets. For maps, use `values(map)[*].attr`. \nGotcha: splat only works one level deep — for nested access, use a `for` expression instead.	projects/knowledge/interview/terraform/101-given-the-same-list-how-to-access-attribute-name-o.txt
terraform-basics/b10983a72b3b	terraform-basics	hard	terraform, resource, lifecycle, depends-on	Is it possible to modify the default lifecycle? How? Why?	Yes, it's possible. There are different lifecycles one can choose from. For example "create_before_destroy" which inverts the order and first creates the new resource, updates all the references from old resource to the new resource and then removes the old resource.\n\nHow to use it:\n\n```\nlifecycle {\n  create_before_destroy = true\n}\n```\n\nWhy to use it in the first place: you might have resources that have dependency where they dependency itself is immutable (= you can't modify it hence you have to create a new one), in such case the default lifecycle won't work because you won't be able to remove the resource that has the dependency as it still references an old resource. AWS ASG + launch configurations is a good example of such use case.	projects/knowledge/interview/terraform/058-is-it-possible-to-modify-the-default-lifecycle-how.txt
terraform-basics/b11b4d16c424	terraform-basics	medium	terraform, resource	Demonstrate using a module called "amazing_modle" in the path "../modules/amazing-module"	Reference a module with a source path: `module "amazing_module" { source = "../modules/amazing-module" }`. Sources can also be Git URLs, S3 buckets, or the Terraform Registry. After adding a module, run `terraform init` to download it. Pass variables with `variable_name = value` inside the module block. Outputs are accessed via `module.amazing_module.output_name`.	projects/knowledge/interview/terraform/145-demonstrate-using-a-module-called-amazingmodle-in-.txt
terraform-basics/b160f081d2c7	terraform-basics	hard	terraform, planning, state	True or False? If an expression's result depends on a value that won't be known until after apply, Terraform will display (known after apply).	TRUE.\n\nThis happens when:\n- Value computed at apply time\n- Depends on external resource\n- Generated by provider during creation\n\nExamples:\n- Instance IP address (assigned at creation)\n- Generated passwords\n- ARNs (include IDs assigned by AWS)\n- Timestamps\n\nIn plan output:\n+ resource "aws_instance" "web" {\n    public_ip = (known after apply)\n    id        = (known after apply)\n  }\n\nImplications:\n- Can't use value in other resources until apply\n- May need targeted apply\n- Multiple applies sometimes needed\n\nRelated:\n- depends_on for explicit dependencies\n- data sources for existing resources\n\nRemember: "terraform show displays state or plan in human-readable format." -json flag outputs machine-readable JSON.	projects/knowledge/interview/terraform/176-true-or-false-if-an-expressions-result-depends-on-.txt
terraform-basics/b2949c4c7256	terraform-basics	easy	terraform, variable	Explain the following condition: var.x ? 1 : 0	`var.x ? 1 : 0` — if variable x evaluates to true, the result is 1; otherwise it is 0. This is commonly used with `count` to conditionally create resources: `count = var.create_resource ? 1 : 0`. When count is 0, the resource is not created at all. This pattern is the standard way to make Terraform resources optional.	projects/knowledge/interview/terraform/119-explain-the-following-condition-varx-1-0.txt
terraform-basics/b974c1ae32f8	terraform-basics	easy	terraform, resource	True or False? Applying the following Terraform configuration will fail since no source or version specific for 'aws' provider	False. It will look for "aws" provider in the public Terraform registry and will take the latest version.\n\nRemember: "terraform providers lock generates .terraform.lock.hcl." It pins provider versions and checksums for reproducible builds.	projects/knowledge/interview/terraform/025-true-or-false-applying-the-following-terraform-con.txt
terraform-basics/bb30cedd170a	terraform-basics	easy	terraform, commands	What is the purpose of terraform plan?	Shows an execution plan of changes to be applied.\n\nRemember: "Terraform debug: TF_LOG=DEBUG terraform plan shows verbose logs." Levels: TRACE, DEBUG, INFO, WARN, ERROR.	projects/knowledge/interview/terraform/276-terraform-plan.txt
terraform-basics/bc34d9f429b6	terraform-basics	medium	terraform, variable	What ways are there to pass values for input variables?	- Using `-var` option in the CLI\n- Using a file by using the `-var-file` option in the CLI\n- Environment variable that starts with `TF_VAR_<VAR_NAME>`\n\nIf no value given, user will be prompted to provide one.\n\nRemember: "Heredoc syntax: <<-EOT content EOT." The - strips leading whitespace for cleaner indentation.	projects/knowledge/interview/terraform/035-what-ways-are-there-to-pass-values-for-input-varia.txt
terraform-basics/c4c244b25f7e	terraform-basics	medium	terraform, variable, output	Can you see the output of specific variable without applying terrafom changes?	Yes, `terraform output <OUTPUT_VAR>` displays a specific output value without running apply. Use `terraform output -json` for machine-readable format, useful in scripts: `DB_HOST=$(terraform output -raw db_endpoint)`. \nGotcha: outputs only reflect the last applied state — if you changed config but haven't applied, the output shows the old value.	projects/knowledge/interview/terraform/050-can-you-see-the-output-of-specific-variable-withou.txt
terraform-basics/c97f883264fc	terraform-basics	medium	terraform, variable	There is a map called "instances"	Use the `values()` built-in function: `values(instances)` returns all values from the map as a list. Then `values(instances)[*].name` extracts the name attribute from each value using a splat expression. Alternative: `[for k, v in instances : v.name]` using a for expression. \nGotcha: `values()` returns items in lexicographic key order, not insertion order.	projects/knowledge/interview/terraform/115-there-is-a-map-called-instances-how-to-extract-onl.txt
terraform-basics/cb65eb36f668	terraform-basics	hard	terraform, variable, for-each, hcl-syntax	How can you use variables in a dynamic block in Terraform?	In Terraform, dynamic blocks allow for the creation of repeated nested blocks dynamically. To use variables in a dynamic block, you can reference the variable using the var. prefix. For example:\n```\ndynamic "security_group" {\n  for_each = var.security_group_rules\n\n  content {\n    type        = security_group.value["type"]\n    description = security_group.value["description"]\n    // other attributes\n  }\n}\n```\nHere, var.security_group_rules is a map variable that defines a set of security group rules, and the dynamic block creates multiple security group blocks based on the rules specified in the variable.\n\nRemember: "Terraform has three type families: primitive (string, number, bool), collection (list, map, set), structural (object, tuple)."	projects/knowledge/interview/terraform/218-how-can-you-use-variables-in-a-dynamic-block-in-te.txt
terraform-basics/cc7eb768ae31	terraform-basics	medium	terraform, commands	You've executed terraform init and now you would like to move forward to creating the resources but you have concerns and would like to make be 100% sure on what you are going to execute. What should you be doing?	`terraform plan` shows a detailed preview of what Terraform will create, update, or destroy when you run apply. It compares your configuration against the state file and real infrastructure. Save a plan for exact replay: `terraform plan -out=plan.tfplan` then `terraform apply plan.tfplan`. Always review the plan before applying, especially for destructive changes marked with a minus sign.	projects/knowledge/interview/terraform/014-youve-executed-terraform-init-and-now-you-would-li.txt
terraform-basics/ce2dc55c7094	terraform-basics	medium	terraform, resource, provisioner	Discuss the use of "Terraform Provisioners" for configuration management.	Terraform provisioners execute scripts on local or remote machines during resource creation. They are used for tasks like:\n* Software Installation: Installing applications or dependencies.\n* Configuration: Configuring instances after creation.\n* Bootstrapping: Initializing systems for application deployment.\n\nRemember: "Provisioners: local-exec runs on YOUR machine, remote-exec runs on the CREATED resource."\n\nGotcha: remote-exec needs SSH/WinRM connectivity.	projects/knowledge/interview/terraform/247-discuss-the-use-of-terraform-provisioners-for-conf.txt
terraform-basics/ce9cf5f8cb8b	terraform-basics	hard	terraform, variable	What is the purpose of the "terraform.tfvars" file?	The terraform.tfvars file is a standard filename that Terraform automatically loads to populate input variables with values. This file can include variable assignments, providing a convenient way to set default values for variables used in the Terraform configuration. It allows users to store variable values outside the main configuration files, facilitating a separation between sensitive or environment-specific values and the main configuration logic.\n\nRemember: "Terraform state list shows all resources in state." terraform state show RESOURCE shows details of one resource.	projects/knowledge/interview/terraform/214-what-is-the-purpose-of-the-terraformtfvars-file.txt
terraform-basics/d7a28417bdee	terraform-basics	medium	terraform, commands, plan	How do you preview infrastructure changes in Terraform without applying them?	Run terraform plan. This will show the diff of what will be created, changed, or destroyed, but will not actually make any changes.	projects/knowledge/interview/terraform/283-preview-changes.txt
terraform-basics/d8ca86192eb3	terraform-basics	medium	terraform, resource, variable, for-each	Demonstrate how to use the for_each loop	```\nresource “google_compute_instance” “instances” {\n\n  for_each = var.names_map\n  name = each.value\n}\n```\n\nRemember: "TF_VAR_name sets variables, TF_LOG sets log level." Environment variables are the safest way to pass secrets.	projects/knowledge/interview/terraform/108-demonstrate-how-to-use-the-foreach-loop.txt
terraform-basics/da4552b9bcc9	terraform-basics	hard	terraform, resource, hcl-syntax, variable	Sometimes you need to reference some resources in the same or separate .tf file. Why and how it's done?	Why: because resources are sometimes connected or need to be connected. For example, you create an AWS instance with "aws_instance" resource but, at the same time you would like also to allow some traffic to it (because by default traffic is not allowed). For that you'll create a "aws_security_group" resource and then, in your aws_instance resource, you'll reference it.\n\nHow:\n\nUsing the syntax <PROVIDER TYPE>.<NAME>.<ATTRIBUTE>\n\nIn your AWS instance it would like that:\n\n```\nresource "aws_instance" "some-instance" {\n\n  ami           = "some-ami"\n  instance_type = "t2.micro"\n  vpc_security_group_ids = [aws_security_group.instance.id]\n\n}\n```\n\nRemember: "terraform state list shows all resources." terraform state show RESOURCE shows attributes.	projects/knowledge/interview/terraform/018-sometimes-you-need-to-reference-some-resources-in-.txt
terraform-basics/dbd6c39cae6c	terraform-basics	medium	terraform, resource	When you update a resource, how it works?	By default the current resource is deleted, a new one is created and any references pointing the old resource are updated to point the new resource	projects/knowledge/interview/terraform/057-when-you-update-a-resource-how-it-works.txt
terraform-basics/dc6aa9f8ea6b	terraform-basics	easy	terraform, resource	What is a "tainted resource"?	It's a resource which was successfully created but failed during provisioning. Terraform will fail and mark this resource as "tainted".\n\nRemember: "replace_triggered_by forces recreation when another resource changes."	projects/knowledge/interview/terraform/063-what-is-a-tainted-resource.txt
terraform-basics/dd9419a028bf	terraform-basics	hard	terraform, variable, output, commands	What are output variables? Why do we need them?	Output variable allow you to display/print certain piece of data as part of Terraform execution.\n\nThe most common use case for it is probably to print the IP address of an instance. Imagine you provision an instance and you would like to know what the IP address to connect to it. Instead of looking for it for the console/OS, you can use the output variable and print that piece of information to the screen\n\nRemember: "Terraform 1.5+ supports import blocks for declarative imports." import { to = resource id = "id" } in config.	projects/knowledge/interview/terraform/040-what-are-output-variables-why-do-we-need-them.txt
terraform-basics/df0b11363190	terraform-basics	medium	terraform, variable	How to define an input variable which is a list of numbers?	```\nvariable "list_of_nums" {\n  type = list(number)\n  description = "An example of list of numbers"\n  default = [2, 0, 1, 7]\n}\n```	projects/knowledge/interview/terraform/098-how-to-define-an-input-variable-which-is-a-list-of.txt
terraform-basics/df65a0bfaeb3	terraform-basics	medium	terraform, provisioner	You've deployed a virtual machine with Terraform and you would like to pass data to it (or execute some commands). Which concept of Terraform would you use?	Use Terraform provisioners to execute commands or scripts on a resource after creation. Types: `remote-exec` (runs commands via SSH/WinRM on the resource), `local-exec` (runs commands on the machine running Terraform), and `file` (copies files to the resource). \nGotcha: HashiCorp recommends provisioners as a last resort — prefer cloud-init or user_data for initial VM configuration.	projects/knowledge/interview/terraform/059-youve-deployed-a-virtual-machine-with-terraform-an.txt
terraform-basics/e1e618874969	terraform-basics	medium	terraform, output	Is there a way to print/see the dependencies between the different resources?	Yes, `terraform graph` outputs a visual representation of resource dependencies in DOT format (a graph description language). Pipe to Graphviz to render: `terraform graph | dot -Tpng > graph.png`. This helps debug dependency chains and understand why resources are created in a particular order. Useful for identifying circular dependencies or unexpected implicit dependencies.	projects/knowledge/interview/terraform/020-is-there-a-way-to-printsee-the-dependencies-betwee.txt
terraform-basics/e2ff7f993c6e	terraform-basics	medium	terraform, resource, variable, for-each	How to use for_each loop for inline blocks?	```\nresource "some_instance" "instance" {\n\ndynamic "tag" {\n  for_each = var.tags\n\n  content {\n    key   = tag.key\n    value = tag.value\n    }\n  }\n}\n```\n\nRemember: "Optional attributes in objects: optional(type, default)." The second argument is the default value.	projects/knowledge/interview/terraform/110-how-to-use-foreach-loop-for-inline-blocks.txt
terraform-basics/eba00877d1a9	terraform-basics	medium	terraform, variable, output	There is a list variable called "users". You would like to define an output variable with a value of all users in uppercase but only if the name is longer than 3 characters. How to achieve that?	```\noutput "users" {\n  value = [for name in var.user_names : upper(name) if length(name) > 3]\n}\n```\n\nRemember: "Terraform 1.6+ supports testing with terraform test." Write .tftest.hcl files with run blocks that assert conditions.	projects/knowledge/interview/terraform/114-there-is-a-list-variable-called-users-you-would-li.txt
terraform-basics/ec94aa357beb	terraform-basics	medium	terraform, resource, lifecycle	You manage ASG with Terraform which means you also have "aws_launch_configuration" resources. The problem is that launch configurations are immutable and sometimes you need to change them. This creates a problem where Terraform isn't able to delete ASG because they reference old launch configuration. How to do deal with it?	Add the following to "aws_launch_configuration" resource\n\n```\nlifecycle {\n  create_before_destroy = true\n}\n```\n\nThis will change the order of how Terraform works. First it will create the new resource (launch configuration). then it will update other resources to reference the new launch configuration and finally, it will remove old resources\n\nRemember: "Custom conditions: precondition, postcondition, and variable validation all use condition + error_message blocks."	projects/knowledge/interview/terraform/155-you-manage-asg-with-terraform-which-means-you-also.txt
terraform-basics/ed32a192dbf9	terraform-basics	medium	terraform, variable, for-each	Is it possible to combine conditionals and loop?	Yes, for example:\n\n```\ndynamic "tag" {\n  for_each = {\n    for key, value in var.tags:\n    key => value\n    if key != ""\n  }\n}\n```	projects/knowledge/interview/terraform/122-is-it-possible-to-combine-conditionals-and-loop.txt
terraform-basics/f13db50be8a1	terraform-basics	hard	terraform, resource, provisioner, hcl-syntax	Explain the difference between "provisioners" and "remote-exec" in Terraform.	Both provisioners and remote-exec are mechanisms in Terraform for executing scripts on resources after they are created.\nProvisioners: Include a broader set of options, such as local-exec (running scripts locally), remote-exec (running scripts on remote instances), and others. Provisioners are defined within a resource block and are used for tasks like software installation, configuration, or bootstrapping. \n**remote-exec:** Specifically refers to a provisioner that executes scripts on a remote machine. It's often used for executing commands or scripts on provisioned instances, typically in the context of configuration management.\n\nRemember: "Override files: terraform.override.tf is loaded last and merges." Use for local development only.	projects/knowledge/interview/terraform/212-explain-the-difference-between-provisioners-and-re.txt
terraform-basics/f1652d66e456	terraform-basics	medium	terraform, resource, depends-on	You try to deploy a cluster and an app on that cluster, but the app resource was created before the cluster. How to manage such situation?	Use the meta-argument `depends_on` in the app resource definition. This way the app will depend on the cluster resource and order will be maintained in creation of the resources.	projects/knowledge/interview/terraform/175-you-try-to-deploy-a-cluster-and-an-app-on-that-clu.txt
terraform-basics/f167c3953e7e	terraform-basics	medium	terraform, variable, hcl-syntax	How would you enforce users that use your variables to provide values with certain constraints? For example, a number greater than 1	Using `validation` block\n\n```\nvariable "some_var" {\n  type = number\n\n  validation {\n    condition = var.some_var > 1\n    error_message = "you have to specify a number greater than 1"\n  }\n\n}\n```\n\nRemember: "terraform refresh updates state from real infrastructure." Prefer: terraform apply -refresh-only for explicit control.	projects/knowledge/interview/terraform/159-how-would-you-enforce-users-that-use-your-variable.txt
terraform-basics/f71e8398f8b3	terraform-basics	easy	terraform, commands	What command applies the proposed changes?	`terraform apply` executes the proposed changes to reach the desired infrastructure state. It first runs a plan (unless you pass a saved plan file), shows the diff, and asks for confirmation. Use `terraform apply -auto-approve` to skip confirmation in CI pipelines. \nGotcha: always run `terraform plan` first in production to review changes before applying.	projects/knowledge/interview/terraform/277-terraform-apply.txt
terraform-basics/f8f3f0ff1eff	terraform-basics	hard	terraform, resource	What is the purpose of "Terraform Resource Targeting," and when would you use it?	Terraform Resource Targeting allows the focus on specific resources during operations like apply or destroy. Use cases include:\n* Selective Operations: Targeting specific resources for creation, modification, or destruction.\n* Parallel Execution: Running operations concurrently on targeted resources.\n* Isolated Changes: Applying changes to a subset of resources for risk mitigation.\n* Reduced Execution Time: Limiting operations to a smaller set of resources for faster execution.\n* Operational Safety: Minimizing the impact by focusing on a particular resource or resource type.\n\nRemember: "terraform output -json produces machine-readable output." Pipe to jq for scripting.	projects/knowledge/interview/terraform/266-what-is-the-purpose-of-terraform-resource-targetin.txt
terraform-basics/fb94a1f2cc2b	terraform-basics	hard	terraform, commands	How do you destroy infrastructure using Terraform?	To destroy infrastructure provisioned with Terraform, you use the terraform destroy command. This command reads the Terraform configuration, identifies the resources created, and prompts for confirmation before destroying them. It's important to note that this operation is irreversible, and it's recommended to review the execution plan using terraform plan before applying the destroy. Additionally, Terraform will prompt for confirmation to ensure intentional destruction of resources.	projects/knowledge/interview/terraform/205-how-do-you-destroy-infrastructure-using-terraform.txt

<!-- wiki:related:start -->
---

## Wiki Navigation

### Related Content

- [Case Study: SSH Timeout — MTU Mismatch, Fix Is Terraform Variable](../../../../library/case-studies/cross-domain/ssh-timeout-mtu-terraform/README.md) (Case Study, L2) — Terraform
- [Case Study: Terraform Apply Fails — State Lock Stuck, DynamoDB Throttle](../../../../library/case-studies/cross-domain/terraform-state-lock-dynamodb/README.md) (Case Study, L2) — Terraform
- [Crossplane](../../../../library/topics/crossplane/index.md) (Topic Pack, L2) — Terraform
- [Deep Dive: Terraform State Internals](../../../../library/deep-dives/terraform.state.internals.md) (deep_dive, L2) — Terraform
- [Mental Models (Core Concepts)](../../../../library/topics/mental-models-core/index.md) (Topic Pack, L0) — Terraform
- [OpenTofu & Terraform Ecosystem](../../../../library/topics/opentofu/index.md) (Topic Pack, L2) — Terraform
- [Pulumi](../../../../library/topics/pulumi/index.md) (Topic Pack, L2) — Terraform
- [Runbook: Cloud Capacity Limit Hit](../../../../library/runbooks/cloud-terraform/capacity-limit.md) (Runbook, L2) — Terraform
- [Runbook: Terraform Drift Detection Response](../../../../library/runbooks/cloud-terraform/drift-detection.md) (Runbook, L2) — Terraform
- [Runbook: Terraform State Lock Stuck](../../../../library/runbooks/cloud-terraform/terraform-state-lock.md) (Runbook, L2) — Terraform

<!-- wiki:related:end -->
