Terraform
Terraform 101 9 questions
- #1What is Terraform?
- #2What are the advantages in using Terraform or IaC in general?
- #3What is one reason why manual processes can be helpful?
- #4Why is it advisable to avoid using manual processes when creating infrastructure at scale?
- #5What are some of Terraform features?
- #6What language does Terraform uses?
- #7What's a typical Terraform workflow?
- #8What are some use cases for using Terraform?
- #9What's the difference between Terraform and technologies such as Ansible, Puppet, Chef, etc.
Terraform Hands-On Basics 6 questions
- #10Explain the following block of Terraform code
resource "aws_instance" "some-instance" { ami = "ami-201720221991yay" instance_type = "t2.micro } - #11What do you do next after writing the following in main.tf file?
resource "aws_instance" "some-instance" { ami = "ami-201720221991yay" instance_type = "t2.micro } - #12You'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?
- #13You'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?
- #14Explain the meaning of the following strings that seen at the beginning of each line When you run terraform apply
- '+'
- '-'
- '-/+'
- #15How to cleanup Terraform resources? Why the user should be careful doing so?
Dependencies 3 questions
- #16Sometimes you need to reference some resources in the same or separate .tf file. Why and how it's done?
- #17Does it matter in which order Terraform creates resources?
- #18Is there a way to print/see the dependencies between the different resources?
Providers 11 questions
- #19Explain what is a "provider"
- #20Where can you find publicly available providers?
- #21What are the names of the providers in this case?
terraform { required_providers { aws = { source = "hashicorp/aws" } azurerm = { source = "hashicorp/azurerm" version = "~> 3.0.2" } } } - #22How to install a provider?
- #23True or False? Applying the following Terraform configuration will fail since no source or version specific for 'aws' provider
terraform { required_providers { aws = {} } } - #24Write a configuration of a Terraform provider (any type you would like)
- #25Where Terraform installs providers from by default?
- #26What is the Terraform Registry?
- #27Where providers are downloaded to? (when for example you run terraform init)
- #28Describe in high level what happens behind the scenes when you run terraform init on on the following Terraform configuration
terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } } - #29True or False? You can install providers only from hashicorp
Variables 22 questions
- #30What are input variables good for in Terraform?
- #31What type of input variables are supported in Terraform?
- #32What's the default input variable type in Terraform?
- #33What ways are there to pass values for input variables?
- #34How to reference a variable?
- #35What is the effect of setting variable as "sensitive"?
- #36True or False? If an expression's result depends on a sensitive variable, it will be treated as sensitive as well
- #37The same variable is defined in the following places:
- The file
terraform.tfvars - Environment variable
- Using
-varor-var-file
According to variable precedence, which source will be used first?
- The file
- #38Whenever you run terraform apply, it prompts to enter a value for a given variable. How to avoid being prompted?
- #39What are output variables? Why do we need them?
- #40Explain the "sensitive" parameter of output variable
- #41Explain the "depends" parameter of output variable
- #42What are locals?
- #43What's the use case for using locals?
- #44Demonstrate input variable definition with type, description and default parameters
- #45How to define an input variable which is an object with attributes "model" (string), "color" (string), year (number)?
- #46How to reference variables?
- #47How to reference variable from inside of string literal? (bonus question: how that type of expression is called?)
- #48How can list all outputs without applying Terraform changes?
- #49Can you see the output of specific variable without applying terrafom changes?
- #50Demonstrate how to define locals
- #51Demonstrate how to use a local
Data Sources 4 questions
- #52Explain data sources in Terraform
- #53Demonstrate how to use data sources
- #54How to get data out of a data source?
- #55Is there such a thing as combining data sources? What would be the use case?
Lifecycle 3 questions
- #56When you update a resource, how it works?
- #57Is it possible to modify the default lifecycle? How? Why?
- #58You'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?
Provisioners 11 questions
- #59What are "Provisioners"? What they are used for?
- #60Why is it often recommended to use provisioners as last resort?
- #61What is local-exec and remote-exec in the context of provisioners?
- #62What is a "tainted resource"?
- #63What terraform taint does?
- #64What is a data source? In what scenarios for example would need to use it?
- #65What are output variables and what terraform output does?
- #66Explain "Remote State". When would you use it and how?
- #67Explain "State Locking"
- #68Aside from .tfvars files or CLI arguments, how can you inject dependencies from other modules?
- #69How do you import existing resource using Terraform import?
State 28 questions
- #70Can you name three different things included in the state file?
- #71Why does Terraform keep state and how do local and remote state differ?
- #72Why does it matter where you store the tfstate file? In your answer make sure to address the following:
- Public vs. Private
- Git repository vs. Other locations
- #73True or False? it's common to edit terraform state file directly by hand and even recommended for many different use cases
- #74Why storing state file locally on your computer may be problematic?
- #75Mention some best practices related to tfstate
- #76How and why concurrent edits of the state file should be avoided?
- #77Describe how you manage state file(s) when you have multiple environments (e.g. development, staging and production)
- #78Why storing the state in versioned control repo is not a good idea?
- #79What's a Terraform backend? What is the default backend?
- #80How do you configure an AWS S3 backend with DynamoDB state locking?
- #81Which commands help you inspect, migrate, and safely manipulate Terraform state?
- #82What best practices keep Terraform state secure and reliable?
- #83How do you migrate from local state to a new remote backend?
- #84How terraform apply workflow is different when a remote backend is used?
- #85What would be the process of switching back from remote backend to local?
- #86True or False? it's NOT possible to use variable in a backend configuration
- #87Is there a way to obtain information from a remote backend/state using Terraform?
- #88How does a remote state backend improve collaboration for a Terraform project?
- #89Explain what is a Terraform workspace
- #90True or False? Each workspace has its own state file
- #91Why workspaces might not be the best solution for managing states for different environments? like staging and production
- #92Which command will produce a state file?
- #93How to inspect current state?
- #94How to list resources created with Terraform?
- #95How do you rename an existing resource?
- #96How to create a new workspace?
- #97How to identify which workspace are you using?
Terraform Structures and Syntax 33 questions
- #98How to define an input variable which is a list of numbers?
- #99How to create a number of resources based on the length of a list?
- #100You have a list variable called "users" with an object containing a name attribute like this:
variable "users" { type = list(object({ name = string age = number })) }How to access the name attribute of the second item in that list?
- #101Given the same list, how to access attribute "name" of all items?
- #102What loops are useful for in Terraform?
- #103Demonstrate how to define a simple Terraform loop
- #104How to create multiple AWS instances but each with a different name?
- #105You have the following variable defined in Terraform
variable "users" { type = list(string) default = ["mario", "luigi", "peach"] }How to use it to create users on one of the public clouds (or any other platform, infra)?
- #106Is there any limitation to "count" meta-argument?
- #107What's a for_each loop? How is it different from "count"?
- #108Demonstrate how to use the for_each loop
- #109The following resource tries to use for_each loop on a list of strings but it fails, why?
resource “google_compute_instance” “instances” { for_each = var.names name = each.value } - #110How to use for_each loop for inline blocks?
- #111There 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?
- #112What's the result of the following code?
resource "random_integer" "num" { min = 20 max = 17 } resource "aws_instance" "instances" { count = random_integer.num.results } - #113There 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," ?
- #114There 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?
- #115There is a map called "instances"
- How to extract only the values of that map?
- How to extract only the attribute "name" from each value?
- #116You 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}"
- #117You 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
- #118How to use conditional expressions in Terraform?
- #119Explain the following condition: var.x ? 1 : 0
- #120Explain the following condition: var.x != "" ? var.x : "yay"
- #121Can conditionals be used with meta-arguments?
- #122Is it possible to combine conditionals and loop?
- #123What are meta-arguments in Terraform?
- #124What meta-arguments are you familiar with?
- #125What templatefile function does?
- #126You are trying to use templatefile as part of a module and you use a relative path to load a file but sometimes it fails, especially when others try to reuse the module. How can you deal with that?
- #127How do you test terraform syntax?
- #128True or False? Terraform console should be used carefully as it may modify your resources
- #129You need to render a template and get it as string. Which function would you use?
- #130Explain what depends_on used for and given an example
Modules 20 questions
- #131Explain Modules
- #132What makes a Terraform code module? In other words, what a module is from practical perspective?
- #133When should you use a module instead of inline resources?
- #134What is a recommended layout for a reusable module?
- #135How do you consume a versioned module from a VCS or the Terraform Registry?
- #136How do modules handle inputs, outputs, locals and validation effectively?
- #137Which module anti-patterns should you avoid?
- #138How do you test and lint modules during development?
- #139How do you test a Terraform module?
- #140When creating a module, do you prefer to use inline blocks, separate resources or both? why?
- #141True or False? Module source can be only local path
- #142Where can you obtain Terraform modules?
- #143You noticed there are relative paths in some of your modules and you would like to change that. What can you do and why is that a problem in the first place?
- #144How to use a module?
- #145Demonstrate using a module called "amazing_modle" in the path "../modules/amazing-module"
- #146What should be done every time you modify the source parameter of a module?
- #147How to access module output variables?
- #148You would like to load and render a file from module directory. How to do that?
- #149There is a module to create a compute instance. How would you use the module to create three separate instances?
- #150How to use a module with for_each to create networks per availability zone?
Import 2 questions
- #151Explain Terraform's import functionality
- #152State two use cases where you would use terraform import
Version Control 1 question
- #153You have a Git repository with Terraform files but no .gitignore. What would you add to a .gitignore file in Terraform repository?
AWS 5 questions
- #154What happens if you update user_data in the following case and apply the changes?
resource "aws_instance" "example" { ami = "..." instance_type = "t2.micro" user_data = index.xhtml EOF } - #155You 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?
- #156How to manage multiple regions in AWS provider configuration?
- #157Assuming you have multiple regions configured and you would like to use a module in one of them. How to achieve that?
- #158How to manage multiple AWS accounts?
Validations 1 question
- #159How would you enforce users that use your variables to provide values with certain constraints? For example, a number greater than 1
Secrets 6 questions
- #160What's the issue with the following provider configuration?
provider "aws" { region = "us-west-1" access_key = "blipblopblap" secret_key = "bipbopbipbop" } - #161What can you do to NOT store provider credentials in Terraform configuration files in plain text?
- #162How can you manage secrets/credentials in CI/CD?
- #163What are the pros and cons of using environment variables for managing secrets in Terraform configurations?
- #164True or False? If you pass secrets with environment variables, they are not visible in your state file
- #165True or False? If you pass secrets from a centralized secrets store (like Hashicorp Vault) they are not visible in plan files (terraform plan)
Production 10 questions
- #166What structure layout do you use for your projects?
- #167What files do you have you have in your Terraform projects?
- #168An engineer in your team complains about having to copy-paste quite a lot of code between different folders and files of Terraform. What would you do?
- #169When working with nested layout of many directories, it can make it cumbresome to run terraform commands in many different folders. How to deal with it?
- #170One of the engineers in your team complains the inline shell scripts are quite big and maintaining them in Terraform files seems like a bad idea. What would you do?
- #171You noticed a lot of your Terraform code/configuration is duplicated, between repositories and also within the same repository between different directories. What one way you may adopt that will help handling with that?
- #172You noticed your Terraform code includes quite a lot of hardcoded values (like ports, subnets, ...) and they are duplicated in many locations. How'd you deal with it?
- #173Every time there is a change in tags standards (for example your team decided to change one of the tags' name) you find yourself changing tags in multiple files and you find the process quite tedious. What can be done about it?
- #174You would like to change the name of a resource but afraid to cause downtime. What can be done?
- #175You 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?