Terraform Interview Questions - Basics & Intermediate
48 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is HCL in Terraform?

  • A web framework for developing applications
  • A domain-specific language for writing configurations (correct)
  • A programming language for scripting
  • A database management system

How does HCL differ from JSON?

  • HCL is more concise and human-readable (correct)
  • HCL supports dynamic typing unlike JSON
  • HCL is more verbose and less readable
  • JSON is supported only in Terraform, not HCL

What constitutes a block in HCL?

  • A container for configuration that defines resources (correct)
  • A sequence of variable declarations
  • A collection of user input values
  • A repository for storing Terraform modules

Which keyword is used to declare a variable in HCL?

<p>variable (B)</p> Signup and view all the answers

What is an attribute in HCL?

<p>A key-value pair defining properties for a block (A)</p> Signup and view all the answers

What is the function of the output block in HCL?

<p>To display values after successful deployment (B)</p> Signup and view all the answers

How is a map defined in HCL?

<p>Using curly braces (C)</p> Signup and view all the answers

What is required for defining a list in HCL?

<p>Using square brackets with multiple values (B)</p> Signup and view all the answers

What is Terraform used for?

<p>Defining and provisioning infrastructure (D)</p> Signup and view all the answers

How does Terraform differ from Ansible?

<p>Terraform focuses on infrastructure while Ansible manages deployed resources (B)</p> Signup and view all the answers

What does the terraform init command do?

<p>Initializes the working directory for further commands (A)</p> Signup and view all the answers

What is the purpose of the Terraform state file?

<p>To map real-world resources to configuration and manage dependencies (D)</p> Signup and view all the answers

What is a provider in Terraform?

<p>A plugin that interacts with APIs of cloud services (D)</p> Signup and view all the answers

Which of the following is a primary function of Terraform?

<p>Infrastructure provisioning (D)</p> Signup and view all the answers

In which of the following areas does Terraform NOT specialize?

<p>User management (C)</p> Signup and view all the answers

What lifecycle aspect does Terraform focus on?

<p>Infrastructure lifecycle (A)</p> Signup and view all the answers

What does the file() function do in HCL?

<p>Reads the raw content of a file (C)</p> Signup and view all the answers

What does the coalesce() function return?

<p>The first non-null argument from a list (B)</p> Signup and view all the answers

How is a dynamic block defined in HCL?

<p>dynamic 'ingress' { for_each = var.ingress_rules } (A)</p> Signup and view all the answers

What is the primary purpose of the toset() function in HCL?

<p>To convert a list or tuple into a set (D)</p> Signup and view all the answers

What does the try() function do in HCL?

<p>Evaluates expressions and returns the first successful result (B)</p> Signup and view all the answers

What command is used to create a new workspace in Terraform?

<p>terraform workspace new (A)</p> Signup and view all the answers

How can you define a map with mixed data types in HCL?

<p>Use the any type for mixed-type maps (D)</p> Signup and view all the answers

In HCL, what is the result of the expression try(var.maybe_value, 'fallback_value') if var.maybe_value is null?

<p>'fallback_value' (D)</p> Signup and view all the answers

Which practice is recommended to avoid conflicts in workspace state files?

<p>Isolate State Per Workspace (C)</p> Signup and view all the answers

What type of blocks does a dynamic block generate in HCL?

<p>Nested configuration blocks dynamically (C)</p> Signup and view all the answers

What feature does Terraform Cloud provide to prevent simultaneous updates?

<p>State locking (C)</p> Signup and view all the answers

What command lists the existing workspaces in Terraform?

<p>terraform workspace list (A)</p> Signup and view all the answers

What should be managed through variable sets for Terraform Cloud?

<p>Environment-specific variables (D)</p> Signup and view all the answers

What type of notifications can be configured in Terraform Cloud?

<p>Slack or email notifications (C)</p> Signup and view all the answers

What is the first step in the recommended example workflow for Terraform Cloud?

<p>Configure the backend for remote (B)</p> Signup and view all the answers

