0
0
GCPcloud~10 mins

Variables and outputs in GCP - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Variables and outputs
Define Variables
Use Variables in Config
Deploy Infrastructure
Capture Outputs
View Outputs
Use Outputs Elsewhere
This flow shows how variables are defined, used in deployment, and how outputs are captured and viewed after deployment.
Execution Sample
GCP
variable "region" {
  default = "us-central1"
}

output "instance_zone" {
  value = "${var.region}-a"
}
Defines a variable for region and outputs a computed instance zone based on that variable.
Process Table
StepActionVariable StateOutput ValueNotes
1Define variable 'region' with default 'us-central1'region = 'us-central1'Variable ready for use
2Use variable 'region' to compute output 'instance_zone'region = 'us-central1'instance_zone = 'us-central1-a'Output expression evaluated
3Deploy infrastructure using variable 'region'region = 'us-central1'Deployment uses variable value
4Capture output 'instance_zone' after deploymentregion = 'us-central1'instance_zone = 'us-central1-a'Output available for viewing
5View output 'instance_zone'region = 'us-central1'instance_zone = 'us-central1-a'Output shown to user
6Use output 'instance_zone' in another config or scriptregion = 'us-central1'instance_zone = 'us-central1-a'Output passed as input elsewhere
7End of processregion = 'us-central1'instance_zone = 'us-central1-a'All steps complete
💡 All variables defined and outputs captured successfully after deployment
Status Tracker
VariableStartAfter Step 1After Step 2Final
regionundefinedus-central1us-central1us-central1
instance_zoneundefinedundefinedus-central1-aus-central1-a
Key Moments - 2 Insights
Why does the output 'instance_zone' depend on the variable 'region'?
Because in the execution_table at Step 2, the output value is computed using the variable 'region', showing the dependency clearly.
Can outputs be used before deployment?
No, outputs are only available after deployment as shown in Step 4 and Step 5 where the output is captured and viewed after infrastructure is deployed.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 2, what is the value of 'instance_zone'?
Aus-central1-a
Bus-central1
Cundefined
Da-us-central1
💡 Hint
Check the 'Output Value' column at Step 2 in the execution_table
At which step does the deployment use the variable 'region'?
AStep 1
BStep 3
CStep 5
DStep 6
💡 Hint
Look at the 'Action' column for deployment usage in the execution_table
If the variable 'region' changed to 'europe-west1', what would be the new output 'instance_zone'?
Aeurope-west1
Bus-central1-a
Ceurope-west1-a
Da-europe-west1
💡 Hint
Refer to how 'instance_zone' is computed from 'region' in the execution_sample and execution_table
Concept Snapshot
Variables store input values for deployment.
Outputs show results after deployment.
Define variables with defaults or inputs.
Use variables in resource configs.
Outputs can be used elsewhere after deployment.
Full Transcript
This lesson shows how variables and outputs work in cloud infrastructure deployment. First, variables are defined with default values or user inputs. Then, these variables are used in the configuration to customize resources. When the infrastructure is deployed, outputs are computed based on variables or resource attributes. Outputs become available after deployment and can be viewed or used in other configurations. The execution table traces each step from defining variables, using them, deploying, capturing outputs, and using outputs elsewhere. Variables hold values throughout, and outputs depend on those variables. This helps make deployments flexible and reusable.