HashiCorp Terraform Associate - Practice Questions 1

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What are the Providers?

A provider is a plugin that Terraform uses to translate the API interactions with the service. A provider is responsible for understanding API interactions and exposing resources. Because Terraform can interact with any API, you can represent almost any infrastructure type as a resource in Terraform.

What is Infrastructure as Code?

You write and execute the code to define, deploy, update, and destroy your infrastructure

What are the types of provisioners?

local-exec remote-exec

What is the command to initialize the directory?

terraform init

What is the flag you should use to upgrade modules and plugins a part of their respective installation steps?

upgrade terraform init -upgrade

How many ways you can configure provider versions?

1. With required_providers blocks under terraform block terraform { required_providers { aws = "~> 1.0" } } 2. Provider version constraints can also be specified using a version argument within a provider block provider { version= "1.0" }

What is a remote-exec provisioner and when do we use it?

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.

What does this symbol version = "~> 1.0" mean when defining versions?

Any version more than 1.0 and less than 2.0

How do you select alternate providers?

By default, resources use a default provider configuration inferred from the first word of the resource type name. For example, a resource of type aws_instance uses the default (un-aliased) aws provider configuration unless otherwise stated. resource "aws_instance" "foo" { provider = aws.west# ... }

What are Provisioners?

If you need to do some initial setup on your instances, then provisioners let you upload files, run shell scripts, or install and trigger other software like configuration management tools, etc.

What is the use of terraform being cloud-agnostic?

It simplifies management and orchestration, helping operators build large-scale multi-cloud infrastructures.

What is the Private Module Registry?

Terraform Cloud's private module registry helps you share Terraform modules across your organization. It includes support for module versioning, a searchable and filterable list of available modules, and a configuration designer to help you build new workspaces faster.

Where do you find and explore terraform Modules?

Terraform Registry

What is a local-exec provisioner and when do we use it?

The local-exec provisioner executing a 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

What are workspaces?

The persistent data stored in the backend belongs to a workspace. Initially the backend has only one workspace, called "default", and thus there is only one Terraform state associated with that configuration.

What is the first thing you should do when the terraform crashes?

panic message

How do you configure a Provider?

provider "google" { project = "acme-app" region = "us-central1" } The name given in the block header ("google" in this example) is the name of the provider to configure. Terraform associates each resource type with a provider by taking the first word of the resource type name (separated by underscores), and so the "google" provider is assumed to be the provider for the resource type name google_compute_instance. The body of the block (between { and }) contains configuration arguments for the provider itself. Most arguments in this section are specified by the provider itself; in this example both project and region are specific to the google provider.

If different teams are working on the same configuration. How do you make files to have consistent formatting?

terraform fmt This command automatically updates configurations in the current directory for easy readability and consistency.

You are formatting the configuration files and what is the flag you should use to see the differences?

terraform fmt -diff

You are formatting configuration files in a lot of directories and you don't want to see the list of file changes. What is the flag that you should use?

terraform fmt -list=false

You are formatting the configuration files and what is the flag you should use to process the subdirectories as well?

terraform fmt -recursive

What is the command usage?

terraform fmt [options] [DIR]

How do you upgrade to the latest acceptable version of the provider?

terraform init --upgrade It upgrade to the latest acceptable version of each providerThis command also upgrades to the latest versions of all Terraform modules.

When you are doing initialization with terraform init, you want to skip backend initialization. What should you do?

terraform init -backend=false

What is the command to show the execution plan and not apply?

terraform plan

How do you update the state prior to checking differences when you run a terraform plan?

terraform plan -refresh=true

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.

If your state file is too big and you want to list the resources from your state. What is the command?

terraform state list

You are working on terraform files and you want to list all the resources. What is the command you should use?

terraform state list

Give an example of tainting a resource within a module?

terraform taint "module.couchbase.aws_instance.cb_node[9]"

When you are tainting a resource terraform reads the default state file terraform.tfstate. What is the flag you should use to read from a different path?

terraform taint -state=path

What is the taint command usage?

terraform taint [options] address

Give an example of tainting a single resource?

terraform taint aws_security_group.allow_all

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. Validate your configuration. If your configuration is valid, Terraform will return a success message.

What is the naming scheme for provider plugins?

terraform-provider-<NAME>_vX.Y.Z

What is the name of the terraform state file?

terraform.tfstate

Third-party plugins should be manually installed. Is that true?

True

The command terraform init cannot install third-party plugins? True or false?

True Install third-party providers by placing their plugin executables in the user plugins directory. The user plugins directory is in one of the following locations, depending on the host operating system. Once a plugin is installed, terraform init can initialize it normally. You must run this command from the directory where the configuration files are located.

What is the command to create infrastructure?

terraform apply

What are the meta-arguments that are defined by Terraform itself and available for all provider blocks?

version: Constraining the allowed provider versions alias: using the same provider with different configurations for different resources

What should you use to set both a lower and upper bound on versions for each provider?

~> terraform { required_providers { aws = "~> 2.7.0" } }

What is Provider Plugin Cache?

By default, terraform init downloads plugins into a subdirectory of the working directory so that each working directory is self-contained. As a consequence, if you have multiple configurations that use the same provider then a separate copy of its plugin will be downloaded for each configuration. Given that provider plugins can be quite large (on the order of hundreds of megabytes), this default behavior can be inconvenient for those with slow or metered Internet connections. Therefore Terraform optionally allows the use of a local directory as a shared plugin cache, which then allows each distinct plugin binary to be downloaded only once.

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 more graceful recovery of the loss of a region or entire provider.

What is the benefit of Sentinel?

Codifying policy removes the need for ticketing queues, without sacrificing enforcement. One of the other benefits of Sentinel is that it also has a full testing framework. Avoiding a ticketing workflow allows organizations to provide more self-service capabilities and end-to-end automation, minimizing the friction for developers and operators.

Where do you describe all the components or your entire datacenter so that Terraform provision those?

Configuration files ends with *.tf

What is plug-in based architecture?

Defining additional features as plugins to your core platform or core application. This provides extensibility, flexibility and isolation

What is the difference between directory-separated and workspace-separated environments?

Directory separated environments rely on duplicate Terraform code, which may be useful if your deployments need differ, for example to test infrastructure changes in development. But they can run the risk of creating drift between the environments over time. Workspace-separated environments use the same Terraform code but have different state files, which is useful if you want your environments to stay as similar to each other as possible, for example if you are providing development infrastructure to a team that wants to simulate running in production.

What is Provider initialization and why do we need?

Each time a new provider is added to configuration -- either explicitly via a provider block or by adding a resource from that provider -- Terraform must initialize the provider before it can be used. Initialization downloads and installs the provider's plugin so that it can later be executed.

What is the Terraform State?

Every time you run Terraform, it records information about what infrastructure it 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.

What are the use cases of Terraform?

Heroku App SetupMulti-Tier ApplicationsSelf-Service ClustersSoftware DemosDisposable EnvironmentsSoftware Defined NetworkingResource SchedulersMulti-Cloud Deployment

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. "Day 0" code provisions and configures your initial infrastructure. "Day 1" refers to OS and application configurations you apply after you've initially built your infrastructure.

How using IaC make it easy to provision infrastructure?

IaC makes it easy to provision and apply 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.

When terraform mark the resources are tainted?

If a resource successfully creates 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.

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.

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, 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. Syncing When two people works on the same file and doing some changes to the infrastructure. Its very important for everyone to be working with the same state so that operations will be applied to the same remote objects.

Where is the location of the CLI configuration File?

On Windows, the file must be named named terraform.rc and placed in the relevant user's %APPDATA% directory. On all other systems, the file must be named .terraformrc (note the leading period) and placed directly in the home directory of the relevant user. The location of the Terraform CLI configuration file can also be specified using the TF_CLI_CONFIG_FILE environment variable.

Terraform assumes an empty default configuration for any provider that is not explicitly configured. A provider block can be empty. Is this true?

True

What are the advantages of Terraform?

Platform AgnosticState ManagementOperator Confidence

How do you initialize any Provider?

Provider initialization is one of the actions of terraform init. Running this command will download and initialize any providers that are not already initialized.

When you run terraform init command, all the providers are installed in the current working directory. Is this true?

Providers downloaded by terraform init are only installed for the current working directory; other working directories can have their own installed provider versions. Note that terraform init cannot automatically download providers that are not distributed by HashiCorp. See Third-party Plugins below for installation instructions.

Are provisioners runs 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.

What is multi-cloud deployment?

Provisoning your infrastrcutire into multiple cloud providers to increase fault-tolerance of your applications.

Why do we need Multiple Provider instances?

Some of the example scenarios: a. multiple regions for a cloud platform b. targeting multiple Docker hosts c. multiple Consul hosts, etc.

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.

How do you do debugging terraform?

Terraform has detailed logs which can be enabled by setting the TF_LOG environment variable to any value. You can set TF_LOG to one of the log levels TRACE, DEBUG, INFO, WARN or ERROR to change the verbosity of the logs. TRACE is the most verbose and it is the default if TF_LOG is set to something other than a log level name.

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

What is the recommended approach after upgrading terraform?

The canonical format may change in minor ways between Terraform versions, so after upgrading Terraform we recommend to proactively run terraform fmt on your modules along with any other changes you are making to adopt the new version.

What is the Core Terraform workflow?

The core Terraform workflow has three steps: 1. Write - Author infrastructure as code. 2. Plan - Preview changes before applying. 3. Apply - Provision reproducible infrastructure.

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.

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 { # ... }

What is command fmt?

The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style. This command applies a subset of the Terraform language style conventions, along with other minor adjustments for readability.

What is the command import?

The terraform import command is used to import existing resources into Terraform.

What does the command refresh do?

The terraform refresh command is used to reconcile the state Terraform knows about (via its state file) with the real-world infrastructure. This can be used to detect any drift from the last-known state, and to update the state file.

What is the command state?

The terraform state command is used for advanced state management.

What is the command taint?

The terraform taint command manually marks a Terraform-managed resource as tainted, forcing it to be destroyed and recreated on the next apply.

You are building infrastructure for different environments for example test and dev. How do you maintain separate states?

There are two primary methods to separate state between environments: directories workspaces

How do you constrain the provider version?

To constrain the provider version as suggested, add a required_providers block inside a terraform block: terraform { required_providers { aws = "~> 1.0" } }

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:

How do we define multiple Provider configurations?

To include multiple configurations for a given provider, include multiple provider blocks with the same provider name, but set the alias meta-argument to an alias name to use for each additional configuration. # The default provider configuration provider "aws" { region = "us-east-1" } # Additional provider configuration for west coast region provider "aws" { alias = "west" region = "us-west-2" }

By default, fmt scans the current directory for configuration files. Is this true?

True

By default, provisioners that fail will also cause the Terraform apply itself to fail. Is this true?

True

Terraform CLI versions and provider versions are independent of each other. Is this true?

True

When you are using plugin cache you end up growing cache directory with different versions. Whose responsibility 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.

Why do we need to initialize the directory?

When you create a new configuration — or check out an existing configuration from version control — you need to initialize the directory. Initializing a configuration directory downloads and installs providers used in the configuration, which in this case is the aws provider. Subsequent commands will use local settings and data during initialization.

What is the location of the user plugins directory?

Windows %APPDATA%\terraform.d\plugins All other systems ~/.terraform.d/plugins

You want to create a parallel, distinct copy of a set of infrastructure in order to test a set of changes before modifying the main production infrastructure. How do you achieve that?

Workspaces

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.

What are the benefits of IaC?

a. AutomationWe 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 codeWe can reuse the same code c. VersioningWe 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 wehave this transparency of documentation IaC makes changes idempotent, consistent, repeatable, and predictable.

How do you configure Multiple Provider Instances?

alias You can optionally define multiple configurations for the same provider, and select which one to use on a per-resource or per-module basis.

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.

If terraform crashes where should you see the logs?

crash.log

How do you configure the required version of Terraform CLI can be used with your configuration?

required_version

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.

What are the data types for the variables?

string number bool list(<TYPE>) set(<TYPE>) map(<TYPE>) object({<ATTR NAME> = <TYPE>, ... }) tuple([<TYPE>, ...])


Ensembles d'études connexes

Introduction to Entrepreneurship

View Set

Chapter 17 The Endocrine System Review Questions

View Set

Leadership and Management Quiz 5,6,11,15

View Set