Configuring Secrets & Environment Variables
Overview
With your deployment principals created, the next step is wiring up secrets and environment variables so Terraform Cloud and GitHub Actions can authenticate securely. This ensures your pipeline can provision resources and trigger deployments without exposing sensitive credentials.
In this section, you’ll configure:
- Terraform Cloud Variable Sets for managing environment variables at the organization level.
- GitHub Repository Secrets for authenticating pipelines.
Terraform Cloud Configuration
-
Log in to Terraform Cloud and select your DSB organization.
-
From the left-hand menu, go to Settings → Variable Sets. You’ll see a page like this:
-
Click Create Organization Variable Set and fill out the details:
- Name: Something descriptive (e.g.,
Azure Deployment Variables
). - Description: Add a short explanation for clarity.
- Variable Set Scope: Select Apply to all projects and workspaces. (This can be narrowed later if needed.)
- Name: Something descriptive (e.g.,
-
Under the Variables section, click Add Variable and define the following keys. Be sure to set each one as an Environment Variable:
TFC_AZ_CLIENT_ID
: Application ID of the Terraform Deployment Service PrincipalTFC_AZ_CLIENT_PASSWORD
: Client Secret value of the Terraform Deployment Service PrincipalTFC_AZ_DEVOPS_GITHUB_PAT
: GitHub PAT generated earlierTFC_AZ_DEVOPS_ORG_SERVICE_URL
:https://dev.azure.com/your_organization
TFC_AZ_DEVOPS_PAT
: Azure DevOps PAT you created earlierTFC_AZ_SUBSCRIPTION_NAME
: Subscription NameTFC_AZ_SUBSCRIPTION_ID
: Subscription ID of your default subscriptionTFC_AZ_TENANT_ID
: Directory (Tenant) ID of the Terraform Service Principal
-
Once complete, your variable set should look something like this:
These values are sensitive. Store them securely and rotate them regularly to maintain security best practices.
GitHub Configuration
Next, configure GitHub to store the secrets required by your pipeline. This will allow GitHub Actions to securely connect to Terraform Cloud.
-
Log in to GitHub and open your fork of the
azure-devsecops-pipeline
repository. -
Navigate to Settings → Secrets and Variables under the Security section.
-
Click Actions, then select New Repository Secret.
-
Create a secret named:
TF_API_TOKEN
→ Paste in the Terraform Cloud API token you generated earlier.
Conclusion
That’s it! You’ve successfully configured your secrets in Terraform Cloud and GitHub. With this step complete, your pipeline is now ready to authenticate, provision resources, and automate deployments securely.