Bird
Raised Fist0
GCPcloud~5 mins

Variables and outputs in GCP - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is a variable in GCP infrastructure as code?
A variable is a placeholder used to store values that can change, like names or sizes, so you can reuse and customize your infrastructure easily.
Click to reveal answer
beginner
Why use outputs in GCP infrastructure templates?
Outputs show important information after deployment, like IP addresses or resource names, so you can use them in other steps or share with your team.
Click to reveal answer
intermediate
How do variables improve your GCP deployment templates?
Variables let you change settings without rewriting code, making your templates flexible and easier to manage, like changing a server size without editing many places.
Click to reveal answer
intermediate
What is the difference between a variable and an output in GCP templates?
Variables are inputs you set before deployment to customize resources. Outputs are results you get after deployment to see or use resource details.
Click to reveal answer
beginner
Give an example of when you would use an output in a GCP deployment.
You might output the external IP of a virtual machine so you can connect to it or share it with others after deployment.
Click to reveal answer
What is the main purpose of a variable in GCP deployment templates?
ATo display information after deployment
BTo store values that can be changed to customize deployments
CTo delete resources automatically
DTo monitor resource usage
What does an output in a GCP template provide?
AInput values for deployment
BSecurity settings
CError messages during deployment
DInformation about deployed resources
Which of the following is NOT a good use of variables in GCP templates?
AHardcoding IP addresses
BDefining the project ID
CSetting the machine type for a VM
DChoosing the region for resources
When should you use outputs in your GCP deployment?
ATo delete resources
BBefore deployment to set values
CAfter deployment to get resource details
DTo write deployment scripts
How do variables and outputs work together in GCP templates?
AVariables set inputs; outputs show results
BVariables delete resources; outputs create them
CVariables monitor usage; outputs set permissions
DVariables and outputs are the same
Explain what variables and outputs are in GCP infrastructure templates and why they are useful.
Think about inputs before deployment and information after deployment.
You got /4 concepts.
    Describe a simple example where you use a variable and an output in a GCP deployment template.
    Imagine setting a server size and then getting its IP address.
    You got /3 concepts.

      Practice

      (1/5)
      1. What is the main purpose of variables in a Google Cloud deployment configuration?
      easy
      A. To monitor resource usage in real-time
      B. To display the final results after deployment
      C. To delete resources automatically
      D. To store values that can be reused throughout the configuration

      Solution

      1. Step 1: Understand the role of variables

        Variables hold values like names or sizes that you want to reuse in your cloud setup.
      2. Step 2: Differentiate variables from outputs

        Outputs show results after deployment, but variables store reusable data before deployment.
      3. Final Answer:

        To store values that can be reused throughout the configuration -> Option D
      4. Quick Check:

        Variables store reusable values [OK]
      Hint: Variables hold reusable data; outputs show results after deployment [OK]
      Common Mistakes:
      • Confusing variables with outputs
      • Thinking variables delete resources
      • Assuming variables monitor usage
      2. Which of the following is the correct syntax to declare a variable named region with default value us-central1 in a Terraform configuration for GCP?
      easy
      A. var region = "us-central1"
      B. variable "region" { default = "us-central1" }
      C. set variable region = "us-central1"
      D. region := "us-central1"

      Solution

      1. Step 1: Recall Terraform variable syntax

        Terraform uses the keyword 'variable' followed by the name in quotes and a block with 'default' value.
      2. Step 2: Compare options

        variable "region" { default = "us-central1" } matches Terraform syntax exactly; others use invalid or different language syntax.
      3. Final Answer:

        variable "region" { default = "us-central1" } -> Option B
      4. Quick Check:

        Terraform variable syntax uses 'variable' block [OK]
      Hint: Terraform variables use 'variable' block with default inside braces [OK]
      Common Mistakes:
      • Using assignment syntax from other languages
      • Missing quotes around variable name
      • Using := which is not Terraform syntax
      3. Given this Terraform output block:
      output "instance_ip" {
        value = google_compute_instance.vm_instance.network_interface[0].access_config[0].nat_ip
      }

      What will terraform output instance_ip show after deployment?
      medium
      A. The public IP address of the VM instance
      B. The internal IP address of the VM instance
      C. The VM instance name
      D. An error because output syntax is wrong

      Solution

      1. Step 1: Understand the output value path

        The path accesses the VM's network interface, then the first access config's NAT IP, which is the public IP.
      2. Step 2: Confirm output command result

        Running 'terraform output instance_ip' returns the value of that output, which is the public IP address.
      3. Final Answer:

        The public IP address of the VM instance -> Option A
      4. Quick Check:

        Output shows public IP from access_config NAT IP [OK]
      Hint: Access NAT IP in output shows public IP address [OK]
      Common Mistakes:
      • Confusing NAT IP with internal IP
      • Assuming output shows instance name
      • Thinking output block syntax is invalid
      4. You wrote this Terraform variable block:
      variable "zone" {
        default = us-central1-a
      }

      Why does Terraform fail to apply this configuration?
      medium
      A. The default value is missing quotes around the string
      B. Variable name cannot be 'zone'
      C. Default values are not allowed in variables
      D. The block must use 'var' instead of 'variable'

      Solution

      1. Step 1: Check the default value syntax

        Terraform requires string values to be in quotes. Here, us-central1-a is unquoted.
      2. Step 2: Understand Terraform variable rules

        Variable names like 'zone' are valid, default values are allowed, and 'variable' keyword is correct.
      3. Final Answer:

        The default value is missing quotes around the string -> Option A
      4. Quick Check:

        Strings need quotes in Terraform variables [OK]
      Hint: Always quote string default values in Terraform variables [OK]
      Common Mistakes:
      • Forgetting quotes around string values
      • Thinking variable names are restricted
      • Using 'var' instead of 'variable' keyword
      5. You want to create a Terraform output that shows the URL of a deployed Cloud Storage bucket using a variable bucket_name. Which output block correctly uses the variable to build the URL?
      hard
      A. output "bucket_url" { value = "https://storage.googleapis.com/var.bucket_name" }
      B. output "bucket_url" { value = https://storage.googleapis.com/${bucket_name} }
      C. output "bucket_url" { value = "https://storage.googleapis.com/${var.bucket_name}" }
      D. output "bucket_url" { value = "https://storage.googleapis.com/bucket_name" }

      Solution

      1. Step 1: Understand variable interpolation syntax

        Terraform uses ${var.variable_name} inside strings to insert variable values.
      2. Step 2: Check each option for correct syntax

        output "bucket_url" { value = "https://storage.googleapis.com/${var.bucket_name}" } correctly uses "${var.bucket_name}" inside quotes. Others either miss quotes or use wrong syntax.
      3. Final Answer:

        output "bucket_url" { value = "https://storage.googleapis.com/${var.bucket_name}" } -> Option C
      4. Quick Check:

        Use ${var.name} for variable interpolation in outputs [OK]
      Hint: Use ${var.name} inside quotes for variable interpolation [OK]
      Common Mistakes:
      • Missing quotes around the URL string
      • Not using 'var.' prefix for variables
      • Using variable name without interpolation syntax
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard