Solved: Do you separate template browsing from deployment in your internal IaC tooling?
Source: Dev.to
The Problem: Coupled Discovery & Deployment
Coupling IaC template browsing with deployment often results in:
- Template sprawl & cognitive overload â Hundreds of Terraform modules, CloudFormation templates, Helm charts, etc., sit in a monolithic repo with little categorisation or search capability.
- Errorâprone deployments â Poorly documented parameters force users to guess or manually extract values, leading to misconfigurations, failed runs, and security gaps.
- Slow provisioning & low selfâservice adoption â Teams rely on a central DevOps/platform group, creating bottlenecks and delaying projects.
- Lack of standardisation & guardrails â Adâhoc copying/modifying of templates drifts away from organisational policies and compliance requirements.
Three Primary Solutions for Separation
| Approach | Core Idea | When It Shines |
|---|---|---|
| Dedicated Template Catalog | A userâfriendly UI that lists curated IaC templates with metadata, forms for input, and oneâclick deployment triggers. | Teams need a lowâcode, selfâservice portal; governance is a priority. |
| CLIâDriven Discovery | Enhanced commandâline tools that provide searchable, colourâcoded listings, autoâcompletion, and validation before execution. | Scriptingâheavy environments; power users prefer terminal workflows. |
| GitOps with PullâRequestâBased SelfâService | Templates live in Git; users submit PRs that are reviewed, merged, and automatically reconciled by CI/CD pipelines. | Organizations that value a single source of truth, auditability, and automated reconciliation, even at the cost of higher initial setup. |
Why GitOps Often Wins
- Single source of truth â All templates and version history reside in Git.
- Strong auditability â Every change is captured in a PR, with reviewers, comments, and approvals.
- Builtâin review process â Misâconfigurations are caught early during code review.
The tradeâoff is a more complex initial setup (repositories, CI pipelines, policy enforcement), but the longâterm benefits in compliance and reliability are substantial.
How a Dedicated Template Catalog Works
- Webâbased interface â presents a curated list of IaC templates.
- Each entry includes:
- Name & description â humanâreadable.
- Categorisation â e.g., Web App, Database, Networking.
- Input parameters â descriptions, defaults, validation rules.
- Estimated cost â optional, if integrated with costâmanagement tools.
- Links â to detailed documentation or source code.
- User fills a form with the required variables.
- The portal triggers deployment via an underlying CI/CD pipeline or directly through IaC tools, abstracting away the raw commands.
Examples of catalog platforms: Spotifyâs Backstage, HashiCorp Terraform Cloud/Enterprise Workspaces, or custom internal portals.
Sample Template: AWSâŻS3 Static Website (Terraform)
# main.tf for S3 static website module (in your template repo)
resource "aws_s3_bucket" "website_bucket" {
bucket = var.bucket_name
acl = "public-read"
website {
index_document = "index.html"
error_document = "error.html"
}
tags = {
Environment = var.environment
Project = var.project
}
}
resource "aws_s3_bucket_policy" "website_policy" {
bucket = aws_s3_bucket.website_bucket.id
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Principal = "*",
Action = "s3:GetObject",
Resource = "${aws_s3_bucket.website_bucket.arn}/*"
}
]
})
}
variable "bucket_name" {
description = "The unique name for the S3 bucket."
type = string
}
variable "environment" {
description = "The deployment environment (e.g., dev, staging, prod)."
type = string
}
variable "project" {
description = "The project name associated with this resource."
type = string
}
In a catalog UI, the variables bucket_name, environment, and project appear as form fields with the descriptions above, guiding the user. Submitting the form triggers a Terraform run in a preâconfigured workspace, provisioning the static website automatically.
Benefits of Decoupling Discovery & Deployment
- Enhanced Discoverability â A central, searchable catalog makes finding the right template trivial.
- Improved User Experience â Intuitive forms, clear descriptions, and preâvalidation reduce mistakes.
- Standardisation & Governance â Only vetted templates are exposed, and organisational policies are enforced automatically.
- SelfâService Enablement â Teams can provision infrastructure without waiting on a central platform group, accelerating delivery cycles.
Bottom Line
Separating IaCâtemplate discovery from the deployment processâwhether via a UIâdriven catalog, an enriched CLI, or a GitOps workflowâeliminates âtemplate sprawl,â reduces cognitive load, and creates a safer, faster path to infrastructure provisioning. Choose the approach that aligns with your teamâs maturity, tooling preferences, and governance requirements, and watch selfâservice adoption and developer productivity soar.
Template Discovery Approaches
Approved templates are available, promoting best practices and compliance.
Benefits
- Reduced Cognitive Load â Users donât need to know IaC syntax or CLI commands.
Considerations
- Development & Maintenance Overhead â Building and maintaining a custom portal can be resourceâintensive.
- Potential for Drift â If the portalâs template definitions arenât kept in sync with the actual IaC code, it can lead to confusion.
- Limited Flexibility â May not support highly custom or experimental deployments easily.
CLIâBased Approach
This approach emphasizes a robust commandâline interface (CLI) that provides specific commands for:
- Template discovery â list available templates.
- Detailed parameter explanation â show variables, descriptions, defaults, etc.
- Preâdeployment validation â verify inputs before the actual deployment command.
Itâs ideal for teams comfortable with CLI tools and scripting.
How It Works
Instead of a GUI, users interact with a custom CLI tool (or a set of wellâdefined scripts). Typical commands include:
list-templatesâ show all discoverable templates.describe-template <template>â display rich metadata, variables, and documentation.validate-template <template>â run static checks on the template.deploy-template <template> [paramsâŚ]â perform the actual deployment.
The discovery phase focuses on providing rich metadata directly at the command line, often pulling from structured documentation or code comments.
Directory Structure for IaC Templates
iac/
âââ modules/
â âââ s3-website/
â â âââ main.tf
â â âââ variables.tf
â â âââ README.md
â âââ rds-instance/
â âââ main.tf
â âââ variables.tf
â âââ README.md
âââ environments/
â âââ dev/
â âââ prod/
â âââ staging/
âââ templates/
âââ s3-static-site.yaml # CloudFormation template
âââ ec2-webserver.json # CloudFormation template
âââ eks-cluster.tf # Terraform root module for EKS
- Each moduleâs
README.mdprovides detailed documentation. - The
templates/folder contains readyâtoâapply root modules.
Sample iac-helper Bash Script (Simplified)
#!/usr/bin/env bash
# Root directory for IaC assets
IAC_ROOT_DIR="iac"
# ----------------------------------------------------------------------
# List all available IaC templates (modules and rootâmodule files)
# ----------------------------------------------------------------------
list_templates() {
echo "Available IaC Templates:"
# List modules
find "$IAC_ROOT_DIR/modules" -maxdepth 1 -mindepth 1 -type d -print0 |
xargs -0 -n 1 basename |
while read -r template; do
echo " - $template"
done
# List rootâmodule files (Terraform, CloudFormation, JSON)
find "$IAC_ROOT_DIR/templates" -maxdepth 1 -type f \
\( -name "*.tf" -o -name "*.yaml" -o -name "*.json" \) -print0 |
xargs -0 -n 1 basename |
sed -E 's/\.(tf|yaml|json)//' |
while read -r template; do
echo " - $template (Root Module)"
done
}
# ----------------------------------------------------------------------
# Show detailed information about a specific template
# ----------------------------------------------------------------------
describe_template() {
local TEMPLATE_NAME=$1
if [[ -d "$IAC_ROOT_DIR/modules/$TEMPLATE_NAME" ]]; then
echo "Description for module: $TEMPLATE_NAME"
cat "$IAC_ROOT_DIR/modules/$TEMPLATE_NAME/README.md" 2>/dev/null ||
echo "No README.md found."
echo
echo "Variables:"
terraform-docs md "$IAC_ROOT_DIR/modules/$TEMPLATE_NAME" |
sed -n '/^| Name | Description | Type | Default | Required |/,/^$/p'
elif [[ -f "$IAC_ROOT_DIR/templates/$TEMPLATE_NAME.tf" ]]; then
echo "Description for root module: $TEMPLATE_NAME.tf"
terraform-docs md "$IAC_ROOT_DIR/templates/$TEMPLATE_NAME.tf" |
sed -n '/^| Name | Description | Type | Default | Required |/,/^$/p'
elif [[ -f "$IAC_ROOT_DIR/templates/$TEMPLATE_NAME.yaml" ]]; then
echo "Description for CloudFormation template: $TEMPLATE_NAME.yaml"
yq e '.Parameters | to_entries[] | .key + ": " + .value.Description' \
"$IAC_ROOT_DIR/templates/$TEMPLATE_NAME.yaml"
else
echo "Template '$TEMPLATE_NAME' not found."
fi
}
# ----------------------------------------------------------------------
# Deploy a template (placeholder â real implementation would be more complex)
# ----------------------------------------------------------------------
deploy_template() {
local TEMPLATE_NAME=$1
# ... logic to run `terraform apply` or `aws cloudformation create-stack`
echo "Deploying $TEMPLATE_NAME..."
# Example (simplified):
# terraform apply -var="bucket_name=$2" -var="environment=$3" \
# "$IAC_ROOT_DIR/modules/$TEMPLATE_NAME"
}
# ----------------------------------------------------------------------
# Commandâline interface
# ----------------------------------------------------------------------
case "$1" in
list)
list_templates
;;
describe)
if [[ -z "$2" ]]; then
echo "Usage: iac-helper describe <template-name>"
exit 1
fi
describe_template "$2"
;;
deploy)
echo "Deploy command not fully implemented in this example."
echo "Usage: iac-helper deploy <template-name> [params...]"
;;
*)
echo "Usage: iac-helper [list|describe|deploy] ..."
;;
esac
Example Usage
iac-helper list
iac-helper describe s3-website
iac-helper deploy s3-website bucket_name=my-unique-site-name environment=dev
Advantages & Disadvantages of the CLI Approach
| Aspect | Advantages | Disadvantages |
|---|---|---|
| Low overhead | Minimal development effort compared with a full UI portal. | â |
| Scriptingâfriendly | Easy to embed in CI/CD pipelines and local automation scripts. | â |
| Precision & control | Advanced users can specify exactly what they need. | Steeper learning curve for newcomers. |
| Versionâcontrol native | Docs and helper scripts live alongside IaC code. | Effectiveness depends on comprehensive, upâtoâdate docs. |
| Learning curve | â | Requires comfort with CLI tools and syntax. |
| Documentation dependent | â | If docs drift, the CLI becomes unreliable. |
| Discoverability | â | Less visual and intuitive for nonâtechnical users. |
GitOpsâBased Approach
GitOps separates the desired state of infrastructure (defined in Git) from the operational process that brings that state to life.
Repository Types
| Repository | Purpose | Example |
|---|---|---|
| Template Repositories | Store core IaC modules, Helm charts, etc. | infraâtemplates |
| Configuration Repositories | One per environment (e.g., infraâprod, infraâdev). Teams submit PRs here to declare the desired state. | infraâprod |
GitOps Operator
Tools such as ArgoâŻCD or FluxâŻCD watch the configuration repositories, detect changes, and automatically apply the referenced templates with the supplied values.
Workflow
- Browse the template repository to locate the needed module or chart.
- Create a PR in the configuration repository that references the chosen template and supplies required parameters.
- Review the PRâautomated policy checks and human approvals ensure compliance.
- Merge the PR; the GitOps operator detects the change and reconciles the infrastructure to match the declared state.
Closing Thoughts
Whether you opt for a UIâdriven catalog, a powerful CLI, or a GitOpsâcentric workflow, the key is to decouple discovery from deployment. This separation reduces cognitive load, enforces governance, and empowers teams to provision infrastructure quickly and safely. Align the chosen approach with your organizationâs maturity and tooling preferences to unlock faster, more reliable selfâservice.