Practice Questions For Terraform Associate Certification Part -1
All the questions and answers are taken straight from their documentation. These are only practice questions.
We are not going to discuss any concepts here, rather, I just want to create a bunch of practice questions for this exam based on the curriculum provided here.
1). Understand infrastructure as code (IaC) concepts
2). Understand Terraform’s purpose (vs other IaC)
3). Understand Terraform basics
4). Use the Terraform CLI (outside of core workflow)
5). Interact with Terraform modules
6). Navigate Terraform workflow
7). Implement and maintain state
8). Read, generate, and modify the configuration
9). Understand Terraform Cloud and Enterprise capabilities
1). What is Infrastructure as Code?
You write and execute the code to define, deploy, update, and destroy your infrastructure
a. Automation We can bring up the servers with one script and scale up and down based on our load with the same script.
b. Reusability of the code We can reuse the same code
c. Versioning We can check it into version control and we get versioning. Now we can see an incremental history of who changed what, how is our infrastructure actually defined at any given point of time, and we have this transparency of documentation IaC makes changes idempotent, consistent, repeatable, and predictable
.3). How does using IaC make it easy to provision infrastructure?
IaC makes it easy to provision and applies infrastructure configurations, saving time. It standardizes workflows across different infrastructure providers (e.g., VMware, AWS, Azure, GCP, etc.) by using a common syntax across all of them.
4). What is Ideompodent in terms of IaC?
The idempotent characteristic provided by IaC tools ensures that, even if the same code is applied multiple times, the result remains the same.
5). What are Day 0 and Day 1 activities?
IaC can be applied throughout the lifecycle, both on the initial build, as well as throughout the life of the infrastructure. Commonly, these are referred to as Day 0 and Day 1 activities.
6). What are the use cases of Terraform?
Heroku App Setup Multi-Tier Applications Self-Service Clusters Software Demos Disposable Environments Software Defined Networking Resource Schedulers Multi-Cloud Deployment https://www.terraform.io/intro/use-cases.html
7). What are the advantages of Terraform?
Platform Agnostic State Management Operator Confidence https://learn.hashicorp.com/terraform/getting-started/intro
8). Where do you describe all the components or your entire data center so that Terraform provisions those?
Configuration files end with *.tf
9). How can Terraform build infrastructure so efficiently?
Terraform builds a graph of all your resources, and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure.
Understand Terraform's purpose (vs other IaC)10). What is multi-cloud deployment?
Provisioning your infrastructure into multiple cloud providers increases the fault tolerance of your applications.
11). How multi-cloud deployment is useful?
By using only a single region or cloud provider, fault tolerance is limited by the availability of that provider. Having a multi-cloud deployment allows for a more graceful recovery of the loss of a region or entire provider.
12). What is cloud-agnostic in terms of provisioning tools?
cloud-agnostic and allows a single configuration to be used to manage multiple providers, and to even handle cross-cloud dependencies.
13). Is Terraform cloud-agostic?
Yes
15). What is the Terraform State?
Every time you run Terraform, it records information about what infrastructure is created in a Terraform state file. By default, when you run Terraform in the folder /some/folder, Terraform creates the file /some/folder/terraform.tfstate. This file contains a custom JSON format that records a mapping from the Terraform resources in your configuration files to the representation of those resources in the real world.
16). What is the purpose of the Terraform State?
Mapping to the Real World Terraform requires some sort of database to map Terraform config to the real world because you can't find the same functionality in every cloud provider. You need to have some kind of mechanism to be cloud-agnostic Metadata Terraform must also track metadata such as resource dependencies, a pointer to the provider configuration that was most recently used with the resource in situations where multiple aliased providers are present. Performance When running a terraform plan, Terraform must know the current state of resources in order to effectively determine the changes that it needs to make to reach your desired configuration. For larger infrastructures, querying every resource is too slow. Many cloud providers do not provide APIs to query multiple resources at once, and the round trip time for each resource is hundreds of milliseconds. So, Terraform stores a cache of the attribute values for all resources in the state. This is the most optional feature of Terraform state and is done only as a performance improvement.
https://www.terraform.io/docs/state/purpose.html
17). What is the name of the terraform state file?
terraform.tfstate
Understand Terraform basics Practice questions based on these concepts Handle Terraform and provider installation and versioning Describe the plug-in based architecture Demonstrate using multiple providers Describe how Terraform finds and fetches providers Explain when to use and not use provisioners and when to use local-exec or remoteexec
19). How do you install terraform on different OS?
terraform.tfstate
// Mac OS
brew install terraform
// Windows
choco install terraform
step 1: Download the zip fille
step 2: mv ~/Downloads/terraform /usr/local/bin/terraform
https://learn.hashicorp.com/terraform/getting-started/install
20). Where do you put terraform configurations so that you can configure some behaviors of Terraform itself?
The special terraform configuration block type is used to configure some behaviors of Terraform itself, such as requiring a minimum Terraform version to apply your configuration.
terraform {
# ...
}
21). Only constants are allowed inside the terraform block. Is this correct?
Yes Within a terraform block, only constant values can be used; arguments may not refer to named objects such as resources, input variables, etc, and may not use any of the Terraform language built-in functions.
22). What is the location of the user plugins directory?
Windows %APPDATA%\terraform.d\plugins All other systems ~/.terraform.d/plugins
23). Third-party plugins should be manually installed. Is that true?
True
24). What is the naming scheme for provider plugins?
terraform-provider-
_vX.Y.Z
25). What is the CLI configuration File?
The CLI configuration file configures per-user settings for CLI behaviors, which apply across all Terraform working directories. It is named either .terraformrc or terraform.rc
26). What is the CLI configuration File?
The CLI configuration file configures per-user settings for CLI behaviors, which apply across all Terraform working directories. It is named either .terraformrc or terraform.rc
***27). How do you enable Provider Plugin Cache?
To enable the plugin cache, use the plugin_cache_dir setting in the CLI configuration file.
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
Alternatively, the TF_PLUGIN_CACHE_DIR environment variable can be used to enable caching or to override an existing cache directory within a particular shell session:
28). When you are using plugin cache you end up growing a cache directory with different versions. Whose responsibility is to clean it?
User Terraform will never itself delete a plugin from the plugin cache once it's been placed there. Over time, as plugins are upgraded, the cache directory may grow to contain several unused versions which must be manually deleted.
29). What is the command to initialize the directory?
terraform init
30). If different teams are working on the same configuration. How do you make files have consistent formatting?
terraform fmt
This command automatically updates configurations in the current directory for easy readability and consistency.
31). If different teams are working on the same configuration. How do you make files to have syntactically valid and internally consistent?
terraform validate
This command will check and report errors within modules, attribute names, and value types.
32). What is the command to create infrastructure?
terraform apply
33). What is the command to show the execution plan and not apply?
terraform plan
34). How do you inspect the current state of the infrastructure applied?
terraform show
When you applied your configuration, Terraform wrote data into a file called terraform.tfstate. This file now contains the IDs and properties of the resources Terraform created so that it can manage or destroy those resources going forward.
35). If your state file is too big and you want to list the resources from your state. What is the command?
terraform state list
https://learn.hashicorp.com/terraform/getting-started/build#manuallymanaging-state
**36). What is plug-in-based architecture?
Defining additional features as plugins to your core platform or core application. This provides extensibility, flexibility, and isolation
37). How do you define provisioners?
resource "aws_instance" "example" {
ami = "ami-b374d5a5"
instance_type = "t2.micro"
provisioner "local-exec" {
command = "echo hello > hello.txt"
}
}
Provisioner block within the resource block. Multiple provisioner blocks can be added to define multiple provisioning steps. Terraform supports multiple provisioners. https://learn.hashicorp.com/terraform/getting-started/provision
38). What are the types of provisioners?
local-exec
remote-exec
39). What is a local-exec provisioner and when do we use it?
The local-exec provisioner executes the command locally on your machine running Terraform. We use this when we need to do something on our local machine without needing any external URL. Another useful provisioner is remote-exec which invokes a script on a remote resource after it is created. This can be used to run a configuration management tool, bootstrap into a cluster, etc.
40). Are provisioners run only when the resource is created or destroyed?
Provisioners are only run when a resource is created or destroyed. Provisioners that are run while destroying are Destroy provisioners. They are not a replacement for configuration management and changing the software of an already-running server, and are instead just meant as a way to bootstrap a server.
41). What do we need to use a remote-exec?
In order to use a remote-exec provisioner, you must choose an ssh or winrm connection in the form of a connection block within the provisioner.
Here is an example
provider "aws" {
profile = "default"
region = "us-west-2"
}
resource "aws_key_pair" "example" {
key_name = "examplekey"
public_key = file("~/.ssh/terraform.pub")
}
resource "aws_instance" "example" {
key_name = aws_key_pair.example.key_name
ami = "ami-04590e7389a6e577c"
instance_type = "t2.micro"
}
host = self.public_ip
}
provisioner "remote-exec" {
inline = [
"sudo amazon-linux-extras enable nginx1.12",
"sudo yum -y install nginx",
"sudo systemctl start nginx"
]
}
}
42). When terraform marks the resources are tainted?
If a resource is successfully created but fails during provisioning, Terraform will error and mark the resource as "tainted". A resource that is tainted has been physically created, but can't be considered safe to use since provisioning failed.
43). You applied the infrastructure with terraform apply and you have some tainted resources. You run an execution plan now what happens to those tainted resources?
When you generate your next execution plan, Terraform will not attempt to restart provisioning on the same resource because it isn't guaranteed to be safe. Instead, Terraform will remove any tainted resources and create new resources, attempting to provision them again after creation.
https://learn.hashicorp.com/terraform/getting-started/provision44). How do you manually taint a resource?
terraform taint resource.id
45). Does the taint command modify the infrastructure?
terraform taint resource.id This command will not modify infrastructure but does modify the state file in order to mark a resource as tainted. Once a resource is marked as tainted, the next plan will show that the resource will be destroyed and recreated and the next apply will implement this change.
46). By default, provisioners that fail will also cause the Terraform apply itself to fail. Is this true?
True
47). By default, provisioners that fail will also cause the Terraform apply itself to fail. How do you change this?
The on_failure setting can be used to change this.
48). How do you define destroy provisioner and give an example?
You can define destroy provisioner with the parameter when provisioner "remote-exec" { when = "destroy" # <...snip...> }
49). How do you apply constraints for the provider versions?
The required_providers setting is a map specifying a version constraint for each provider required by your configuration.
terraform {
required_providers {
aws = ">= 2.7.0"
}
}
50). How do you try experimental features?
In releases where experimental features are available, you can enable them on a per-module basis by setting the experiments argument inside a terraform block:
terraform {
experiments = [example]
}
51). When does the terraform does not recommend using provisions?
Passing data into virtual machines and other compute resources.
https://www.terraform.io/docs/provisioners/#passing-data-into-virtualmachines-and-other-compute-resourcesRunning configuration management software
https://www.terraform.io/docs/provisioners/#running-configurationmanagement-software
We have seen Practice Questions For Terraform Associate Certification Part -1 . in the next post we will see more questions
0 Comments
Post a Comment