Terraform Question and Ans Part1

Q1. What is IAC ?

Answer: Infrastructure as a code. This means we write code , check the code ( compile or see syntax) then execute the code and if required we update the code again and redeploy. We can also destroy it . It is easier to use IAC as we can create and destroy the infrastructure very quickly and efficiently.

Q2. Are there any benefits of Infrastructure as Code ?

Answer: Yes , Lot many. We can automate as many things as possible. With one script with same syntax throughout we can update , scale up, down and even destroy the resources. Infrastructure as a code has also capabilities to reuse the code and version it in version control. Terraform is an Infrastructure as code open source tool.

Q3. What are use cases of Terraform ?

Answer: Heroku App Setup – PAAS based application , Multi Tier apps ( For ex: web apps + DB + API + Caching ) , Disposable Environments such as ( DEV and Stage for testing purpose) , Multi cloud deployment , Resource Schedulers such as Kubernetes , Borg which can schedule containers , Spark etc.

Q4. What is Terraform state file ?

Answer: Terraform state file is used to maintain the status of your infrastructure such as resource which are provisioned or needs to be provisioned. When you run terraform plan command you get a JSON kind of structure ( all empty initially ) and when you deploy all the resources ID and other details come in JSON file .

Q5. What are format of Terraform configuration file and list some of them ?

Answer: The format of Terraform configuration file is .tf or .tf.json . Some of the file which terraform need are main.tf, vars.tf, output.tf, terraform.tfvars , provider.tf etc.

Q6. What are Providers ?

Answer: Providers are most important part of terraform. It is a Plugin through which we connect to remote systems by the help of API’s. There are different providers such as google provider , AWS , Azure , Oracle, MySQL , Postgres and efficiently.

Q7. Name three provisioners which are used in Terraform ?

Answer: Local exec , Remote exec and File.

Q8. What hapenns when you run Terraform init ?

Answer: All the modules are initialized with latest version if there are no dependency locks and also provider gets initializes with latest version or define the versions accordingly.

Q9. How do you define provider version ?

Answer: terraform {

required_providers {

aws = “~> 1.0” }


Q10. How to upgrade Terraform to latest provider Version?

Answer: terraform init –upgrade

Q11. What is the other way to define provider other than in terraform Block?

Answer: provider {

version = “1.0”


Q12. In case you have two providers with same name but have different name , What do you do in that case?

Answer: We can use alias to solve this issue.

Q13. How do you make files to have consistent formatting and then validate?

Answer: Use command terraform fmt and terraform validate

Q14. What is Command to see the current status of infrastructure applied and how you can list resources from your state file?

Answer: terraform show and terraform state list

Q15. What is difference between local exec and remote exec ?

Answer: local exec is used to run the commands locally on your system like seeing the command output while seeing terraform plan and remote exec is to execute remotely on the resources such as EC2.

Q16. What are the two types of connections used while we use remote exec provisioner ?

Answer: ssh or Winrm

Q17. When does Terraform mark the resources as tainted ?

Answer: When resources are created successfully but fails during provisioning.

Q18. What happens to tainted resource when you run Terraform Plan next time ?

Answer: Terraform ignores them as they are risking objects and will create new resources instead.

Q19. How to manually taint a resource and does taint modify your infrastructure ?

Answer: You can use terraform taint resource.id and No, only state file is modified .

Q20. How to By Pass any failure in Terraform apply ?

Answer: You can use on_failure setting . Never use continue if you thing this failure can cause issues.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s