A command-line tool to generate DevOps configuration files (Dockerfiles, Terraform, Kubernetes manifests, Ansible playbooks, GitHub Actions workflows, etc.) using Amazon Q's AI-powered chat interface. Outputs are cleaned, split into files, and formatted automatically.
- Multi-format support: Generate Dockerfiles, Terraform
.tffiles, Kubernetes YAML, Ansible playbooks, GitHub Actions workflows, and more. - ANSI cleanup: Strips ANSI escape sequences and extraneous help text.
- Auto-splitting: Splits multi-file responses into separate files based on markers or filenames.
- HCL & YAML formatting: Optionally parse and re-dump HCL2 and YAML for consistent formatting.
- Interactive mode: Guided prompts for selecting config type, filenames, and custom options.
-
Python 3.8+ installed
-
Amazon Q CLI (
q) installed and configured withq chat -
Optional Python packages for enhanced formatting:
PyYAML(for YAML parsing)hcl2(for HCL2 parsing)
-
Clone this repository:
git clone https://github.com/your-repo/devops-config-generator.git cd devops-config-generator -
Create a new environment:
python3 -m venv test_env source test_env/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Ensure Amazon Q CLI is available:
q chat --help
All prompts and default output filenames are defined in config.py:
CONFIG = {
'dockerfile': {
'prompt': 'Generate a Dockerfile to ...',
'files': ['Dockerfile']
},
'terraform': { ... },
# other types...
}You can override prompts and filenames via CLI flags.
Generate a Dockerfile with defaults:
python main.py dockerfileAdd extra instructions to the prompt:
python main.py dockerfile -o "Use Alpine Linux and include curl"Specify custom output filenames:
python main.py terraform --files main.tf variables.tfCompletely overwrite the default prompt using --prompt:
python main.py dockerfile --prompt "Generate a minimal Dockerfile using Debian slim"
```bash
python main.py terraform --files main.tf variables.tfRun guided prompts:
python main.py --interactiveYou can use multi-stage mode to break generation into planning and execution phases. In planning phase, you'll review the AI's proposed steps before generating files. you can either edit the plan, accept it as it is, or abort it
-
Plan: Run with
--multi-stageto get a step-by-step plan.python main.py dockerfile --multi-stage
-
Execute: After reviewing the plan, re-run without
--multi-stageto generate files:python main.py dockerfile
- Prompt: Constructs a base prompt (from
config.pyor custom) and sends it to Amazon Q viaq chat. - Cleaning: Strips ANSI codes and filters out UI artifacts.
- Splitting: Uses regex and file markers to split combined output into separate files.
- Formatting: Optionally re-parses HCL2 or YAML for pretty output.
- Saving: Writes each block to its target filename, creating directories as needed.
You can read the full blog post here.