Terraform is an infrastructure as code tool that lets you define and manage cloud resources declaratively. It is not a database, web server, or monitoring agent.
ข้อ 2
What is infrastructure as code?
Infrastructure as code means defining and provisioning infrastructure through version-controlled configuration files. This makes changes repeatable and auditable.
ข้อ 3
What does HCL stand for?
HCL is the HashiCorp Configuration Language used by Terraform. It is designed to be readable by humans and machines.
ข้อ 4
What is a provider in Terraform?
A provider is a plugin that translates Terraform configuration into API calls for a specific platform such as AWS, Azure, or GCP.
ข้อ 5
What is a resource in Terraform?
A resource is an infrastructure object such as a virtual machine, network, or database that Terraform creates and manages.
ข้อ 6
What is a data source in Terraform?
A data source lets Terraform read information from existing infrastructure without creating or changing it.
ข้อ 7
What does terraform plan do?
terraform plan compares the configuration with current state and shows what will be created, changed, or destroyed without applying it.
ข้อ 8
What does terraform apply do?
terraform apply executes the changes needed to make real infrastructure match the configuration. It should usually follow a plan.
ข้อ 9
What does terraform destroy do?
terraform destroy removes the resources managed by the current configuration. It is destructive and should be used carefully.
ข้อ 10
What does terraform init do?
terraform init prepares the working directory by downloading providers and modules and configuring the backend. It is usually the first command.
ข้อ 11
What does terraform validate do?
terraform validate checks whether configuration is syntactically valid and internally consistent without contacting providers, which helps catch errors before planning or applying changes.
ข้อ 12
What does terraform fmt do?
terraform fmt rewrites .tf files using Terraform canonical formatting. It does not change infrastructure or state.
ข้อ 13
What is a variable in Terraform?
Variables let users pass values into configuration, such as region or instance size. They make modules reusable.
ข้อ 14
What is an output in Terraform?
Outputs expose selected values from applied infrastructure, such as IP addresses or endpoint URLs, to users or other modules.
ข้อ 15
Terraform configuration is declarative.
This statement is true. Terraform declares the desired end state, and Terraform figures out how to reach it. This is different from imperative scripts.
ข้อ 16
The Terraform configuration language is called ___.
Terraform uses HCL, the HashiCorp Configuration Language, to define infrastructure. HCL files usually have .tf extensions.
ข้อ 17
What does a provider configuration define?
A provider block tells Terraform which provider plugin to use and includes settings such as region and credentials.
ข้อ 18
What is a dependency graph?
Terraform builds a dependency graph from references between resources and uses it to determine creation and update order.
ข้อ 19
What does terraform refresh do?
terraform refresh reads the actual infrastructure and updates the state file without changing resources. Modern versions refresh during plan and apply.
ข้อ 20
What is a resource address?
A resource address such as aws_instance.web identifies a resource uniquely so commands like plan, apply, and state can target it.
ข้อ 21
What is Terraform state?
Terraform state maps configuration to real-world resources. It stores resource metadata and is essential for planning and updates.
ข้อ 22
Where can Terraform state be stored?
State can be stored locally in terraform.tfstate or remotely in a backend such as Terraform Cloud, S3, or Azure Storage.
ข้อ 23
What is a backend in Terraform?
A backend defines where state is stored and how locking works. Remote backends are important for team collaboration.
ข้อ 24
What is state locking?
State locking prevents two Terraform operations from modifying the same state at the same time, reducing conflicts.
ข้อ 25
How are sensitive values stored in state by default?
Sensitive values such as passwords can appear in plaintext in state files. You should use secure backends and avoid committing state.
ข้อ 26
What is remote state?
Remote state stores the state file in a shared backend, enabling team collaboration and centralized locking.
ข้อ 27
What does terraform state list do?
terraform state list shows the resource addresses currently tracked in the state file. It is useful for confirming which resources are managed before planning changes.
ข้อ 28
What does terraform state show do?
terraform state show displays the attributes of a specific resource as recorded in state. This is useful when inspecting a single resource without running a plan.
ข้อ 29
What does count do in a resource block?
count creates a fixed number of resource instances from one block. for_each is a more flexible alternative.
ข้อ 30
What does for_each do?
for_each iterates over a map or set of strings to create resource instances. It is more flexible than count.
ข้อ 31
What is depends_on used for?
depends_on forces Terraform to create one resource before another when the dependency is not automatic.
ข้อ 32
What is a lifecycle block used for?
A lifecycle block includes settings such as create_before_destroy, prevent_destroy, and ignore_changes. These settings control how Terraform replaces and updates resources.
ข้อ 33
What does create_before_destroy do?
create_before_destroy builds the new resource before removing the old one, which helps reduce downtime during replacement.
ข้อ 34
What is a provisioner?
Provisioners execute scripts or configuration steps on local or remote machines after a resource is created.
ข้อ 35
Which provisioner runs commands on the local machine?
local-exec runs a command on the machine where Terraform runs. remote-exec runs commands on a remote resource.
ข้อ 36
Which provisioner runs commands on a remote resource?
remote-exec connects to the created resource and runs commands there. local-exec runs on the Terraform host.
ข้อ 37
State files can contain sensitive values.
This statement is true. State files can store sensitive attribute values, so secure backends and access controls are important.
ข้อ 38
Every backend automatically supports state locking.
This statement is false. Not all backends support locking. Backends such as S3 with DynamoDB or Terraform Cloud provide locking.
ข้อ 39
The command to list resources in state is terraform state ___.
terraform state list prints resource addresses from state. Other subcommands include show, mv, rm, and pull.
ข้อ 40
What does the configuration represent?
Terraform configuration declares the desired end state. Terraform compares it with real resources to plan changes.
ข้อ 41
What is a Terraform module?
A module is a reusable container of Terraform configuration. Modules can be called from other configurations and the registry.
ข้อ 42
What is the root module?
The root module is the configuration in the working directory where Terraform runs. Child modules are called from it.
ข้อ 43
What are module inputs?
Module inputs are variables defined in the child module and set by the calling configuration.
ข้อ 44
What are module outputs?
Module outputs expose selected values so the calling configuration can use them, such as endpoint URLs or IDs.
ข้อ 45
Where can modules be sourced from?
Modules can come from local directories, the Terraform Registry, Git repositories, HTTP URLs, and other sources.
ข้อ 46
What is the Terraform Registry?
The Terraform Registry is a public repository where users can find and publish reusable providers and modules.
ข้อ 47
What is module versioning?
Module versioning uses tags such as v1.0.0 so callers can pin a specific version and receive controlled updates.
ข้อ 48
What is a workspace in Terraform?
Workspaces allow multiple named states for the same configuration, which is useful for environments such as dev and prod.
ข้อ 49
What is Terraform Cloud?
Terraform Cloud provides remote runs, state storage, variable management, and collaboration features for Terraform. It is used by teams to run infrastructure changes in a controlled way.
ข้อ 50
What is a run in Terraform Cloud?
A run represents the process of planning and applying changes to infrastructure for a Terraform Cloud workspace.
ข้อ 51
Where are variables stored in Terraform Cloud?
Terraform Cloud stores variables in workspaces, and they can be marked sensitive so they are hidden after saving.
ข้อ 52
What does terraform import do?
terraform import attaches an existing real-world resource to a resource block in configuration so Terraform can manage it.
ข้อ 53
What does terraform output do?
terraform output shows the values of outputs after apply, which is useful for scripts and integrations.
ข้อ 54
What is a run trigger?
Run triggers in Terraform Cloud start a workspace run when another workspace completes or a source changes.
ข้อ 55
Modules can be reused across projects.
This statement is true. Modules are designed for reuse across projects and teams, reducing duplicated configuration.
ข้อ 56
terraform plan can save an execution plan file.
This statement is true. terraform plan -out=plan.tfplan saves a plan that can be applied later with terraform apply plan.tfplan.
ข้อ 57
Workspaces are commonly used to manage multiple environments.
This statement is true. Workspaces keep separate state for environments such as development, staging, and production.
ข้อ 58
Terraform Cloud stores state remotely by default.
This statement is true. Terraform Cloud uses a remote backend for state and provides locking and version history.
ข้อ 59
The command to initialize a working directory is terraform ___.
terraform init installs providers, downloads modules, and configures the backend. It should be run before plan and apply.
ข้อ 60
What does terraform destroy -target do?
-target limits an operation to a specific resource or module. terraform destroy -target=aws_instance.web removes only that resource.