Refactor a copied template into one parameterised module
Task
Start from the failure mode the lesson describes -- two near-identical copies that have drifted -- and refactor them into a single parameterised module. Then prove the two environments still differ only in the ways you intended.
Steps
- Write one template describing a small environment, copy it to a second file, and change five things in the copy: two deliberate (size and name) and three that represent drift (a missing tag, a different storage setting, an extra rule).
- Diff the two files and record all five differences in
lab/drift.md, labelling each as intended or accidental. - Refactor into a single module with parameters for the intended differences only. Create two small value files, one per environment.
- Run plan for both environments and save the outputs. Diff the two plans and confirm the only differences are the parameterised ones.
- Add a type and a constraint to every parameter, then deliberately pass an invalid value and capture the validation failure in
lab/invalid.txt.
Verify
grep -Eci 'intended' lab/drift.md
grep -Eci 'accidental|drift' lab/drift.md
test -s lab/invalid.txt && grep -Eci 'invalid|not allowed|must be|error' lab/invalid.txt
The validation capture is the important one: a parameter with no constraint fails halfway through an apply instead of at validation, which is a much worse place to find out.
This is an independent study companion for CompTIA Cloud+ CV0-004 and is not produced by or endorsed by CompTIA.