Skip to content
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

Add examples and tests for !include Atmos YAML function #1080

Merged
merged 14 commits into from
Feb 20, 2025
30 changes: 15 additions & 15 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 31 additions & 32 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/exec/terraform_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ func generateProviderOverrides(atmosConfig *schema.AtmosConfiguration, info *sch
// requires the `Go` templates and Atmos YAML functions to be processed
func needProcessTemplatesAndYamlFunctions(command string) bool {
commandsThatNeedFuncProcessing := []string{
"init",
"plan",
"apply",
"deploy",
"destroy",
"generate",
"output",
"clean",
"shell",
"write",
"force-unlock",
Expand Down
19 changes: 19 additions & 0 deletions tests/fixtures/components/terraform/yaml-functions/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "string_var" {
description = "String output"
value = var.string_var
}

output "boolean_var" {
description = "Boolean output"
value = var.boolean_var
}

output "list_var" {
description = "List output"
value = var.list_var
}

output "map_var" {
description = "Map output"
value = var.map_var
}
28 changes: 28 additions & 0 deletions tests/fixtures/components/terraform/yaml-functions/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
variable "stage" {
description = "Stage where it will be deployed"
type = string
}

variable "string_var" {
description = "String variable"
type = string
default = "test"
}

variable "boolean_var" {
description = "Boolean variable"
type = bool
default = false
}

variable "list_var" {
description = "List variable"
type = list(string)
default = []
}

variable "map_var" {
description = "Map variable"
type = map(string)
default = {}
}
21 changes: 21 additions & 0 deletions tests/fixtures/scenarios/atmos-include-yaml-function/atmos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
base_path: "./"

components:
terraform:
base_path: "../../components/terraform"
apply_auto_approve: false
deploy_run_init: true
init_run_reconfigure: true
auto_generate_backend_file: false

stacks:
base_path: "stacks"
included_paths:
- "deploy/**/*"
excluded_paths:
- "**/_defaults.yaml"
name_pattern: "{stage}"

logs:
file: "/dev/stderr"
level: Info
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# yaml-language-server: $schema=https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json

vars:
stage: nonprod

components:
terraform:
component-1:
metadata:
component: yaml-functions
vars:
string_var: !include stacks/mixins/vars.json .string_var
boolean_var: !include stacks/mixins/vars.yaml .boolean_var
list_var: !include stacks/mixins/vars.tfvars .list_var
map_var: !include stacks/mixins/vars.tfvars .map_var
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"string_var": "abc",
"boolean_var": true,
"list_var": [
"a",
"b",
"c"
],
"map_var": {
"a": 1,
"b": 2,
"c": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
string_var = "abc"
boolean_var = true
list_var = ["a", "b", "c"]
map_var = {
a = 1
b = 2
c = 3
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
string_var: abc
boolean_var: true
list_var:
- a
- b
- c
map_var:
a: 1
b: 2
c: 3
21 changes: 21 additions & 0 deletions tests/test-cases/atmos-include-yaml-function.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
tests:
- name: "terraform !include function test"
enabled: true
tty: true
clean: true
description: "Ensure the !include function works."
workdir: "fixtures/scenarios/atmos-include-yaml-function/"
command: "atmos"
args:
- "describe"
- "component"
- "component-1"
- "-s"
- "nonprod"
expect:
exit_code: 0
stdout:
- "string_var: abc"
- "boolean_var: true"
stderr:
- "^$"
Loading