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

Introduce Atmos YAML functions #810

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
035991c
updates
aknysh Sep 4, 2024
ae41d91
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Sep 4, 2024
f60eb66
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Sep 5, 2024
e34473f
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Sep 15, 2024
17629d4
updates
aknysh Sep 15, 2024
6e2156b
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Sep 29, 2024
32dc56c
updates
aknysh Sep 29, 2024
595b192
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Oct 1, 2024
ece0d18
updates
aknysh Oct 1, 2024
426d2b2
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Oct 16, 2024
96bc0dc
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Oct 20, 2024
66acbe2
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Oct 21, 2024
c8db31b
updates
aknysh Oct 21, 2024
9a4a5c4
updates
aknysh Oct 21, 2024
4d641ed
updates
aknysh Oct 21, 2024
e54d32b
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Oct 21, 2024
bff3129
updates
aknysh Oct 21, 2024
c4cb255
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Oct 25, 2024
0fc479d
updates
aknysh Oct 27, 2024
115e742
updates
aknysh Oct 28, 2024
55040e0
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Oct 29, 2024
de92c72
updates
aknysh Nov 3, 2024
2ec93c8
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 3, 2024
e72dd86
updates
aknysh Nov 3, 2024
43af832
updates
aknysh Nov 4, 2024
a304a5a
updates
aknysh Nov 4, 2024
de2e9f1
updates
aknysh Nov 4, 2024
de74c18
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 12, 2024
d1f0acd
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 14, 2024
a38a067
updates
aknysh Nov 14, 2024
8df3288
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 15, 2024
9cc8ec1
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 15, 2024
a9f3d6d
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 16, 2024
70f2a43
updates
aknysh Nov 18, 2024
2a315d8
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 20, 2024
ece5296
updates
aknysh Nov 22, 2024
4e26275
updates
aknysh Nov 22, 2024
80ce6f8
updates
aknysh Nov 22, 2024
6b0826d
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 23, 2024
248faec
updates
aknysh Nov 26, 2024
47c43e4
updates
aknysh Nov 26, 2024
26050b5
Merge remote-tracking branch 'origin/main' into yaml-explicit-types-1
aknysh Nov 27, 2024
431c95b
updates
aknysh Nov 27, 2024
e295eb3
updates
aknysh Nov 29, 2024
6cc90b8
updates
aknysh Nov 29, 2024
ce06337
updates
aknysh Nov 29, 2024
bdc7024
updates
aknysh Nov 29, 2024
68f70d8
updates
aknysh Nov 29, 2024
47855e7
updates
aknysh Nov 29, 2024
8029d59
updates
aknysh Nov 29, 2024
eb65be3
updates
aknysh Nov 29, 2024
cf84bdd
updates
aknysh Nov 29, 2024
ca66222
updates
aknysh Nov 29, 2024
1d6098d
updates
aknysh Nov 29, 2024
ab1cf57
updates
aknysh Nov 29, 2024
66d2ea3
updates
aknysh Nov 29, 2024
58bd05b
updates
aknysh Nov 29, 2024
0bc4ca8
updates
aknysh Nov 29, 2024
0ede8ec
updates
aknysh Nov 29, 2024
52909c9
updates
aknysh Nov 29, 2024
9eeff87
updates
aknysh Nov 29, 2024
73de1d6
updates
aknysh Nov 30, 2024
597f581
updates
aknysh Nov 30, 2024
3ba1607
updates
aknysh Nov 30, 2024
513b29f
updates
aknysh Nov 30, 2024
63181a3
updates
aknysh Nov 30, 2024
4bd28b7
updates
aknysh Nov 30, 2024
ec7f1ec
updates
aknysh Nov 30, 2024
3741d22
updates
aknysh Nov 30, 2024
03806f5
updates
aknysh Nov 30, 2024
62b119a
updates
aknysh Nov 30, 2024
5e44336
updates
aknysh Nov 30, 2024
cfee7bb
updates
aknysh Nov 30, 2024
21b626a
updates
aknysh Nov 30, 2024
4f68de7
updates
aknysh Nov 30, 2024
d0749f6
updates
aknysh Nov 30, 2024
56f194f
updates
aknysh Dec 1, 2024
f00b647
updates
aknysh Dec 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# are independent settings (supporting both absolute and relative paths).
# If 'base_path' is provided, 'components.terraform.base_path', 'components.helmfile.base_path', 'stacks.base_path' and 'workflows.base_path'
# are considered paths relative to 'base_path'.
base_path: "./"
base_path: "."

