0
0
Terraformcloud~20 mins

GCP provider setup in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GCP Provider Setup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Configuration
intermediate
2:00remaining
Correct GCP provider block for Terraform
Which Terraform provider block correctly sets up the Google Cloud provider with project ID "my-project" and region "us-central1"?
A
provider "google" {
  project = "my-project"
  zone    = "us-central1"
}
B
provider "gcp" {
  project_id = "my-project"
  region    = "us-central1"
}
C
provider "google" {
  project_id = "my-project"
  location   = "us-central1"
}
D
provider "google" {
  project = "my-project"
  region  = "us-central1"
}
Attempts:
2 left
💡 Hint
The official Terraform provider for Google Cloud is named "google" and uses "project" and "region" keys.
🧠 Conceptual
intermediate
2:00remaining
Service Account Authentication in GCP Provider
Which option correctly describes how to authenticate Terraform with a GCP service account JSON key file?
AInclude the JSON key file content directly inside the provider block under a 'credentials' attribute.
BUse the 'access_token' attribute in the provider block with the service account email.
CSet the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON key file before running Terraform.
DNo authentication is needed if you run Terraform on any machine inside GCP.
Attempts:
2 left
💡 Hint
Terraform uses environment variables or explicit credentials file paths for authentication.
Architecture
advanced
3:00remaining
Best practice for managing multiple GCP projects in Terraform
You manage infrastructure across multiple GCP projects. Which Terraform setup best isolates configurations and credentials per project?
ACreate separate Terraform root modules for each project, each with its own provider block and state file.
BUse a single provider block with multiple project IDs listed in an array.
CManage all projects in one Terraform configuration with conditional resource creation.
DUse one Terraform workspace and switch the project ID in the provider block dynamically with variables.
Attempts:
2 left
💡 Hint
Isolating state and credentials per project reduces risk and complexity.
security
advanced
2:30remaining
Least privilege principle for GCP provider service accounts
Which option best follows the least privilege principle when assigning roles to a service account used by Terraform's GCP provider?
AAssign the 'Owner' role to the service account for full access during deployment.
BAssign only the specific roles needed to create and manage the resources Terraform will handle.
CAssign the 'Editor' role to cover most resource management needs.
DAssign no roles and rely on default permissions.
Attempts:
2 left
💡 Hint
Grant only permissions necessary for the tasks Terraform performs.
service_behavior
expert
3:00remaining
Terraform GCP provider behavior with missing project attribute
What happens when you run Terraform with a GCP provider block that omits the 'project' attribute and no project is set in environment variables or default credentials?
Terraform
provider "google" {
  region = "us-east1"
}
ATerraform throws an error indicating the project ID is missing and stops execution.
BTerraform applies resources in the default project linked to the credentials automatically.
CTerraform prompts the user to input a project ID during apply.
DTerraform uses the region value as the project ID by default.
Attempts:
2 left
💡 Hint
The project ID is required unless set in credentials or environment.