Skip to main content
demo.yaml2.9 KB
View on GitHub
# Base component configuration with file generation
# This example generates the entire Terraform component from stack configuration
components:
terraform:
demo:
vars:
app_name: "myapp"
app_version: "1.0.0"
features:
- feature1
- feature2

generate:
# Generate versions.tf using HCL map syntax
# The 'terraform' block doesn't need labels, so map syntax works perfectly
"versions.tf":
terraform:
required_version: ">= 1.0.0"

# Generate locals.tf using HCL map syntax
# The 'locals' block takes simple key-value pairs
"locals.tf":
locals:
environment: "{{ .vars.stage }}"
app_name: "{{ .vars.app_name }}"

# Generate variables.tf using string template
# String templates are better for blocks with HCL expressions/types
"variables.tf": |
variable "stage" {
type = string
description = "Stage (environment) name"
}

variable "app_name" {
type = string
description = "Application name"
}

variable "app_version" {
type = string
description = "Application version"
}

variable "features" {
type = list(string)
description = "List of enabled features"
default = []
}

# Generate outputs.tf using string template
# Outputs reference variables, so string templates preserve HCL expressions
"outputs.tf": |
output "app_name" {
description = "The application name"
value = var.app_name
}

output "app_version" {
description = "The application version"
value = var.app_version
}

output "features" {
description = "List of enabled features"
value = var.features
}

# Generate terraform.tfvars with flat attributes
"terraform.tfvars":
app_name: "{{ .vars.app_name }}"
app_version: "{{ .vars.app_version }}"

# Generate config.json with templated values (map -> JSON)
"config.json":
app: "{{ .vars.app_name }}"
app_version: "{{ .vars.app_version }}"
stage: "{{ .vars.stage }}"

# Generate README from string template
"README.md": |
# {{ .atmos_component }}

> **Note:** This component was generated by `atmos terraform generate files`.
> Do not edit these files directly. Modify the stack configuration instead.

## Source

- **Stack:** `{{ .atmos_stack }}`
- **Catalog:** `stacks/catalog/demo.yaml`

## Regenerate

```bash
atmos terraform generate files {{ .atmos_component }} -s {{ .atmos_stack }}
```

Related Documentation