vendor:
# Path to vendor configuration file or directory containing vendor files
Expand Down
4 changes: 2 additions & 2 deletions examples/quick-start-advanced/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ ARG GEODESIC_OS=debian
# https://atmos.tools/
# https://github.com/cloudposse/atmos
# https://github.com/cloudposse/atmos/releases
ARG ATMOS_VERSION=1.109.0
ARG ATMOS_VERSION=1.111.0

# Terraform: https://github.com/hashicorp/terraform/releases
ARG TF_VERSION=1.9.8
ARG TF_VERSION=1.5.7

FROM cloudposse/geodesic:${GEODESIC_VERSION}-${GEODESIC_OS}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ components:
metadata:
# Point to the Terraform component
component: "test/template-functions-test"
settings:
spacelift:
workspace_enabled: false
vars:
enabled: true
name: "test"
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,27 @@ components:
metadata:
# Point to the Terraform component
component: "test/template-functions-test2"
settings:
spacelift:
workspace_enabled: false
vars:
enabled: true
name: "test2"
# Examples of using Atmos template functions to get the outputs of another Atmos component
test_label_id: '{{ (atmos.Component "template-functions-test" .stack).outputs.test_label_id }}'
test_label_id_2: '{{ (atmos.Component "template-functions-test" .stack).outputs.test_label_id }}'
test_1: '{{ (atmos.Component "template-functions-test" .stack).outputs.test_label_id }}'
test_2: '{{ (atmos.Component "template-functions-test" .stack).outputs.test_label_id }}'
test_3: '{{ toJson (atmos.Component "template-functions-test" .stack).outputs.test_list }}'
test_4: '{{ toJson (atmos.Component "template-functions-test" .stack).outputs.test_map }}'
test_5: '{{ toJson (atmos.Component "template-functions-test" .stack).outputs.test_list }}'
test_10: !terraform.output template-functions-test {{ .stack }} test_label_id
test_11: !terraform.output template-functions-test {{ .stack }} test_label_id
test_12: !terraform.output template-functions-test {{ .stack }} test_list
test_13: !terraform.output template-functions-test {{ .stack }} test_map
test_17: !template '{{ .stack }}'
test_18: !template '{{ toJson (atmos.Component "template-functions-test" .stack).outputs.test_list }}'
test_19: !template '{{ toJson (atmos.Component "template-functions-test" .stack).outputs.test_map }}'
test_20: !exec echo 42
test_21: !exec echo 43
test_30: !exec atmos terraform output template-functions-test -s {{ .stack }} --skip-init -- -json test_label_id
test_31: !exec atmos terraform output template-functions-test -s {{ .stack }} --skip-init -- -json test_map
test_32: !exec atmos terraform output template-functions-test -s {{ .stack }} --skip-init -- -json test_list
aknysh marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/arsham/figurine v1.3.0
github.com/bmatcuk/doublestar/v4 v4.7.1
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.3
github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/glamour v0.8.0
github.com/charmbracelet/lipgloss v1.0.0
github.com/elewis787/boa v0.1.2
Expand All @@ -22,7 +22,7 @@ require (
github.com/hashicorp/go-getter v1.7.6
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcl/v2 v2.23.0
github.com/hashicorp/terraform-config-inspect v0.0.0-20241107133921-3adb156ecfe2
github.com/hashicorp/terraform-config-inspect v0.0.0-20241129133400-c404f8227ea6
github.com/hashicorp/terraform-exec v0.21.0
github.com/ivanpirog/coloredcobra v1.0.1
github.com/json-iterator/go v1.1.12
Expand All @@ -40,8 +40,8 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
github.com/zclconf/go-cty v1.15.0
github.com/stretchr/testify v1.10.0
github.com/zclconf/go-cty v1.15.1
golang.org/x/term v0.26.0
gopkg.in/yaml.v3 v3.0.1
mvdan.cc/sh/v3 v3.10.0
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ github.com/chainguard-dev/git-urls v1.0.2 h1:pSpT7ifrpc5X55n4aTTm7FFUE+ZQHKiqpiw
github.com/chainguard-dev/git-urls v1.0.2/go.mod h1:rbGgj10OS7UgZlbzdUQIQpT0k/D4+An04HJY7Ol+Y/o=
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
github.com/charmbracelet/bubbletea v1.2.3 h1:d9MdMsANIYZB5pE1KkRqaUV6GfsiWm+/9z4fTuGVm9I=
github.com/charmbracelet/bubbletea v1.2.3/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM=
github.com/charmbracelet/bubbletea v1.2.4 h1:KN8aCViA0eps9SCOThb2/XPIlea3ANJLUkv3KnQRNCE=
github.com/charmbracelet/bubbletea v1.2.4/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM=
github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs=
github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw=
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
Expand Down Expand Up @@ -813,8 +813,8 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR
github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0=
github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY=
github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4=
github.com/hashicorp/terraform-config-inspect v0.0.0-20241107133921-3adb156ecfe2 h1:h+wcDC5wTiM+5YKjuLtUSWJtdtMVJNCRCPHoWieLpM4=
github.com/hashicorp/terraform-config-inspect v0.0.0-20241107133921-3adb156ecfe2/go.mod h1:Gz/z9Hbn+4KSp8A2FBtNszfLSdT2Tn/uAKGuVqqWmDI=
github.com/hashicorp/terraform-config-inspect v0.0.0-20241129133400-c404f8227ea6 h1:146llE+6P/9YO8RcHRehzGNiS9+OoirKW9/aML6/JIA=
github.com/hashicorp/terraform-config-inspect v0.0.0-20241129133400-c404f8227ea6/go.mod h1:Gz/z9Hbn+4KSp8A2FBtNszfLSdT2Tn/uAKGuVqqWmDI=
github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ=
github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg=
github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7orfb5Ltvec=
Expand Down Expand Up @@ -1168,8 +1168,9 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/tchap/go-patricia/v2 v2.3.1 h1:6rQp39lgIYZ+MHmdEq4xzuk1t7OdC35z/xm0BGhTkes=
Expand Down Expand Up @@ -1205,8 +1206,8 @@ github.com/yuin/goldmark v1.7.4 h1:BDXOHExt+A7gwPCJgPIIq7ENvceR7we7rOS9TNoLZeg=
github.com/yuin/goldmark v1.7.4/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
github.com/yuin/goldmark-emoji v1.0.3 h1:aLRkLHOuBR2czCY4R8olwMjID+tENfhyFDMCRhbIQY4=
github.com/yuin/goldmark-emoji v1.0.3/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=
github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ=
github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty v1.15.1 h1:RgQYm4j2EvoBRXOPxhUvxPzRrGDo1eCOhHXuGfrj5S0=
github.com/zclconf/go-cty v1.15.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
github.com/zealic/xignore v0.3.3 h1:EpLXUgZY/JEzFkTc+Y/VYypzXtNz+MSOMVCGW5Q4CKQ=
Expand Down
14 changes: 12 additions & 2 deletions internal/exec/describe_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,12 @@ func ExecuteDescribeStacks(
u.LogErrorAndExit(cliConfig, err)
}

componentSection = componentSectionConverted
componentSectionFinal, err := ProcessCustomYamlTags(cliConfig, componentSectionConverted)
if err != nil {
return nil, err
}

componentSection = componentSectionFinal
}

