In this lab you will:
- Authenticate via the CLI
- Configure workspace variables
- Initiate a Terraform run using the API

1. Authenticate and Prepare
Log in to Terraform Cloud via CLI to obtain your API credentials:terraform login opens a browser for authentication and saves your token in ~/.terraform.d/credentials.tfrc.json.
MYORGNAME with your org):
Keep your
TOKEN secure. Do not commit it to source control or share it publicly.2. Retrieve the Workspace ID
Every Terraform Cloud workspace has a unique ID. Store it in an environment variable:
3. Define Variable Payloads
Create three JSON payloads in thejson/ directory to configure workspace variables:
POST /workspaces/:id/vars endpoint:

4. Create Workspace Variables via API
Switch into the JSON directory and run the followingcurl commands:

5. Trigger a Terraform Run via API
Prepare theapply.json payload to create a run:
REPLACEME with your $WORKSPACE_ID:
On macOS, use
sed -i '' for inline replacements.
Conclusion
You have successfully:- Authenticated to Terraform Cloud via CLI
- Used the Workspace Variables API to set variables
- Triggered a Terraform run through the Runs API