Prompt

I need infrastructure code that works in pull requests and CI pipelines

Technology / Cloud Infrastructure1 observationLast seen Oct 25, 2026

Latest observation

Oct 25, 2026OpenAI APIWeb search: off

Absolutely — if you want infrastructure code that works well in pull requests and CI pipelines, the main goal is to make it:

  • non-destructive
  • repeatable
  • plan-first
  • safe for ephemeral environments
  • easy to validate automatically

Here’s a practical pattern that works well for most IaC setups, especially with Terraform, Pulumi, or similar tools.


Recommended workflow

In pull requests

Run only checks and a plan:

  1. Format
  2. Validate / lint
  3. Create a plan
  4. Post the plan back to the PR
  5. Do not apply automatically

In CI on main branch

Run:

  1. format check
  2. validation
  3. plan
  4. manual approval or protected deployment
  5. apply

Example structure

repo/
  infra/
    main.tf
    variables.tf
    outputs.tf
    environments/
      dev.tfvars
      staging.tfvars
      prod.tfvars
  .github/
    workflows/
      pr.yml
      deploy.yml

Terraform example for PR-safe workflows

pr.yml

name: Pull Request Checks

on:
  pull_request:

jobs:
  terraform:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write

    defaults:
      run:
        working-directory: infra

    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Terraform fmt
        run: terraform fmt -check -recursive

      - name: Terraform init
        run: terraform init -input=false

      - name: Terraform validate
        run: terraform validate

      - name: Terraform plan
        run: terraform plan -input=false -no-color -out=tfplan

      - name: Show plan
        run: terraform show -no-color tfplan

This is good for CI, but note:

  • terraform plan may still require cloud credentials
  • you may need remote state access
  • PRs from forks can’t safely use secrets by default

Safer PR design: use speculative plans

In PRs, use a speculative plan only. Do not save or apply it.

For Terraform, plan is already speculative unless you apply it.

If you need cloud access in PRs:

  • use read-only credentials
  • or use a mocked test backend
  • or skip cloud-dependent steps for forked PRs

Example with GitHub Actions and environment separation

deploy.yml

name: Deploy Infrastructure

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: read

    environment: production

    defaults:
      run:
        working-directory: infra

    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Terraform init
        run: terraform init -input=false

      - name: Terraform apply
        run: terraform apply -input=false -auto-approve

Best practices for PR/CI-friendly infra code

1. Keep modules small and composable

  • one module per concern
  • avoid giant monolithic stacks

2. Make environments explicit

Use separate variable files or directories:

  • dev
  • staging
  • prod

3. Avoid interactive prompts

All commands should use:

  • -input=false
  • explicit variables
  • environment variables for secrets

4. Use remote state

This prevents state drift between CI runs.

Examples:

  • S3 + DynamoDB lock for Terraform
  • Terraform Cloud
  • Azure Storage
  • GCS backend

5. Add policy checks

Use tools like:

  • tflint
  • checkov
  • tfsec
  • infracost
  • OPA / Conftest

6. Gate production applies

Require:

  • branch protection
  • manual approval
  • environment approvals

7. Make plans visible in PRs

Post the diff so reviewers can see:

  • what will be created
  • what will change
  • what will be destroyed

If you want ephemeral preview environments

For each PR, you can create temporary infrastructure named by PR number:

  • preview-pr-123

Then destroy it when the PR closes.

This is common for:

  • Kubernetes namespaces
  • feature environments
  • temporary databases
  • preview apps

Example naming pattern:

locals {
  env_name = "pr-${var.pr_number}"
}

In CI:

  • create on PR open
  • update on new commits
  • destroy on PR close

Common pitfalls

  • Using real production credentials in PRs
  • Applying automatically on every push
  • Not locking state
  • Relying on local-only state
  • Allowing secrets in forked PRs
  • Missing cleanup for preview environments

If you tell me your stack, I can generate the exact code

I can produce a ready-to-use setup for any of these:

  • Terraform + GitHub Actions
  • Pulumi + GitHub Actions
  • AWS / Azure / GCP
  • Kubernetes manifests + CI
  • CDK / CDKTF
  • preview environments per PR

If you want, I can generate a complete working example for your cloud/provider and CI system.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.