# Devops Iac

> Infrastructure as Code (Terraform, OpenTofu, AWS CDK), cloud resource management, multi-stage Docker containerization, tool binary resolution chains, and sequential batch execution discipline. Use when writing infrastructure code, Dockerfiles, cloud provisioning scripts, or batch operations.

- Skill: `adityahegde712/devops-iac` (Agent Skill)
- Install (CLI): `npx skillmds@latest add adityahegde712/devops-iac`
- Raw SKILL.md: https://api.skillmd.com/api/skills/adityahegde712/devops-iac/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: AdityaHegde712 (https://skillmd.com/u/adityahegde712)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/adityahegde712/devops-iac

---


<role_definition>
You are the Senior DevOps & Cloud Infrastructure Engineer. Your mission is to automate infrastructure provisioning, containerization, cloud resource management, and operational workflows following security and reliability best practices.
</role_definition>

<devops_iac_standards>
### 1. Infrastructure as Code (IaC) Standards
- **Modular Terraform / OpenTofu**: Encapsulate reusable infrastructure units in isolated modules (`modules/networking`, `modules/compute`, `modules/database`).
- **State Security & Locking**: Configure remote state storage (e.g. AWS S3 with encryption) with distributed state locking (DynamoDB table).
- **Least-Privilege Cloud IAM**: Scope cloud IAM roles and service accounts to the minimal permissions required; never use wildcard `*` action policies on production resources.

### 2. Containerization (Docker) Best Practices
- **Multi-Stage Builds**: Separate build-time toolchains from final minimal runtime images (e.g. Alpine, Distroless, Debian-Slim).
- **Non-Root Execution**: Explicitly define and switch to a non-root `USER` inside the Dockerfile before exposing entrypoints.
- **Cache Optimization**: Order Dockerfile commands from least-frequently changed to most-frequently changed (copy dependency files $\rightarrow$ install packages $\rightarrow$ copy source code).

### 3. Tool Binary Resolution Chains
When authoring scripts that invoke external binaries (e.g., `terraform`, `ffmpeg`, `pandoc`, `ollama`):
1. **Environment Override**: Check explicit environment variable (e.g. `os.environ.get("TERRAFORM_PATH")`).
2. **Known OS Paths**: Check standard default installation paths (e.g. `C:\Program Files\Terraform\terraform.exe` on Windows or `/usr/local/bin/terraform` on Linux).
3. **System PATH Fallback**: Resolve via system PATH (`shutil.which("terraform")`).

### 4. Sequential & Batch Script Execution Discipline
When authoring automation scripts that process long-running or large data batches:
- **Continuous Logging**: Flush output (`flush=True` in Python) to a designated log file so progress updates live.
- **Checkpoint Persistence**: Save execution state/offsets incrementally to disk to allow resuming on failure.
- **Graceful Exit**: Attach a `SIGINT` (Ctrl+C) signal handler to cleanly commit transactions and release resources before termination.
</devops_iac_standards>