// Add sections
Expand Down Expand Up @@ -542,7 +547,12 @@ func ExecuteDescribeStacks(
u.LogErrorAndExit(cliConfig, err)
}

componentSection = componentSectionConverted
componentSectionFinal, err := ProcessCustomYamlTags(cliConfig, componentSectionConverted)
if err != nil {
return nil, err
}

componentSection = componentSectionFinal
}

// Add sections
Expand Down
7 changes: 6 additions & 1 deletion internal/exec/terraform_generate_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ func ExecuteTerraformGenerateBackends(
u.LogErrorAndExit(cliConfig, err)
}

componentSection = componentSectionConverted
componentSectionFinal, err := ProcessCustomYamlTags(cliConfig, componentSectionConverted)
if err != nil {
return err
}

componentSection = componentSectionFinal

if i, ok := componentSection[cfg.BackendSectionName].(map[string]any); ok {
backendSection = i
Expand Down
7 changes: 6 additions & 1 deletion internal/exec/terraform_generate_varfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ func ExecuteTerraformGenerateVarfiles(
u.LogErrorAndExit(cliConfig, err)
}

componentSection = componentSectionConverted
componentSectionFinal, err := ProcessCustomYamlTags(cliConfig, componentSectionConverted)
if err != nil {
return err
}

componentSection = componentSectionFinal

if i, ok := componentSection[cfg.VarsSectionName].(map[string]any); ok {
varsSection = i
Expand Down
16 changes: 14 additions & 2 deletions internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,14 @@ func ProcessStacks(
u.LogErrorAndExit(cliConfig, err)
}

configAndStacksInfo.ComponentSection = componentSectionConverted
componentSectionFinal, err := ProcessCustomYamlTags(cliConfig, componentSectionConverted)
if err != nil {
return configAndStacksInfo, err
}

// Process Atmos manifest sections after processing `Go` templates
configAndStacksInfo.ComponentSection = componentSectionFinal

// Process Atmos manifest sections after processing `Go` templates and custom YAML tags
if i, ok := configAndStacksInfo.ComponentSection[cfg.ProvidersSectionName].(map[string]any); ok {
configAndStacksInfo.ComponentProvidersSection = i
}
Expand Down Expand Up @@ -639,6 +644,13 @@ func processArgsAndFlags(componentType string, inputArgsAndFlags []string) (sche
var globalOptions []string
var indexesToRemove []int

// For commands like `atmos terraform clean` and `atmos terraform plan`, show the command help
if len(inputArgsAndFlags) == 1 {
info.SubCommand = inputArgsAndFlags[0]
info.NeedHelp = true
return info, nil
}

// https://github.com/roboll/helmfile#cli-reference
var globalOptionsFlagIndex int

Expand Down
15 changes: 2 additions & 13 deletions internal/exec/validate_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func validateComponentInternal(
modulePaths []string,
timeoutSeconds int,
) (bool, error) {
if schemaType != "jsonschema" && schemaType != "opa" && schemaType != "cue" {
return false, fmt.Errorf("invalid schema type '%s'. Supported types: jsonschema, opa, cue", schemaType)
if schemaType != "jsonschema" && schemaType != "opa" {
return false, fmt.Errorf("invalid schema type '%s'. Supported types: jsonschema, opa", schemaType)
aknysh marked this conversation as resolved.
Show resolved Hide resolved
}

// Check if the file pointed to by 'schemaPath' exists.
Expand All @@ -202,10 +202,6 @@ func validateComponentInternal(
{
filePath = path.Join(cliConfig.BasePath, cliConfig.Schemas.Opa.BasePath, schemaPath)
}
case "cue":
{
filePath = path.Join(cliConfig.BasePath, cliConfig.Schemas.Cue.BasePath, schemaPath)
}
}

if !u.FileExists(filePath) {
Expand Down Expand Up @@ -248,13 +244,6 @@ func validateComponentInternal(
return false, err
}
}
case "cue":
{
ok, err = ValidateWithCue(componentSection, filePath, schemaText)
if err != nil {
return false, err
}
}
}

return ok, nil
Expand Down
1 change: 1 addition & 0 deletions internal/exec/validate_stacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func ValidateStacks(cliConfig schema.CliConfiguration) error {
cliConfig.Schemas.Atmos.Manifest = atmosManifestDefault
u.LogTrace(cliConfig, fmt.Sprintf("The Atmos JSON Schema file is not configured. Using the default schema '%s'", atmosManifestDefault))
}

atmosManifestJsonSchemaFileAbsPath := path.Join(cliConfig.BasePath, cliConfig.Schemas.Atmos.Manifest)

if u.FileExists(cliConfig.Schemas.Atmos.Manifest) {
Expand Down
36 changes: 36 additions & 0 deletions internal/exec/yaml_func_exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package exec

import (
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)

func processTagExec(cliConfig schema.CliConfiguration, input string) any {
u.LogTrace(cliConfig, fmt.Sprintf("Executing Atmos YAML function: %s", input))

part := strings.TrimPrefix(input, config.AtmosYamlFuncExec)
part = strings.TrimSpace(part)

if part == "" {
err := errors.New(fmt.Sprintf("invalid Atmos YAML function: %s", input))
u.LogErrorAndExit(cliConfig, err)
}

res, err := ExecuteShellAndReturnOutput(cliConfig, part, input, ".", nil, false)
if err != nil {
u.LogErrorAndExit(cliConfig, err)
}

var decoded any
if err := json.Unmarshal([]byte(res), &decoded); err != nil {
return res
}

return decoded
}
31 changes: 31 additions & 0 deletions internal/exec/yaml_func_template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package exec

import (
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/schema"
u "github.com/cloudposse/atmos/pkg/utils"
)

func processTagTemplate(cliConfig schema.CliConfiguration, input string) any {
u.LogTrace(cliConfig, fmt.Sprintf("Executing Atmos YAML function: %s", input))

part := strings.TrimPrefix(input, config.AtmosYamlFuncTemplate)
part = strings.TrimSpace(part)

if part == "" {
err := errors.New(fmt.Sprintf("invalid Atmos YAML function: %s", input))
u.LogErrorAndExit(cliConfig, err)
}

var decoded any
if err := json.Unmarshal([]byte(part), &decoded); err != nil {
return part
}

return decoded
}
Loading
Loading