You have a Terraform module that creates a Google Cloud Storage bucket and outputs its name. What will be the value of module.bucket.bucket_name after applying the configuration?
module "bucket" { source = "./modules/gcs_bucket" bucket_name = "my-app-bucket" } output "bucket_name" { value = module.bucket.bucket_name }
Think about what the module outputs and how outputs are accessed.
The module outputs the bucket name as defined inside it. Accessing module.bucket.bucket_name returns the string "my-app-bucket".
Given a Terraform module that defines a variable region with a default value, what will be the region used if the module is called without specifying region?
variable "region" { type = string default = "us-central1" } resource "google_compute_instance" "vm" { name = "vm-instance" machine_type = "e2-medium" zone = "${var.region}-a" }
Consider the default value behavior of variables in Terraform modules.
If a variable has a default value and is not overridden, Terraform uses the default value.
You want to ensure that a sensitive variable like a service account key is not exposed in Terraform logs or state files when passed to a module. Which approach correctly secures this sensitive input?
Think about Terraform's built-in support for sensitive variables.
Marking variables as sensitive = true prevents them from being shown in logs and state outputs, protecting secrets.
You reuse a module twice in your Terraform configuration to create two Google Cloud Storage buckets. Both module calls use the same bucket_name input. What will happen when you apply this configuration?
Consider how resource names must be unique in GCP and Terraform behavior on duplicates.
GCP requires unique bucket names globally. Terraform will error if two resources try to create buckets with the same name.
You are designing a Terraform module to deploy a GCP Compute Engine instance. You want to reuse this module for multiple environments (dev, staging, prod) with different configurations. Which design approach best supports this reuse while following best practices?
Think about how to keep modules flexible and maintainable across environments.
Using input variables for environment-specific settings allows one module to be reused safely and clearly for multiple environments.