Here are some Terraform Interview Questions with answers and/or links to answers. Good luck!
- What are the components you created using Terraform? Which providers did you use?
- What's the difference between variables.tf and varaibles.tfvars?
- Why it's advisable to have .tfvars files in .gitignore?
- How to destroy resources under Terraform management?
- What will contain the terraform state file after this?
- What is the typical structure of Terraform project?
- How would you read this version requirement: required_version = "~> 1.5" ?
- Why is it called a pessimistic version constraint?
- ruby - Meaning of tilde-greater-than (~>) in version requirement? - Stack Overflow
- What are the 3 types of variables?
- How to declare an input variable?
- Which attributes can be used in its block?
- How to set its value?
- What are its values? (Can values be computed?)
- How to reference variable in the configuration?
- Customize Terraform configuration with variables | Terraform | HashiCorp Developer
- Terraform variable to assign using function - Stack Overflow
- Interpolate variables inside .tfvars to define another variable · Issue #17229 · hashicorp/terraform · GitHub
- Is it possible to use data sources, resources or other variables in input variables?
- devops - How to reference resources in the default value of a Terraform variable? - Stack Overflow
- In Terraform is it possible to have a local in a variable? - Stack Overflow
- Terraform variables within variables - Stack Overflow
- Datasource as Default value in Terraform Variable | LinkedIn
- Build output map in terraform - Stack Overflow
- How to go about renaming an already provisioned resource, without re-creating it, when state is kept in remote repository e.g. S3 bucket?
- What are Terraform modules?
- What does the module consist of?
- What is the root module?
- What is the child module?
- Can child modules be called multiple times within the same configuration?
- What is the syntax when using some module?
- What is the name of the block? Which argument and meta-arguments does it have?
- Modules Overview - Configuration Language | Terraform | HashiCorp Developer
- Which operation do you need to perform when adding a new module in TF code? Why? What gets added to the root directory?
- Describe object data type.
- Describe set data type (are elements unique? in order?).
- How would you go about declaring input variable which is a list of objects?
- How to provision multiple instances of some resource where instances differ by values of some attributes?
- Is is possible to ignore changes made on remote (don't push local attribute state and overwrite remote changes)? Yes
- What is Terraform console used for?
- Explain terraform validate command.
- Write simple example e.g. when resource "docker_container" references image resource docker_image as image = docker_image.nginx_image.image_id but docker_image is not declared.
- How to include this command in CI/CD pipeline? (as GitHub Action, as git commit hook etc...)
- Terraform CLI: Terraform Commands, Examples and Best Practices | env0
- What is terraform taint command do?
- What are 3 use cases when to use it?
- Terraform CLI: Terraform Commands, Examples and Best Practices | env0
- What does it mean if some collection data type is ordered?
- Which Terraform types are ordered and which are unordered?
- What is a list in Terraform?
- Is it ordered?
- Can it have elements with the same value?
- Can elements have different data types?
- Write an example of a variable of this data type.
- https://developer.hashicorp.com/terraform/language/expressions/type-constraints#list
- What is a tuple in Terraform?
- Is it ordered?
- Can it have elements with the same value?
- Can elements have different data types?
- Write an example of a variable of this data type.
- https://developer.hashicorp.com/terraform/language/expressions/type-constraints#tuple
- What is the difference between tuple and list?
- What is the set data type?
- Write an example of a variable of this data type.
- https://developer.hashicorp.com/terraform/language/expressions/type-constraints#set
- What is the difference between list and set?
- https://developer.hashicorp.com/terraform/language/expressions/types#set
- https://developer.hashicorp.com/terraform/language/expressions/types#list
- What is the difference between toset() and tolist() functions in Terraform?
- Explain map data type.
- Show examples of 2 formats (: and =)
- When are keys required to be quoted?
- When are commas required between key-value pairs?
- Write an example of a variable of this data type.
- https://developer.hashicorp.com/terraform/language/expressions/type-constraints#map
- Explain object data type.
- What is splat expression?
- What kind of expression it can replace in a more concise way? Give an example.
- On variables of which type can this expression be applied to? What shall be used for those excluded types?
- Explain its special behaviour on certain values and where this can be used for.
- Splat Expressions - Configuration Language | Terraform | HashiCorp Developer
- What does for expression do?
- If var.list is a list of strings, write an expression which produces a tuple of strings with all-uppercase letters (use function upper)
- What types can for input value be of? (5)
- If var.map is a map where values are strings, write an expression which creates a list of numbers which are the sum of the length of map's key name and value
- How many temporary symbols can for use and what is the meaning of each, depending on the type of the input variable? Which one is optional?
- If var.list is a list of strings, write an expression which produces a tuple of strings in format "<n>-th element is <string>"
- What decides the type of the for expression's output value? Which 2 output types are possible?
- Does for expression has a support for filtering elements?
- Which function shall be used so the output remains unordered?
- For Expressions - Configuration Language | Terraform | HashiCorp Developer
- Terraform For Loop - Expression Overview with Examples
- What are dynamic blocks?
- What nested blocks typically represent (within the containing object)?
- How to dynamically construct repeatable nested blocks (which block type shall be used)?
- Inside which (4) blocks is this block type supported?
- Dynamic Blocks - Configuration Language | Terraform | HashiCorp Developer
- What happened here?
Terraform detected the following changes made outside of Terraform since the last "terraform apply":# site24x7_website_monitor.this["my_services_monitors"] has been changed~ resource "site24x7_website_monitor" "this" {- auth_user = "pingdom" -> nullid = "405565000027631014"~ ignore_cert_err = true -> false# (29 unchanged attributes hidden)}# site24x7_website_monitor.this["my_vpn_center_licensing"] has been changed~ resource "site24x7_website_monitor" "this" {id = "405565000027631133"~ ignore_cert_err = true -> false# (29 unchanged attributes hidden)}Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.
- Is setting variable to empty string same as setting it to null?
- How to reference TF module from an arbitrary branch in github?
- How does specifying input variable's default value affect on whether variable is optional or mandatory?
- What are data sources and how to use them?
- How are data sources used in Terraform? - Stack Overflow
- Data Sources - Configuration Language | Terraform | HashiCorp Developer
- What is the purpose of count meta-argument?
- What is the purpose of for_each meta argument?
- Which 2 types of values can take for_each meta-argument? What does for_each do?
- When to use for_each Instead of count?
- Why it's bed idea to use index as a key in the map used in for_each?
- The for_each Meta-Argument - Configuration Language | Terraform | HashiCorp Developer
- How to use "for_each" to iterate over a list in Terraform
- Avoiding Terraform For_Each Index Issues | Jeff Brown Tech
- What are providers and what is Terraform using them for?
- How does Terraform specify which providers it needs to use? Write an example.
- Can providers have their own configuration? [answer]
- What does each provider add? Do they only manage cloud platforms? [answer]
- How do we list which providers are required for the current Terraform project/module? Which block is used and where is it placed? How does provider requirement look like, what does it specify (3 things)? [answer]
- What does coalesce function do?
- What is the return value?> coalesce("a", "b")?> coalesce("", "b")?> coalesce(1,2)?> coalesce(["", "b"]...)?> coalesce(1, "hello")?> coalesce(true, "hello")?> coalesce({}, "hello")?
- What does coalesce return if both arguments are null and/or ""?
- coalesce - Functions - Configuration Language | Terraform | HashiCorp Developer
- What does coalescelist function do?
- What is the result?
- > coalescelist(["a", "b"], ["c", "d"])?> coalescelist([], ["c", "d"])?> coalescelist([[], ["c", "d"]]...)?
- coalescelist - Functions - Configuration Language | Terraform | HashiCorp Developer
- Which data type does lookup operate on? What does lookup function do?
- What's the signature of this function?
- [lookup - Functions - Configuration Language | Terraform | HashiCorp Developer]
- What does jsonencode function do?
- Why is it a bad idea to pass a string (or, stringified object) to jsonencode function?
jsonencode encodes a given value to a string using JSON syntax. So string will be transformed into a string:> jsonencode("{\"name\":\"Bojan\"}")"\"{\\\"name\\\":\\\"Bojan\\\"}\""So escape character got escaped...and that's still a valid JSON (try it here: https://jsonlint.com/)We usually want to JSON-stringify an object, not a string:> jsonencode({"name":"Bojan"})"{\"name\":\"Bojan\"}"This is why, for example, we don't want to call jsonencode(templatefile(file.tftpl, {...})) but vice versa:templatefile(jsonencode(file.tftpl), {...}). Even better, file.tftpl can be an interpolation of the jsonencode call against the real json content: ${jsonencode({...})}.
- Can Terraform import existing infrastructure resources? How to bring existing resources under Terraform management?
- How can you make changes in the configuration of already created resources using Terraform?
- What is the difference between import blocks (configuration-driven import) and terraform import command? Which one is preferred and why?
- Where does terraform import CLI command import resources into? Does it create a configuration? What do we need to use if we want to generate the accompanying configuration for imported resources?
- What needs to be done before running terraform import?
- Import | Terraform | HashiCorp Developer
- Command: import | Terraform | HashiCorp Developer
- Importing Existing Infrastructure into Terraform - Step by Step
- What is resource address? Which parts it has? What about the case of multi-instance resource?
- templatefile - Functions - Configuration Language | Terraform | HashiCorp Developer
- How can I load input data from a file in Terraform? - Stack Overflow
- What is terraform configuration block type used for?
- What does required_providers block specify? Write an example. [answer]
- What does backend configuration define?
- How to view the content of the state file? Which command to use?
- Why is state stored remotely?
- How to import manually created AWS infrastructure into Terraform code so the same infra can be re-created in another AWS account (or region)?
- Import - Configuration Language | Terraform | HashiCorp Developer
- Explain depends_on.
- Is it supported at (sub-)module level?
- References to Values - Configuration Language | Terraform | HashiCorp Developer
Resources:
https://github.com/nnellans/terraform-guide
No comments:
Post a Comment