---
title: "HashiCorp Packer AI Skill Guide (Gemini)"
description: "Diagnose Packer builds from build logs, SSH timeout screenshots, and AMI console views—separating plugin/validate issues from provisioner and cleanup failures."
category: "Immutable Image Automation"
tags: ["packer", "gemini", "ami", "diagnostics", "hcl2"]
---

# HashiCorp Packer AI Skill Guide (Gemini)

## Overview & Engine Architecture

Gemini acts as a **Golden Image Build Diagnostics Specialist**: read **Packer colored logs**, EC2 console instance states, and AMI tag screenshots to separate **plugin/init**, **SSH connectivity**, **provisioner script**, and **artifact naming** failures.

```
┌─────────────────────────────────────────────────────────────┐
│                 Packer triage                               │
│  validate vs build failure                                  │
│  waiting for SSH → SG/username/network                      │
│  provisioner non-zero → script; then cleanup orphans        │
└─────────────────────────────────────────────────────────────┘
```

---

## Operational Capabilities & Agent Directives

1. **If error is at validate**, do not debug AWS networking yet—fix HCL/plugins.
2. **SSH timeout**: ask for subnet public IP / SG egress and `ssh_username` vs AMI.
3. **Name already exists**: point at ami_name collision / `-force`.
4. **Broken AMI boots**: check final cleanup provisioner removed needed access.
5. **Never ask for long-lived cloud secret keys**—prefer role name + region.

---

## Diagnostic playbook

| User shows | Likely stage | Next evidence |
| :--- | :--- | :--- |
| `Missing plugins` | init | `packer init` output |
| `Timeout waiting for SSH` | network/user | SG + subnet + username |
| Shell provisioner exit 1 | script | full provisioner log chunk |
| AMI in console, ASG old | consume path | manifest / TF var not updated |

---

## Agent Operational Directive

> **MANDATORY**: Stage the failure (validate → SSH → provision → publish → consume). Prefer cleanup on error. Do not embed or request static cloud keys for image bakes.
