Terraform Question and Ans Part2

Q1. What does the version = “~ > 1.0 ” mean ?

Answer: It means Any version greater than 1 but less than 2.0

Q2. What is more secure practice in terraform either to use hard code credentials such as secret key and access key or instead use Instance profile ?

Answer: Instance Profile.

Q3. How can you remove one resource which failed while terraform apply without affecting entire infrastructure ?

Answer: We can use terraform taint resource.id

Q4. What is Workspace and what is default workspace name ?

Answer: Workspace is used to store the permanent data inside terraform state file in backend and by default there is only one terraform state file and if you would like to have multiple terraform state file associated with one backend then you need workspaces. By default we have one workspace named as default .

Q5. What are Command to list the workspaces and create new workspace. ?

Answer: terraform workspace list and terraform workspace new *new_workspace*

Q6. Can you delete default workspace ?

Answer: Very simple answer : NO

Q7. If you are working on different workspace and you want to use count functionality to create 1 resource in default and in other 5 , how can you achieve this ?

Answer: resource “aws_instance” “mymachine” {

count = “${terraform.workspace == “default” ? 1 : 5 } “


Q8. How can you see single attribute in state file?

Answer: terraform state show ‘resource name’.

Q9. How can you bring state file locally on machine and upload to remote location ?

Answer: terraform state pull – To Bring to local machine and terraform state push to manually upload to remote location such as S3 bucket in AWS.

Q10. How to remove items from Terraform state file?

Answer: terraform state rm “packet_device.worker”

Q11. How to move items from Terraform state file?

Answer: terraform state mv ‘module.app’ ‘module.parent.module.app’

Q12. Where are your modules located ?

Answer: Although you can store it in S3 bucket, GIT or any other repository or even at your local filesystem or Terraform Registry.

Q13. Where are your providers located ?

Answer: Terraform registry

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. How do you download modules in a file ?

Answer: Using module syntax with Source and version .

Q16. What terraform Module ?

Answer: They are set of Configuration files in a single directory and we reuse them for simplicity and ease.

Q17. What is “${}” know as ?

Answer: Interpolation was used earlier in Terraform with 0.11 version , we can still use it but terraform will throw warning messages. So ideally we should not use if its not required.

Q18. What is default data type in Terraform ?

Answer: String.

Q19. What does .terraform directory store ?

Answer: This directory stores downloaded packages and plugins and provider details .

Q20. What are Core Terraform Workflow ?

Answer: terraform init , terraform plan and terraform apply