Harness infrastructure as code

From Intense-Visions/harness-engineering · View interactive version

Harness infrastructure as code is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Terraform, CloudFormation, and Pulumi analysis. Module structure, state management, drift prevention, and security posture for infrastructure definitions.

How to use this skill

Skill file

Harness Infrastructure as Code

Terraform, CloudFormation, and Pulumi analysis. Module structure, state management, drift prevention, and security posture for infrastructure definitions.

When to Use

Process

Phase 1: DETECT -- Identify IaC Tool and Structure

  1. Detect IaC tooling. Scan the project for infrastructure definitions:
  1. Identify provider and backend. Parse configuration for:
  1. Map module structure. Build a dependency tree of modules:
  1. Detect environment separation. Identify how environments are managed:
  1. Present detection summary:

```

IaC Detection:

Tool: Terraform v1.7

Provider: AWS (us-east-1, us-west-2)

Backend: S3 with DynamoDB locking

Modules: 8 local, 3 registry

Environments: dev, staging, prod (directory-per-env)

State files: 3 (one per environment)

```


Phase 2: ANALYZE -- Evaluate Patterns and Anti-Patterns

  1. Check state management. Verify state is properly configured:
  1. Evaluate module design. Check modules for:
  1. Check resource naming and tagging. Verify:
  1. Analyze dependency management. Check for:
  1. Check for common anti-patterns:

Phase 3: DESIGN -- Recommend Structure and Patterns

  1. Recommend module decomposition. If monolithic configurations are detected:
  1. Design state management strategy. Recommend:
  1. Recommend drift detection workflow. Design a process to catch manual changes:
  1. Design environment promotion. Recommend a workflow for infrastructure changes:
  1. Recommend security hardening. For each provider:

Phase 4: VALIDATE -- Verify Configuration Correctness

  1. Run static analysis. Execute available validation tools:
  1. Verify variable completeness. For each root module:
  1. Check plan safety. If a plan output is available:
  1. Verify security posture. Run security-focused checks:
  1. Generate validation report:

```

IaC Validation: [PASS/WARN/FAIL]

Format check: PASS (all files formatted)

Validate: PASS (no syntax errors)

Security scan: WARN (2 findings)

Module design: WARN (3 modules missing input validation)

State management: PASS (remote backend with locking)

Recommendations:

1. Add aws_s3_bucket_server_side_encryption_configuration resource

2. Restrict SSH access to VPN CIDR range

3. Add variable validation blocks to network, compute, and storage modules

```


Harness Integration

Success Criteria

Examples

Example: Terraform AWS Multi-Environment Setup

Phase 1: DETECT
  Tool: Terraform v1.6.4
  Provider: AWS (hashicorp/aws ~> 5.0)
  Backend: S3 (us-east-1) with DynamoDB locking
  Modules: 5 local (vpc, ecs, rds, s3, iam), 2 registry (datadog, cloudwatch)
  Environments: dev, staging, prod (directory-per-env with shared modules)

Phase 2: ANALYZE
  State management: PASS (remote, encrypted, locked, per-env)
  Module design: WARN
    - modules/ecs has 450 lines -- recommend splitting into ecs-cluster
      and ecs-service modules
    - modules/rds missing variable validation for instance_class
  Naming: PASS (consistent {project}-{env}-{resource} pattern)
  Tags: WARN (cost-center tag missing on 3 resources)
  Anti-patterns: 1 hardcoded AMI in modules/ecs/main.tf

Phase 3: DESIGN
  1. Split modules/ecs into ecs-cluster and ecs-service
  2. Add data source for AMI lookup instead of hardcoded value
  3. Add variable validation: instance_class must be db.t3.* or db.r6g.*
  4. Add cost-center tag to default_tags in provider configuration
  5. Add scheduled terraform plan for drift detection in CI

Phase 4: VALIDATE
  terraform fmt: PASS
  terraform validate: PASS
  tfsec: WARN (2 findings -- see above)
  checkov: PASS
  Result: WARN -- 5 improvements recommended, no blocking issues

Example: CloudFormation with CDK

Phase 1: DETECT
  Tool: AWS CDK v2.120 (TypeScript)
  Provider: AWS (us-west-2)
  Backend: CloudFormation (managed by CDK)
  Stacks: 3 (NetworkStack, ComputeStack, StorageStack)
  Environments: dev and prod via CDK context

Phase 2: ANALYZE
  Stack design: PASS (clean separation by concern)
  Cross-stack references: PASS (using CfnOutput and Fn::ImportValue)
  Security: WARN
    - ComputeStack: EC2 instance has public IP and open SSH
    - StorageStack: DynamoDB table missing point-in-time recovery
  CDK constructs: Using L2 constructs (good -- higher abstraction)

Phase 3: DESIGN
  1. Add bastion host pattern instead of direct SSH to EC2
  2. Enable point-in-time recovery on DynamoDB table
  3. Add cdk-nag for automated security checks in synthesis
  4. Add stack-level tags via Tags.of(stack).add()

Phase 4: VALIDATE
  cdk synth: PASS (3 templates generated)
  cfn-lint: PASS (all templates valid)
  Security: WARN (2 findings)
  Result: WARN -- 2 security improvements needed

Rationalizations to Reject

| Rationalization | Reality |

| ---------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| "We store state locally because it's just a dev environment" | Local state is not shared between team members. Two developers running terraform apply against the same environment with diverged local state will produce conflicting resource definitions, duplicate resources, or state corruption that requires manual recovery. |

| "We haven't pinned the provider version because we want to automatically get security patches" | Unpinned providers can silently change resource behavior on terraform init. A ~> 5.0 constraint without an upper bound can pull a provider with breaking changes. Pin the minor version and upgrade explicitly via reviewed PRs so changes are intentional. |

| "That S3 bucket has public access because it hosts our static site" | Static site hosting does not require a public bucket ACL. CloudFront with an Origin Access Control (OAC) policy serves files from a private bucket. Public bucket ACLs are a common misconfiguration vector because they apply to all objects, including accidentally uploaded sensitive files. |

| "We'll tag resources properly before we go to production" | Untagged resources accumulate. Cost allocation reports become impossible, security audits cannot identify owners, and decommissioning requires manual investigation of every resource. Tagging must be enforced at resource creation — retroactive tagging at scale is a weeks-long engineering project. |

| "Manual changes are fine for urgent hotfixes — we'll import them to Terraform afterward" | Manual changes without immediate import create drift that may be overwritten by the next terraform apply. The "import it later" step is almost never done. Every manual change that goes unimported erodes the reliability guarantee that IaC provides. |

Gates

Escalation

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.