Terraform Interview Questions - Basics & Intermediate
48 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition

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</p> Signup and view all the answers

    What is an attribute in HCL?

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

    What is the function of the output block in HCL?

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

    How is a map defined in HCL?

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

    What is required for defining a list in HCL?

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

    What is Terraform used for?

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

    How does Terraform differ from Ansible?

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

    What does the terraform init command do?

    <p>Initializes the working directory for further commands</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</p> Signup and view all the answers

    What is a provider in Terraform?

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

    Which of the following is a primary function of Terraform?

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

    In which of the following areas does Terraform NOT specialize?

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

    What lifecycle aspect does Terraform focus on?

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

    What does the file() function do in HCL?

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

    What does the coalesce() function return?

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

    How is a dynamic block defined in HCL?

    <p>dynamic 'ingress' { for_each = var.ingress_rules }</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</p> Signup and view all the answers

    What does the try() function do in HCL?

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

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

    <p>terraform workspace new</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</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'</p> Signup and view all the answers

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

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

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

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

    What feature does Terraform Cloud provide to prevent simultaneous updates?

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

    What command lists the existing workspaces in Terraform?

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

    What should be managed through variable sets for Terraform Cloud?

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

    What type of notifications can be configured in Terraform Cloud?

    <p>Slack or email notifications</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</p> Signup and view all the answers

    What is a key capability of Terragrunt?

    <p>It simplifies and enhances Terraform's functionality</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</p> Signup and view all the answers

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

    <p>kubernetes_secret</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</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</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</p> Signup and view all the answers

    Which command is used to download the state file locally?

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

    How can sensitive attributes be removed after provisioning in Terraform?

    <p>Update the resource with null_resource</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</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</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</p> Signup and view all the answers

    Where can you create a new workspace in Terraform Cloud?

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

    What should you link each workspace to in Terraform Cloud?

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

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

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

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

    <p>terraform init</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</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</p> Signup and view all the answers

    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