What is a key capability of Terragrunt?

<p>It simplifies and enhances Terraform's functionality (B)</p> Signup and view all the answers

What is a recommended method for storing sensitive passwords when using Terraform?

<p>Use environment variables or secret management tools (B)</p> Signup and view all the answers

Which provider feature can be used to securely manage secrets in Kubernetes?

<p>kubernetes_secret (D)</p> Signup and view all the answers

What should be done if sensitive data is used temporarily during resource creation?

<p>Remove it before storing in the state (D)</p> Signup and view all the answers

Which of the following methods can help encrypt the Terraform state file?

<p>Enable server-side encryption in AWS S3 (D)</p> Signup and view all the answers

What is the first step in manually scrubbing sensitive data from the Terraform state file?

<p>Back up your state file (A)</p> Signup and view all the answers

Which command is used to download the state file locally?

<p>terraform state pull (D)</p> Signup and view all the answers

How can sensitive attributes be removed after provisioning in Terraform?

<p>Update the resource with null_resource (A)</p> Signup and view all the answers

What is a best practice for managing sensitive values in Terraform?

<p>Utilize secret management tools or environment variables (A)</p> Signup and view all the answers

What is the main purpose of using workspaces in Terraform Cloud?

<p>To manage multiple environments with isolated state files (C)</p> Signup and view all the answers

Which of the following is NOT a prerequisite for using Terraform Cloud with workspaces?

<p>Subscription to a premium Terraform service (C)</p> Signup and view all the answers

Where can you create a new workspace in Terraform Cloud?

<p>On the Terraform Cloud Workspace Dashboard (B)</p> Signup and view all the answers

What should you link each workspace to in Terraform Cloud?

<p>The same Terraform configuration repository (C)</p> Signup and view all the answers

What does the following configuration represent in Terraform? 'name = "dev"'

<p>The specific environment for the workspace (A)</p> Signup and view all the answers

Which command is necessary to set up the backend configuration for Terraform Cloud?

<p>terraform init (D)</p> Signup and view all the answers

What type of files should be used to manage environment-specific variables in Terraform Cloud?

<p>Shared configuration files (C)</p> Signup and view all the answers

In the backend configuration example, what is the purpose of 'hostname = "app.terraform.io"'?

<p>To define the URL for the Terraform Cloud backend (C)</p> Signup and view all the answers

Flashcards

Terraform

An Infrastructure as Code (IaC) tool for defining and provisioning infrastructure resources.

IaC

Managing and provisioning infrastructure through code.

Terraform Init

Initializes Terraform workspace by downloading providers and configuring backend.

Terraform State File

Stores information on managed infrastructure resources, tracking dependencies and planned changes.

Signup and view all the flashcards

Terraform Provider

Plugin that allows Terraform to interact with cloud provider/service APIs.

Signup and view all the flashcards

Terraform vs Ansible

Terraform focuses on infrastructure provisioning, Ansible manages the state of resources after deployment.

Signup and view all the flashcards

Infrastructure as Code

Managing and provisioning infrastructure through code.

Signup and view all the flashcards

Cloud Providers

Platforms like AWS, Azure, GCP that offer cloud services.

Signup and view all the flashcards

HCL in Terraform

A configuration language used in Terraform for defining resources and deployments.

Signup and view all the flashcards

HCL vs. JSON

HCL is more concise and readable than JSON, although Terraform supports both.

Signup and view all the flashcards

HCL Block

A container in HCL used to define resources, providers, and modules.

Signup and view all the flashcards

HCL Variable

A configurable value declared using the variable block.

Signup and view all the flashcards

HCL Attribute

A key-value pair defining a resource's properties.

Signup and view all the flashcards

HCL Output Block

Used to present values from the configuration after deployment.

Signup and view all the flashcards

HCL Map

A collection of key-value pairs organized like a dictionary.

Signup and view all the flashcards

HCL List

An ordered collection of items.

Signup and view all the flashcards

Terraform Cloud Workspaces

