For the complete documentation index, see llms.txt. This page is also available as Markdown.

Configure Terraform for Deploy Change Investigator

Send infrastructure changes as deployment webhooks to track them

Track Terraform infrastructure changes by sending deployment webhooks when terraform apply completes.

Before you begin

  • Deploy Change Investigator setup: Deploy webhook integration created in AI SRE. Go to Deploy Change Investigator to create the webhook endpoint.

  • Terraform access: Permission to modify Terraform configurations or CI/CD pipelines that run Terraform.

  • Deploy webhook URL: Deploy webhook URL from the AI SRE integrations page.


Integration approaches

Send Terraform deployment webhooks using one of these methods:

  1. CI/CD wrapper (recommended): Send webhooks from the CI/CD pipeline after terraform apply.

  2. Local provisioner: Use the local-exec provisioner in your Terraform configuration.

  3. Terraform Cloud: Use run notifications.


Send webhooks from your CI/CD pipeline after Terraform completes.

GitHub Actions

name: Terraform Deploy

on:
  push:
    branches: [main]

env:
  TF_WORKSPACE: production

jobs:
  terraform:
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Terraform
        uses: hashicorp/setup-terraform@v3
        with:
          terraform_version: 1.9.0

      - name: Terraform Init
        run: terraform init

      - name: Terraform Apply
        run: terraform apply -auto-approve

      - name: Send deploy webhook to AI SRE
        if: success()
        run: |
          curl -X POST "${{ secrets.AISRE_DEPLOY_WEBHOOK_URL }}" \
            -H "Content-Type: application/json" \
            -d '{
              "services": [{
                "service": "infrastructure-${{ env.TF_WORKSPACE }}",
                "version": "${{ github.sha }}"
              }],
              "environments": ["${{ env.TF_WORKSPACE }}"],
              "changeId": "${{ github.run_id }}",
              "status": "SUCCESS",
              "deployedBy": "${{ github.actor }}",
              "deployTimestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",
              "metadata": {
                "tool": "terraform",
                "workspace": "${{ env.TF_WORKSPACE }}"
              }
            }'

      - name: Send failure webhook
        if: failure()
        run: |
          curl -X POST "${{ secrets.AISRE_DEPLOY_WEBHOOK_URL }}" \
            -H "Content-Type: application/json" \
            -d '{
              "services": [{
                "service": "infrastructure-${{ env.TF_WORKSPACE }}",
                "version": "${{ github.sha }}"
              }],
              "environments": ["${{ env.TF_WORKSPACE }}"],
              "changeId": "${{ github.run_id }}",
              "status": "FAILURE",
              "deployedBy": "${{ github.actor }}",
              "deployTimestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",
              "metadata": {
                "tool": "terraform"
              }
            }'

Option 2: Local provisioner

Use a null_resource with local-exec provisioner to send webhooks from Terraform.

Create webhook notification resource

Use webhook notification


Set webhook URL securely

Using environment variable

Using terraform.tfvars (add to .gitignore)

Using Terraform Cloud variables

Store the webhook URL as a sensitive workspace variable:

  1. Navigate to workspace Settings, then select Variables

  2. Add a variable:

    • Key: deploy_webhook_url

    • Value: Webhook URL

    • Category: Terraform variable

    • Sensitive: Yes


Extract service information

From outputs

Define outputs to list deployed services:

From resource tags


Provisioner considerations

Run only on create

Handle errors


Testing webhooks

Test from CI/CD

Run an apply in your pipeline and confirm the webhook reaches AI SRE:

  1. Run terraform apply in CI/CD

  2. Check pipeline logs for webhook execution

  3. Navigate to AI SRE, then select Integrations

  4. Click the More icon on the DEPLOY integration

  5. Select Debug

  6. Verify the webhook appears

Test local provisioner

Run an apply locally and confirm the webhook reaches AI SRE:

  1. Run terraform apply locally

  2. Check the console output for curl execution

  3. Verify the webhook in the AI SRE Debug view


Troubleshooting

Terraform local-exec provisioner fails silently when sending AI SRE webhooks

A local-exec provisioner does not fail the apply when curl fails. Add error checking in the provisioner command, for example capture the HTTP status code and exit 1 when it is not 200.

Terraform webhook sent on destroy to AI SRE

The provisioner was configured with when = destroy, so it runs during terraform destroy. Remove the when = destroy argument. A local-exec provisioner runs at create time by default, and create is not a valid value for when in current Terraform.

Terraform variable interpolation errors in AI SRE webhook commands

Variables may not expand in the provisioner command. Use proper HCL string interpolation, for example command = <<-EOT curl ... -d '{\"service\": \"${var.service_name}\


Best practices

Follow these practices to keep Terraform change tracking reliable:

  • Store webhook URLs securely: Use environment variables, Terraform Cloud sensitive variables, or CI/CD secrets.

  • Use the CI/CD wrapper: It is more reliable than provisioners for webhook notifications.

  • Separate infrastructure changes: Track infrastructure deployments separately from application deployments.

  • Version consistently: Use the commit SHA or a timestamp for infrastructure change versions.


Next steps

Last updated

Was this helpful?