Atmos scaffold dynamic file generation via for_each #126
Replies: 2 comments 1 reply
Proposal: use
|
|
Appreciate the feedback! I didn't consider Two things I'd like to nail down, though: 1. Content, not just 2. Computed axes, concretely. Take three environments, only environments:
dev:
regions:
us-east-1: {...}
staging:
regions:
us-east-1: {...}
production:
regions:
us-east-1: {...}
us-west-2: {...}With matrix:
environments: '{{ answers.environments | jq "keys | sort" }}'
regions: '{{ answers.environments | jq "[.[].regions | keys[]] | unique | sort" }}'
when: 'matrix.regions in answers.environments[matrix.environments].regions'That would work well. Thoughts on that? |
Uh oh!
There was an error while loading. Please reload this page.
Hey folks 👋
atmos scaffold'sspec.files[].when:can only gate a fixed, enumerable set of files declared up front, it can skip a file, but it can't multiply one. That leaves a gap: there's no way to generate one file per item in an unbounded or structured answer (e.g. "onestacks/<env>.yamlper environment the user typed," or "one file per region × environment in a nested answer").This gap is already defined in the current PRD for scaffold 👉 see here.
I'd like to take a stab at this, so I put together a proposal for a
spec.files[].for_each:construct that closes this gap, staying entirely inside the existingspec.files[]interface. What it would look like:for_eachiterates a list, a map, or (only when needed) a delimited free-text string — and it chains: a later step can iterate something nested inside an earlier step's bound item, so one entry can express a cross-product like "one file per environment within each region."Didn't exactly knew where to put it, so I forked off and made some adjustments to the scaffold PRD to serve as a proposal:
📄
docs/prd/atmos-scaffold.md— see "Dynamic File Generation (for_each) — Proposal"🔀 Diff against
cloudposse/atmos:mainFWIW, for truly complex shapes where you'd have a matrix of regions and environments (potentially not even a full matrix if you only want multi-region on some environments but not all), we are already piping through those shapes by just baking a
.atmos/scaffold.yamlprior to kicking off thescaffoldcommand. Not ideal, but works flawlessly.I have a working version of the
for_eachimplementation already to just verify if it was even at all feasible, but I would love thoughts before I sink more time into a final implementation, especially on:spec.files[]is the right home for this vs. a separate top-level constructin:convention (answers.<path>for the first step, unprefixed for a chained step referencing an earlier binding)If the direction looks good, happy to work on it!
All reactions