Manage multiple environments (dev, staging, prod) with isolated Terraform state and configurations in Terraform Cloud.

Signup and view all the flashcards

Terraform Cloud Account

An account needed to use Terraform Cloud services for workspace management.

Signup and view all the flashcards

Remote Backend Configuration

Setting up Terraform to store state data in Terraform Cloud instead of locally.

Signup and view all the flashcards

Workspace Dashboard

The Terraform Cloud interface for managing and creating workspaces.

Signup and view all the flashcards

Shared Configuration

A single Terraform configuration used across different environments (e.g., dev, staging, prod).

Signup and view all the flashcards

Environment-Specific Variables

Variables within a shared configuration that differ across environments (e.g., dev, staging, prod).

Signup and view all the flashcards

Terraform Backend Configuration (example)

Code within Terraform file (e.g., main.tf) configuring where Terraform stores state, relating to Terraform Cloud.

Signup and view all the flashcards

Workspace Creation (Terraform Cloud)

The process of creating separate environments (e.g., dev, staging, prod) within Terraform Cloud.

Signup and view all the flashcards

Terraform Workspace

A container for managing infrastructure resources in Terraform Cloud or locally.

Signup and view all the flashcards

Terraform Workspace CLI

Command-line tools for interacting with Terraform workspaces, to create , list or delete them.

Signup and view all the flashcards

Workspace Isolation

Keeping state files separate to avoid conflict between different environments or projects in Terraform.

Signup and view all the flashcards

Environment-Specific Variables

Configuration settings tailored for each specific environment (e.g., dev, staging, prod).

Signup and view all the flashcards

Terraform Cloud State Locking

Feature preventing simultaneous updates to Terraform state, maintaining data integrity.

Signup and view all the flashcards

Terragrunt

A tool that simplifies and enhances Terraform to manage complex projects.

Signup and view all the flashcards

Workspace Selection

Choosing a specific workspace in Terraform to apply or manage changes in a specific environment.

Signup and view all the flashcards

Terraform Apply

The command to provision Infrastructure resources by applying the configuration.

Signup and view all the flashcards

Externalizing Sensitive Data

Storing sensitive information (like passwords) outside of your Terraform configuration files.

Signup and view all the flashcards

Environment Variables

Storing a value outside of the codebase that can be referenced by the code.

Signup and view all the flashcards

Provider Features (Secrets)

Tools provided by specific providers to handle sensitive data without state file storage.

Signup and view all the flashcards

Removing Sensitive Data from State

Temporarily use sensitive information, then delete it before saving to the Terraform state.

Signup and view all the flashcards

Encrypting the State File

Using encryption to protect sensitive information within the state file.

Signup and view all the flashcards

Manual State Scrubbing

Manually deleting sensitive data from the state file if needed.

Signup and view all the flashcards

State File Backup

A crucial step when working with the Terraform state, to avoid losing the entire state.

Signup and view all the flashcards

State File Pull/Push

Downloading and uploading the state file for modifications, a critical step for safe state scrubbing.

Signup and view all the flashcards

Multi-line Strings in HCL

Defined using triple quotes (""" ... """) to allow strings that span multiple lines.

Signup and view all the flashcards

file() vs. templatefile()

file() reads a file's raw content; templatefile() processes a file to fill in templates.

Signup and view all the flashcards

Dynamic Blocks in HCL

Generate nested blocks of configuration dynamically based on a loop or list of data.

Signup and view all the flashcards

coalesce() Function

Returns the first non-null value from a given list of arguments.

Signup and view all the flashcards

try() Function in HCL

Evaluates expressions; returns the first successful result or a fallback.

Signup and view all the flashcards

Mixed Type Maps

Maps that store different data types (e.g., strings and numbers) using the 'any' type.

Signup and view all the flashcards

toset() Function

Converts a list or tuple into a set, removing duplicates.

Signup and view all the flashcards

List of Maps in HCL

Defined by nested maps within a parent list structure.

Signup and view all the flashcards

Study Notes

