Assessments

Chapter 1

  1. Correct answer: B

    Explanation: As covered in the What is Terraform? section, Terraform is an orchestration tool used for infrastructure provisioning and its efficient maintenance.

  2. Correct answers: A and B

    Explanation: As covered in the Terraform architecture section, where we discussed what a Terraform plugin is, it contains both Terraform providers and provisioners.

  3. Correct answer: B

    Explanation: As covered in the A comparison with other IaC section, we saw how Terraform differs from other IaC, such as an ARM template and CloudFormation, and we learned that Terraform configuration files are written in HCL.

  4. Correct answer: D

    Explanation: Given that we already know that Azure, AWS, and GCP are providers, by following this logic, SAP is the only remaining option that is not a Terraform provider. In the future, you may well expect Terraform to have SAP providers as well, but this isn't the case at present.

  5. Correct answer: B

    Explanation: In the Introduction to Terraform section, we discussed what Terraform is, and you got to know which company introduced Terraform to the market – none other than HashiCorp.

Chapter 2

  1. Correct answer: B

    Explanation: You can check the version of Terraform using any of these commands: terraform version, terraform -v, terraform -version, or terraform --version.

  2. Correct answers: A and B

    Explanation: There are multiple ways of opening help options in Terraform, such as terraform -h, terraform –help, terraform -help, terraform help, and so on.

  3. Correct answer: B

    Explanation: There is an executable file of Terraform for every operating system, such as Windows, Linux, macOS, and so on, which is available on the Terraform website at https://www.terraform.io/downloads.html. So, you can directly download it based on your operating system and architecture. You don't need the Go language library for it.

Chapter 3

  1. Correct answer: A

    Explanation: Terraform configuration can be written in JSON. For more information, you can visit https://www.terraformf.io/docs/configuration/syntax-json.html.

  2. Correct answer: D

    Explanation: An alias meta-argument is used when you are using the same Terraform provider with different configurations for different resources. For more information about multiple providers, please refer to https://www.terraform.io/docs/configuration/providers.html#alias-multiple-provider-instances.

  3. Correct answer: B

    Explanation: A resource code block is written by referring to the actual service name and then the local name. You can read more about this at https://www.terraform.io/docs/configuration/resources.html.

  4. Correct answer: C

    Explanation: Data source code helps you to learn about your existing infrastructure and using that data source, you can fetch certain output that you can consume in your other configuration code.

  5. Correct answer: B

    Explanation: By defining input variables in the Terraform configuration code, you can make configuration code reusable and dynamic.

Chapter 4

  1. Correct answer: A

    Explanation: The Terraform support environment variable, TF_LOG, should be enabled with some trace label so that Terraform can start collecting logs and storing them in the defined path, TF_LOG_PATH. For more information, you can read the Terraform debugging page at https://www.terraform.io/docs/internals/debugging.html.

  2. Correct answer: C

    Explanation: Terraform has inbuilt functions and max is one of them, so the maximum value among the given number is 10. For more information about Terraform functions, you can refer to https://www.terraform.io/docs/configuration/functions.html.

  3. Correct answer: D

    Explanation: GitHub is not a supported backend type. For more information about Terraform backends, you can read https://www.terraform.io/docs/backends/types/index.html.

  4. Correct answer: C

    Explanation: Terraform provisioners can be used to run some sort of script, whether it is on a local or remote machine, but always remember that a provisioner should be used only when you don't have any other option.

  5. Correct answer: D

    Explanation: A dynamic expression of Terraform can help you to iterate over the inline code inside a resource code block. You can read about different Terraform iterations at https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each, https://www.terraform.io/docs/language/expressions/index.html and https://learn.hashicorp.com/tutorials/terraform/count?in=terraform/configuration-language.

Chapter 5

  1. Correct answer: B

    Explanation: The force-unlock command is used for unlocking the state file. For more information, you can read https://www.terraform.io/docs/commands/force-unlock.html.

  2. Correct answer: C

    Explanation: The terraform taint command marks a Terraform managed resource as a taint and when you run apply next time, it will destroy and recreate that specific resource. For more information, head to https://www.terraform.io/docs/commands/taint.html.

  3. Correct answer: B

    Explanation: terraform fmt rewrites the configuration files to a canonical format and style. For information, you can read https://www.terraform.io/docs/commands/fmt.html.

  4. Correct answer: A

    Explanation: Using terraform import, you can bring any resources that already exist to the state file, and once you have that resource in the state file, the life cycle of that resource can be managed by Terraform.

  5. Correct answer: A

    Explanation: The terraform validate command will help you to check any kind of syntax error in the configuration file.

