GitLab CI Integration
Add DriftWise to your .gitlab-ci.yml pipeline.
Pipeline Example
.gitlab-ci.yml
plan:
stage: plan
script:
- terraform plan -out=tfplan
- terraform show -json tfplan > plan.json
- |
curl -sX POST "https://app.driftwise.ai/api/v2/orgs/$DRIFTWISE_ORG_ID/analyze" \
-H "x-api-key: $DRIFTWISE_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"plan_json\": $(cat plan.json | jq -Rs .),
\"ci\": {
\"repo_owner\": \"$CI_PROJECT_NAMESPACE\",
\"repo_name\": \"$CI_PROJECT_NAME\",
\"pr_number\": $CI_MERGE_REQUEST_IID,
\"commit_sha\": \"$CI_COMMIT_SHA\",
\"branch\": \"$CI_COMMIT_BRANCH\"
}
}"
CI/CD Variables
Add these in your project settings (Settings > CI/CD > Variables):
| Variable | Type | Masked | Value |
|---|---|---|---|
DRIFTWISE_API_KEY | Variable | Yes | Your API key (dw2_...) |
DRIFTWISE_ORG_ID | Variable | No | Your organization ID |
Notes
jqmust be available in your CI runner image (most Terraform images include it)- The
cimetadata block is optional but helps DriftWise link the analysis to the merge request - The response is synchronous with up to a 120-second timeout