Terraform Interview Questions and Answers - Basic Questions

  • Terraform is an Infrastructure as Code (IaC) tool developed by HashiCorp. It's used to define and provision infrastructure resources (e.g., VMs, networks, storage) across cloud providers (AWS, Azure, GCP) using a declarative configuration language.

  • Terraform differs from Ansible. Terraform primarily provisions and manages infrastructure, while Ansible manages software, system configuration, and application deployment after the infrastructure is built.

  • The terraform init command initializes the working directory. It downloads required provider plugins, sets up backend configurations for storing state files, and prepares the directory for subsequent commands.

Terraform Interview Questions and Answers - Intermediate Questions

  • Sensitive data (passwords, API keys) should be handled using environment variables, Vault integration, or Terraform's sensitive argument.

  • Terraform plan previews changes, while apply executes them.

  • Terraform modules are reusable configuration sets that organize, modularize code, reduce duplication, and enable reusable configurations across different projects or environments.

  • Terraform manages drift by comparing the state file with actual infrastructure during plan or apply commands. Detected changes are highlighted, and the infrastructure may be updated to the desired state.

Terraform Interview Questions and Answers - Advanced Questions

  • Terraform state files should be managed using remote backends (AWS S3, Azure Blob Storage or Terraform Cloud), state locking, and workspaces for concurrent operations in team environments.

  • Terraform workspaces allow managing multiple instances of infrastructure configurations within a single directory, easily creating separate development, testing, and production environments.

Terraform Interview Questions and Answers - HCL (Hashicorp Configuration Language)

  • HCL is Terraform's configuration language, designed for human readability and machine-friendliness. It uses blocks, arguments, and attributes to define resources, providers, and modules.

  • HCL variables are placeholders for values passed into the configuration, making it dynamic and reusable.

  • HCL uses locals for reusable expressions within configurations.

  • HCL supports conditionals using ternary operators and loops using the for expression.

  • HCL supports interpolation with the $ syntax.

  • HCL uses double quotes for strings. Multi-line strings use <<EOF blocks.

  • HCL's count argument creates multiple instances of a resource.

  • HCL's for_each iterates over maps or sets to create multiple resource instances.

  • HCL's dynamic block generates nested blocks dynamically based on variable values.

  • HCL's output block displays specific information from Terraform configuration.

  • HCL uses depends_on to define dependencies between resources.

  • HCL data sources retrieve and reference information from external sources.

  • terraform.workspace is a built-in Terraform variable representing the current workspace.

  • HCL's compact() function removes null or empty values from a list.

  • HCL's lookup() function returns a value from a map with a default fallback if the key isn't found.

  • HCL's can() function checks if an expression is valid.

  • HCL's slice() function extracts a portion of a list.

  • HCL uses merge() to combine maps, with later maps overriding earlier conflicting keys.

  • HCL's zipmap() function creates a map from two lists.

  • HCL supports sensitive to mark variables and outputs as sensitive preventing display in logs and state file storage.

  • HCL's optional feature allows for optional attributes in object variables.

Terraform Interview Questions and Answers - Scenario-Based Questions

  • To handle breaking changes in a Terraform provider, update the provider version, test changes in a non-production environment using the terraform plan command, fix code issues, then gradually roll out changes.

Terraform Interview Questions and Answers - Other Questions

  • Terraform import command brings existing manually managed resources under Terraform management.

  • Modules should be stored in a version-controlled repository (e.g., Git) for versioning and use version constraints to manage updates.

  • Optimize costs by using Terraform for resource auto-scaling, identifying and removing unused resources (using tools like AWS Trusted Advisor or Azure Cost Management), and scheduling non-critical resources for shut-down during non-period hours.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

Prepare for your Terraform interview with this comprehensive quiz that covers both basic and intermediate questions. Explore essential concepts like Infrastructure as Code, command usage, and best practices for handling sensitive data. Gain confidence and enhance your understanding of Terraform's functionalities.

More Like This

Use Quizgecko on...
Browser
Browser