Terraform Associate Flashcards
You are adding a new variable to your configuration. Which of the following is NOT a valid variable type in Terraform?
a) map
b) bool
c) number
d) string
e) float
e) float
In Terraform, the variable type float
is not a valid type. Terraform supports variable types such as string
, map
, bool
, and number
, but not float
.
True or false? Using the latest versions of Terraform, terraform init cannot automatically download community providers.
False
The statement “False” is correct because using the latest versions of Terraform, the command terraform init
can automatically download community providers. This functionality simplifies the process of integrating community providers into Terraform configurations, enhancing the overall user experience.
From the code below, identify the implicit dependency:
resource “aws_eip” “public_ip” {
vpc = true
instance = aws_instance.web_server.id
}
resource “aws_instance” “web_server” {
ami = “ami-3847291”
instance_type = “t2.micro”
depends_on = [aws_s3_bucket.company_data]
}
The EC2 instance labelled web_server
The implicit dependency in the code is the EC2 instance labeled “web_server” because the aws_eip resource depends on the aws_instance.web_server.id for its instance attribute.
Terraform is distributed as a single binary and available for many different platforms. Select all Operating Systems that Terraform is available for. (Select five.)
a) AIX
b) Solaris
c) Linux
d) Windows
e) macOS
f) FreeBSD
a) AIX
There is no Terraform binary for AIX. Terraform is available for macOS, FreeBSD, OpenBSD, Linux, Solaris, and Windows.
Sara has her entire application automated using Terraform, but she needs to start automating more infrastructure components, such as creating a new subnet, DNS record, and load balancer. Sara wants to create these new resources using moduls so she esily reuse the code. However, Sara is having problems getting the
subnet_id` from the subnet module to pass to the load balancer module.
modules/subnet.tf:
resource “aws_subnet” “bryan” {
vpc_id = aws_vpc.krausen.id
cidr_block = “10.0.1.0/24”
tags = {
Name = “Krausen Subnet”
}
}
What could fix the problem?
a) add an output block to the subnet module and retrieve the value using module.subnet.subnet_id for the load balancer module
b) move the subnet and load balancer resource into the main configuration file so they can easily be referenced
c) publish the module to a Terraform registry first
d) references to resources that are created within a module cannot be used within other modules
add an output
block to the subnet module and retrieve the value using module.subnet.subnet_id
for the load balancer module
Adding an output block to the subnet module allows the subnet_id to be exposed as an output variable. This output variable can then be retrieved using module.subnet.subnet_id in the load balancer module, enabling Sara to pass the subnet_id between modules.
Provider dependencies are created in several different ways. Select the valid provider dependencies from the following list (select three):
a) Existence of any provider plugins found locally in the working directory.
b) Use of any resource block or data block in the configuration, belonging to a particular provider
c) Explicit use of a provider block in configuration, optionally including a version constraint.
d) Existence of any resource instance belonging to a particular provider in the current state.
b), c), d)
d: The existence of any resource instance belonging to a particular provider in the current state signifies a dependency on that provider, as Terraform needs access to the provider to manage the state of those resources.
True or false? The terraform plan -refresh-only
command is used to create a plan whose goal is only to update the Terraform state to match any changes made to remote objects outside of Terraform.
True
The statement is true because the terraform plan -refresh-only command is specifically designed to only refresh the Terraform state to match any changes made to remote objects outside of Terraform. It does not apply those changes to the state.
Which of the following statements represents the most accurate statement about the Terraform language?
a) Terraform is a mutable, declarative, Infrastructure as Code configuration management language based on Hashicorp Configuration Language, or optionally JSON.
b) Terraform is an immutable, declarative, Infrastructure as Code provisioning language based on Hashicorp Configuration Language, or optionally JSON.
c) Terraform is an immutable, imperative, Infrastructure as Code configuration management language based on Hashicorp Configuration Language, or optionally JSON.
d) Terraform is a mutable, imperative, Infrastructure as Code provisioning language based on Hashicorp Configuration Language, or optionally YAML.
b) Terraform is an immutable, declarative, Infrastructure as Code provisioning language based on Hashicorp Configuration Language, or optionally JSON.
Terraform is indeed an immutable and declarative Infrastructure as Code provisioning language. It allows users to define the desired state of their infrastructure and Terraform will make the necessary changes to reach that state. The language is based on HashiCorp Configuration Language (HCL) or JSON for configuration files.
A user runs terraform init
on their RHEL-based server, and per the output, two provider plugins are downloaded. Where are these plugins downloaded and stored on the server?
a) /etc/terraform/plugins
b) The .terraform.d directory in the current working directory
c) The .terraform/providers directory in the current working directory
d) The .terraform.plugins directory in the current working directory
c) The .terraform/providers directory in the current working directory
The provider plugins are downloaded and stored in the .terraform/providers
directory within the current working directory. This directory is specifically used by Terraform to manage provider plugins.
You have been given requirements to create a security group for a new application. Since your organisation standardises on Terraform, you want to add this new security group with the fewest number of lines of code. What feature could you use to iterate over a list of required tcp ports to add to the new security group?
a) splat expression
b) dynamic backend
c) terraform import
d) dynamic block
d) dynamic block
A dynamic block acts much like a for expression, but produces nested blocks instead of a complex typed value. It iterates over a given complex value and generates a nested block for each element of that complex value.
What are some of the features of Terraform state? (Select three.)
a) inspection of cloud resources
b) mapping configuration to real-world resources
c) determining the correct order to destroy resources
d) increased performance
b), c), d)
When configuring a remote backend in Terraform, it might be a good idea to purposely omit some of the required arguments to ensure secrets and other relevant data are not inadvertently shared with others. What alternatives are available to provide the remaining values to Terraform to initialise and communicate with the remote backend? (Select three.)
a) directly querying HashiCorp Vault for the secrets
b) use the -backend-config=PATH
flag to specify a separate config file
c) interactively on the command line
d) command-line key/value pairs
b), c), d)
You do not need to specify every required argument in the backend configuration. Omitting certain arguments may be desirable to avoid storing secrets, such as access keys, within the main configuration. When some or all of the arguments are omitted, we call this a partial configuration.
In Terraform Cloud, a workspace can be mapped to how many VCS repos?
a) 2
b) 5
c) 3
d) 1
d) 1
A workspace can only be configured to a single VCS repo, however, multiple workspaces can use the same repo, if needed. A good explanation of how to configure your code repositories can be found here.
In the terraform
block, which configuration would be used to identify the specific version of a provider required?
a) required-provider
b) required_providers
c) required-version
d) required_versions
b) required_providers
To identify a specific version of a provider in Terraform, you can use the required_providers configuration block. This block allows you to specify the provider’s name and the version range you want to use by using Terraform’s version constraints syntax.
You want to start managing resources that were not originally provisioned through infrastructure as code. Before you can import the resources’ current state, what must you do before running the terraform import
command?
a) modify the Terraform state file to add the new resources so Terraform will have a record of the resources to be managed
b) shut down or stop using the resources being imported so no changes are inadvertently missed
c) run terraform apply -refresh-only to ensure that the state file has the latest information for existing resources.
d) update the Terraform configuration file to include the new resources that match the resources you want to import
d) update the Terraform configuration file to include the new resources that match the resources you want to import
The current implementation of Terraform import can only import resources into the state. It does not generate a configuration. Because of this, and before running terraform import, it is necessary to manually write a resource configuration block for the resource to which the imported object will be mapped.
True or false? Workspaces provide similar functionality in the open-source and Terraform Cloud versions of Terraform.
False
Workspaces, managed with the terraform workspace command, isn’t the same thing as Terraform Cloud’s workspaces. Terraform Cloud workspaces act more like completely separate working directories.
CLI workspaces (OSS) are just alternate state files.
Which of the following connection types are supported by the remote-exec
provisioner? (Select two.)
a) smb
b) winrm
c) rdp
d) ssh
b) winrm, d) ssh
The remote-exec provisioner in Terraform is used to execute commands on a resource after it has been created over an SSH or WinRM connection. The supported connection types for remote-exec depend on the type of resource being provisioned and the underlying operating system.
What are the core Terraform workflow steps to use infrastructure as code?
a) Write, plan, apply
b) Plan, apply, destroy
c) Plan, apply, pray
d) Code, validate, apply
a) Write, plan, apply
The core Terraform workflow has three steps:
- Write - Author infrastructure as code.
- Plan - Preview changes before applying.
- Apply - Provision reproducible infrastructure.
Published modules via the Terraform Registry provide which of the following benefits? (Select four.)
a) support versioning
b) show examples and READMEs
c) allow browsing version histories
d) support from any code repo
e) automatically generated documentation
a), b), c), e)
Public modules are managed via Git and GitHub. Publishing a module takes only a few minutes. Once a module is published, you can release a new version of a module by simply pushing a properly formed Git tag. The module must be on GitHub and must be a public repo. This is only a requirement for the public registry. If you’re using a private registry, you may ignore this requirement.
When using variables in Terraform Cloud, what level of scope can the variable be applied to? (Select three.)
a) All current and future workspaces in a project using a variable set
b) A specific Terraform run in a single workspace
c) All workspaces across multiple Terraform Cloud organisations
d) Multiple workspaces using a variable set
a), b), d)
Terraform Cloud allows you to store important values in one place, which you can use across multiple projects. You can easily update the values, and the changes will apply to all projects that use them. Additionally, you can modify the values for specific projects without affecting others that use the same values. TFC allows you to use variables within a workspace, or use variable sets that can be used across multiple (or all) TFC workspaces.
Margaret is calling a child module to deploy infrastructure for her organisation. Just as a good architect does (and suggested by HashiCrop), she specifies the module version she wants to use even though there are newer versions available. During a terraform init
, Terraform downloads v0.0.5 just as expected.
What would happen if Margaret removed the version parameter in the module block and ran a terraform init
again?
a) Terraform would download the latest version of the module
b) Terraform would skip the module
c) Terraform would use the existing module already downloaded
d) Terraform would return an error, as the version parameter is required
c) Terraform would use the existing module already downloaded
When using modules installed from a registry, HashiCorp recommends explicitly constraining the acceptable version numbers to avoid unexpected or unwanted changes. The version argument accepts a version constraint string. Terraform will use the newest installed version of the module that meets the constraint; if no acceptable versions are installed, it will download the newest version that meets the constraint.
Fill in the correct answers below:
Infrastructure as Code (IaC) makes infrastructure changes ______, ______, _______, and _______. (Select four.)
a) highly available
b) repeatable
c) consistent
d) predictable
e) idempotent
b), c), d), e)
IaC makes changes idempotent, consistent, repeatable, and predictable. Without IaC, scaling up infrastructure to meet increased demand may require an operator to remotely connect to each machine and then manually provision and configure many servers by executing a series of commands/scripts. They might open multiple sessions and move between screens, which often results in skipped steps or slight variations between how work is completed, necessitating rollbacks. Perhaps a command was run incorrectly on one instance and reverted before being re-run correctly.
Given the following snippet of code, what does servers = 4
reference?
module “servers” {
source = “./modules/aws-servers”
servers = 4
}
a) servers is not a valid configuration for a module
b) the number of times the module will be executed
c) the output variable of the module
d) the value of an input variable
d) the value of an input variable
When calling a child module, values can be passed to the module to be used within the module itself.
Infrastructure as Code (IaC) provides many benefits to help organisations deploy application infrastructure much faster than clicking around in the console. What are the additional benefits of IaC? (Select three.)
a) code can easily be shared and reused
b) can always be used to deploy the latest features and services
c) eliminates parallelism
d) creates a blueprint of your data center
e) allows infrastructure to be versioned
a), d), e)
Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.
Infrastructure as Code almost always uses parallelism to deploy resources faster. And depending on the solution being used, it doesn’t always have access to the latest features and services available on cloud platforms or other solutions.
You have a Terraform configuration file with no defined resources. However, there is a related state file for resources that were created on AWS. What happens when you run a terraform apply
?
a) Terraform will scan the AWS infrastructure and create a new configuration file based on the state file.
b) Terraform will produce an error since there are no resources defined
c) Terraform will not perform any operations.
d) Terraform will destroy all of the resources
d) Terraform will destroy all of the resources
In this case, since there is a state file with resources, Terraform will match the desired state of no resources since the configuration file doesn’t include any resources. Therefore, all resources defined in the state file will be destroyed.