-
-
Notifications
You must be signed in to change notification settings - Fork 153
feat: Add interactive file generation for terraform, helmfile, and packer #1971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
59e8305
feat: Add interactive file generation for terraform, helmfile, and pa…
osterman b320973
fix: Address CodeRabbit review feedback for file generation
osterman bf8d40b
docs: Add blog post and roadmap update for interactive file generation
osterman 5251240
Merge remote-tracking branch 'origin/main' into osterman/generate-exa…
osterman 50b620b
docs: Add EmbedExample to generate files documentation
osterman 0e8ed96
test: Add CLI tests for terraform generate files command
osterman 68b0dfc
docs: Add EmbedExample to devcontainer documentation
osterman cf88fbd
chore: Add generate-files example to file-browser plugin
osterman fc36e60
chore: Remove redundant Go test file for terraform generate files
osterman 25f252e
test: Add YAML tests for generate-files example
osterman b16349e
test: Add file creation validation tests for generate-files example
osterman f84af13
Merge remote-tracking branch 'origin/main' into osterman/generate-exa…
osterman cb95083
test: Regenerate snapshots after merging main
osterman 6446c14
Merge remote-tracking branch 'origin/main' into osterman/generate-exa…
osterman e22e25d
fix: Address CodeRabbit review feedback
osterman e2d4adc
Merge remote-tracking branch 'origin/main' into osterman/generate-exa…
osterman 0030287
Merge remote-tracking branch 'origin/main' into osterman/generate-exa…
osterman 9a08ab1
Merge remote-tracking branch 'origin/main' into osterman/generate-exa…
osterman 4bfef8f
fix: Address CodeRabbit review feedback for file generator
osterman e22f4e4
Merge branch 'main' into osterman/generate-example
aknysh 0b17b5e
address comments, add tests
aknysh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Components folder (created during example usage) | ||
| components/ | ||
|
|
||
| # Terraform | ||
| .terraform/ | ||
| *.tfstate* | ||
| *.tfvars.json | ||
| backend.tf.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| # Generate Files | ||
|
|
||
| This example demonstrates how to use `atmos terraform generate files` to generate an entire Terraform component from stack configuration. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `generate` section in component configuration defines files that Atmos will create. This example generates a complete Terraform component including: | ||
|
|
||
| - `variables.tf` - Variable definitions | ||
| - `outputs.tf` - Output definitions | ||
| - `versions.tf` - Terraform version constraints | ||
| - `locals.tf` - Local values | ||
| - `terraform.tfvars` - Variable values | ||
| - `config.json` - Environment-specific configuration | ||
| - `README.md` - Component documentation | ||
|
|
||
| ## Content Types | ||
|
|
||
| | Content Type | Behavior | | ||
| |--------------|----------| | ||
| | String (multiline) | Written as-is, supports Go templates | | ||
| | Map with `.json` extension | Serialized as pretty-printed JSON | | ||
| | Map with `.yaml`/`.yml` extension | Serialized as YAML | | ||
| | Map with `.tf`/`.hcl` extension | Serialized as HCL blocks | | ||
| | Map with `.tfvars` extension | Serialized as HCL attributes (no blocks) | | ||
|
|
||
| ### HCL Generation | ||
|
|
||
| When using map syntax for `.tf` files, Atmos automatically handles: | ||
|
|
||
| - **Labeled blocks** (`variable`, `output`, `resource`, `data`, `module`, `provider`): | ||
| ```yaml | ||
| variable: | ||
| app_name: | ||
| type: string | ||
| description: "Application name" | ||
| ``` | ||
| Generates: `variable "app_name" { type = "string" ... }` | ||
|
|
||
| - **Unlabeled blocks** (`terraform`, `locals`): | ||
| ```yaml | ||
| terraform: | ||
| required_version: ">= 1.0.0" | ||
| ``` | ||
| Generates: `terraform { required_version = ">= 1.0.0" }` | ||
|
|
||
| **Note:** For blocks that need HCL expressions (like `value = var.app_name`), use string templates instead of map syntax. | ||
|
|
||
| ## Template Variables | ||
|
|
||
| Available in templates via `{{ .variable }}`: | ||
|
|
||
| | Variable | Description | | ||
| |----------|-------------| | ||
| | `atmos_component` | Component name | | ||
| | `atmos_stack` | Stack name | | ||
| | `vars` | Component variables (map) | | ||
| | `vars.stage` | Stage from component vars | | ||
|
|
||
| ## Auto-Generation | ||
|
|
||
| Enable automatic file generation on any terraform command: | ||
|
|
||
| ```yaml | ||
| # atmos.yaml | ||
| components: | ||
| terraform: | ||
| auto_generate_files: true | ||
| ``` | ||
|
|
||
| With this enabled, files are regenerated before `init`, `plan`, `apply`, etc. | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Generate the component | ||
|
|
||
| ```bash | ||
| cd examples/generate-files | ||
| mkdir -p components/terraform/demo | ||
| atmos terraform generate files demo -s dev | ||
| ``` | ||
|
|
||
| ### Preview without writing (dry-run) | ||
|
|
||
| ```bash | ||
| atmos terraform generate files demo -s dev --dry-run | ||
| ``` | ||
|
|
||
| ### Delete generated files (clean) | ||
|
|
||
| ```bash | ||
| atmos terraform generate files demo -s dev --clean | ||
| ``` | ||
|
|
||
| ## Generated Files | ||
|
|
||
| After running `atmos terraform generate files demo -s dev`: | ||
|
|
||
| **versions.tf** (HCL map syntax): | ||
| ```hcl | ||
| terraform { | ||
| required_version = ">= 1.0.0" | ||
| } | ||
| ``` | ||
|
|
||
| **locals.tf** (HCL map syntax with templates): | ||
| ```hcl | ||
| locals { | ||
| app_name = "myapp-dev" | ||
| environment = "dev" | ||
| } | ||
| ``` | ||
|
|
||
| **variables.tf** (string template): | ||
| ```hcl | ||
| variable "app_name" { | ||
| type = string | ||
| description = "Application name" | ||
| } | ||
| ``` | ||
|
|
||
| **terraform.tfvars** (flat HCL attributes): | ||
| ```hcl | ||
| app_name = "myapp-dev" | ||
| version = "1.0.0-dev" | ||
| ``` | ||
|
|
||
| **config.json** (JSON from map): | ||
| ```json | ||
| { | ||
| "app": "myapp-dev", | ||
| "stage": "dev", | ||
| "version": "1.0.0-dev" | ||
| } | ||
| ``` | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ```text | ||
| generate-files/ | ||
| ├── atmos.yaml # Atmos configuration (auto_generate_files: true) | ||
| ├── components/ # Generated (gitignored) | ||
| │ └── terraform/ | ||
| │ └── demo/ | ||
| │ ├── variables.tf # Generated | ||
| │ ├── outputs.tf # Generated | ||
| │ ├── versions.tf # Generated | ||
| │ ├── locals.tf # Generated | ||
| │ ├── terraform.tfvars # Generated | ||
| │ ├── config.json # Generated | ||
| │ └── README.md # Generated | ||
| └── stacks/ | ||
| ├── catalog/ | ||
| │ └── demo.yaml # Component with generate section | ||
| └── deploy/ | ||
| ├── dev.yaml # Dev environment | ||
| └── prod.yaml # Prod environment | ||
| ``` | ||
|
|
||
| ## Try It | ||
|
|
||
| ```bash | ||
| cd examples/generate-files | ||
|
|
||
| # Create component directory | ||
| mkdir -p components/terraform/demo | ||
|
|
||
| # Generate files for dev | ||
| atmos terraform generate files demo -s dev | ||
|
|
||
| # See what was generated | ||
| ls components/terraform/demo/ | ||
| cat components/terraform/demo/versions.tf | ||
| cat components/terraform/demo/locals.tf | ||
|
|
||
| # Generate for prod (different values) | ||
| atmos terraform generate files demo -s prod | ||
| cat components/terraform/demo/config.json | ||
|
|
||
| # Clean up | ||
| atmos terraform generate files demo -s dev --clean | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Minimal Atmos configuration for file generation demo | ||
| base_path: "./" | ||
|
|
||
| components: | ||
| terraform: | ||
| base_path: "components/terraform" | ||
| apply_auto_approve: false | ||
| deploy_run_init: true | ||
| auto_generate_files: true | ||
|
|
||
| stacks: | ||
| base_path: "stacks" | ||
| included_paths: | ||
| - "deploy/**/*" | ||
| excluded_paths: | ||
| - "**/_defaults.yaml" | ||
| name_template: "{{ .vars.stage }}" | ||
|
|
||
| logs: | ||
| level: Info | ||
| file: "/dev/stderr" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.