@@ -6,13 +6,19 @@ import (
66
77 "github.com/samber/lo"
88
9+ cfg "github.com/cloudposse/atmos/pkg/config"
910 "github.com/cloudposse/atmos/pkg/schema"
1011 u "github.com/cloudposse/atmos/pkg/utils"
1112)
1213
1314var componentFuncSyncMap = sync.Map {}
1415
15- func componentFunc (atmosConfig schema.AtmosConfiguration , component string , stack string ) (any , error ) {
16+ func componentFunc (
17+ atmosConfig schema.AtmosConfiguration ,
18+ configAndStacksInfo schema.ConfigAndStacksInfo ,
19+ component string ,
20+ stack string ,
21+ ) (any , error ) {
1622 u .LogTrace (fmt .Sprintf ("Executing template function 'atmos.Component(%s, %s)'" , component , stack ))
1723
1824 stackSlug := fmt .Sprintf ("%s-%s" , stack , component )
@@ -42,41 +48,47 @@ func componentFunc(atmosConfig schema.AtmosConfiguration, component string, stac
4248 return nil , err
4349 }
4450
51+ // Process Terraform remote state
4552 var terraformOutputs map [string ]any
46-
47- // Check if the component in the stack is configured with the 'static' remote state backend,
48- // in which case get the `output` from the static remote state instead of executing `terraform output`
49- remoteStateBackendStaticTypeOutputs , err := GetComponentRemoteStateBackendStaticType (sections )
50- if err != nil {
51- return nil , err
52- }
53-
54- if remoteStateBackendStaticTypeOutputs != nil {
55- terraformOutputs = remoteStateBackendStaticTypeOutputs
56- } else {
57- // Execute `terraform output`
58- terraformOutputs , err = execTerraformOutput (& atmosConfig , component , stack , sections )
53+ if configAndStacksInfo .ComponentType == cfg .TerraformComponentType {
54+ // Check if the component in the stack is configured with the 'static' remote state backend,
55+ // in which case get the `output` from the static remote state instead of executing `terraform output`
56+ remoteStateBackendStaticTypeOutputs , err := GetComponentRemoteStateBackendStaticType (sections )
5957 if err != nil {
6058 return nil , err
6159 }
62- }
6360
64- outputs := map [string ]any {
65- "outputs" : terraformOutputs ,
66- }
61+ if remoteStateBackendStaticTypeOutputs != nil {
62+ terraformOutputs = remoteStateBackendStaticTypeOutputs
63+ } else {
64+ // Execute `terraform output`
65+ terraformOutputs , err = execTerraformOutput (& atmosConfig , component , stack , sections )
66+ if err != nil {
67+ return nil , err
68+ }
69+ }
6770
68- sections = lo .Assign (sections , outputs )
71+ outputs := map [string ]any {
72+ "outputs" : terraformOutputs ,
73+ }
74+
75+ sections = lo .Assign (sections , outputs )
76+ }
6977
7078 // Cache the result
7179 componentFuncSyncMap .Store (stackSlug , sections )
7280
7381 if atmosConfig .Logs .Level == u .LogLevelTrace {
74- u .LogTrace (fmt .Sprintf ("Executed template function 'atmos.Component(%s, %s)'\n \n 'outputs' section:" , component , stack ))
75- y , err2 := u .ConvertToYAML (terraformOutputs )
76- if err2 != nil {
77- u .LogError (err2 )
78- } else {
79- u .LogTrace (y )
82+ u .LogTrace (fmt .Sprintf ("Executed template function 'atmos.Component(%s, %s)'" , component , stack ))
83+
84+ if configAndStacksInfo .ComponentType == cfg .TerraformComponentType {
85+ u .LogTrace ("'outputs' section:" )
86+ y , err2 := u .ConvertToYAML (terraformOutputs )
87+ if err2 != nil {
88+ u .LogError (err2 )
89+ } else {
90+ u .LogTrace (y )
91+ }
8092 }
8193 }
8294
0 commit comments