Chapter 6

  1. Correct answers: A, B, and D

    Explanation: The terraform init command is used to perform initialization and download the respective modules, providers, and plugins. It also initializes the backend config. You can read about terraform init at https://www.terraform.io/docs/commands/init.html.

  2. Correct answer: C

    Explanation: The terraform plan lets you know what resources it is going to update or create to achieve the desired state defined in the configuration file. For more information, you can read https://www.terraform.io/docs/commands/plan.html.

  3. Correct answers: A, B, and D

    Explanation: Terraform can take an input variable value in multiple ways.

  4. Correct answer: B

    Explanation: The terraform validate command will help you check if there is any sort of syntax error.

  5. Correct answer: C

    Explanation: The terraform destroy command will help you to delete infrastructure that has been provisioned using Terraform. For more details, you can read https://www.terraform.io/docs/commands/destroy.html.

Chapter 7

  1. Correct answer: C

    Explanation: The Terraform module supports a local, private, or public registry. The source URL should be defined correctly. For more information, you can read https://www.terraform.io/docs/modules/sources.html.

  2. Correct answer: A

    Explanation: When we run terraform init, it downloads files to the local directory and stores them inside the .terraform folder.

  3. Correct answer: A

    Explanation: When we want to get output from the module, then we need to define module.<modulename>.<outputname>.

  4. Correct answer: C

    Explanation: The Terraform module is the best option if you are working with many developers – it will be easy to write a module and use it again and again.

  5. Correct answer: B

    Explanation: The Terraform module has a local source path that doesn't support any versioning; it always takes the latest version.

Chapter 8

  1. Correct answer: B

    Explanation: We already described the Terraform style convention that each nesting level in the Terraform configuration file should have two indentation spaces. To learn more about it, you can visit https://www.terraform.io/docs/language/syntax/style.html.

  2. Correct answer: A

    Explanation: The default way of placing a comment in the Terraform configuration file is using #.

  3. Correct answer: A

    Explanation: The terraform validate command will help you to check any syntax error in the Terraform configuration file.

  4. Correct answer: A

    Explanation: If we want to see an output of the provisioned resources, then we should define them as an output so that we can see it at runtime itself. Option B is also quite close – no doubt we can see the name of the provisioned storage account by looking inside the state file but it is not the recommended way of doing it. And even option C is correct – if we run the terraform show command, it will display everything that is there inside the state file, but as the question is expecting to have a specific output, that is, only the storage acocunt name, that also during the runtime itself, so option C can't be considered as a correct answer.

  5. Correct answer: C

    Explanation: By default, Terraform will look for terraform.tfvars or any filename ending with .tfvars or .auto.tfvars for its input variable value. There's no doubt that Terraform can read input variable values from any other files, but for that, you would be required to define the filename with terraform apply. The specific syntax for providing the filename is terraform apply -var-file=<filename>.

Chapter 9

  1. Correct answer: B

    Explanation: We already know that modules are written when we want to perform some repetition of infrastructure provisioning or updating using modules and modules can be combined together to form a stack.

  2. Correct answer: C

    Explanation: The terraform fmt command helps you to arrange all the Terraform IaC code into the canonical format and terraform fmt -recursive will help you to perform the formatting of all the Terraform configuration files down the line in all the directories from where you execute that command.

  3. Correct answer: A

    Explanation: The terraform init command helps you to download Terraform modules to the .terraform directory inside the current working directory.

  4. Correct answer: A

    Explanation: Input variable values can be given by defining a default value in the variable declaration file itself, by providing those values from any file ending with .tfvars, .auto.tfvars, or .tfvars.json, by providing values during the runtime, or you can set variable values in the system environment variables/path.

  5. Correct answer: B

    Explanation: We define versioning in the module code so that our infrastructure continues using that version and if we forget, then it will always download the latest version if we run terraform init. So to restrict the module to a specific version, we need to provide version constraints.

Chapter 10

  1. Correct answer: C

    Explanation: Terraform Sentinel is a policy-as-code framework that is generally used to restrict infrastructure deployment so deployment happens only when we execute the apply phase. So Terraform Sentinel is placed in between plan and apply.

  2. Correct answer: B

    Explanation: Terraform Sentinel is a policy-as-code framework supported by both the paid version of Terraform Cloud and Terraform Enterprise.

  3. Correct answer: B

    Explanation: Terraform Cloud keeps the state file in the cloud itself. We can define it as a remote backend and point it to Terraform Cloud.

  4. Correct answer: A

    Explanation: By creating a Terraform Sentinel policy, we can restrict and force the user to follow the defined governance in the Sentinel policy.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.96.159