@@ -14,7 +14,6 @@ import (
1414 "github.com/commitdev/zero/internal/util"
1515 "github.com/commitdev/zero/pkg/util/exit"
1616 "github.com/commitdev/zero/pkg/util/flog"
17- "github.com/k0kubun/pp"
1817 "github.com/manifoldco/promptui"
1918)
2019
@@ -107,7 +106,7 @@ func ValidateProjectName(input string) error {
107106// 1. Execute (this could potentially be refactored into type + data)
108107// 2. type: specific ways of obtaining values (in AWS credential case it will set 2 values to the map)
109108//3.
110- func (p PromptHandler ) RunPrompt (projectParams map [string ]string ) {
109+ func (p PromptHandler ) RunPrompt (projectParams map [string ]string , envVarTranslationMap map [ string ] string ) {
111110 var err error
112111 var result string
113112
@@ -120,7 +119,7 @@ func (p PromptHandler) RunPrompt(projectParams map[string]string) {
120119 // so if community module has an `execute: twitter tweet $ENV`
121120 // it wouldnt leak things the module shouldnt have access to
122121 if p .Parameter .Execute != "" {
123- result = executeCmd (p .Parameter .Execute , projectParams )
122+ result = executeCmd (p .Parameter .Execute , projectParams , envVarTranslationMap )
124123 } else if p .Parameter .Type != "" {
125124 CustomPromptHandler (p .Parameter .Type , projectParams )
126125 } else if p .Parameter .Value != "" {
@@ -172,10 +171,11 @@ func promptParameter(prompt PromptHandler) (error, string) {
172171 return nil , result
173172}
174173
175- func executeCmd (command string , envVars map [string ]string ) string {
176- pp .Print (envVars )
174+ func executeCmd (command string , envVars map [string ]string , envVarTranslationMap map [string ]string ) string {
177175 cmd := exec .Command ("bash" , "-c" , command )
178- cmd .Env = util .AppendProjectEnvToCmdEnv (envVars , os .Environ ())
176+ // Might need to pass down module's translation map as well,
177+ // currently only works in `zero apply`
178+ cmd .Env = util .AppendProjectEnvToCmdEnv (envVars , os .Environ (), envVarTranslationMap )
179179 out , err := cmd .Output ()
180180 flog .Debugf ("Running command: %s" , command )
181181 if err != nil {
@@ -193,7 +193,7 @@ func sanitizeParameterValue(str string) string {
193193
194194// PromptParams renders series of prompt UI based on the config
195195func PromptModuleParams (moduleConfig moduleconfig.ModuleConfig , parameters map [string ]string ) (map [string ]string , error ) {
196-
196+ envVarTranslationMap := moduleConfig . GetParamEnvVarTranslationMap ()
197197 for _ , parameter := range moduleConfig .Parameters {
198198 // deduplicate fields already prompted and received
199199 if _ , isAlreadySet := parameters [parameter .Field ]; isAlreadySet {
@@ -225,12 +225,9 @@ func PromptModuleParams(moduleConfig moduleconfig.ModuleConfig, parameters map[s
225225 // for k, v := range parameters {
226226 // credentialEnvs[k] = v
227227 // }
228- promptHandler .RunPrompt (parameters )
229-
230- // parameters[parameter.Field] = result
231- pp .Print ("Module is done processing %s" , moduleConfig .Name )
232- pp .Print (parameters )
228+ promptHandler .RunPrompt (parameters , envVarTranslationMap )
233229 }
230+ flog .Debugf ("Module %s prompt: \n %#v" , moduleConfig .Name , parameters )
234231 return parameters , nil
235232}
236233
@@ -257,8 +254,9 @@ func paramConditionsMapper(conditions []moduleconfig.Condition) CustomConditionS
257254 return func (params map [string ]string ) bool {
258255 // Prompts must pass every condition to proceed
259256 for i := 0 ; i < len (conditions ); i ++ {
260- if ! conditionHandler (conditions [i ])(params ) {
261- flog .Debugf ("Did not meet condition %v, expected %v to be %v" , conditions [i ].Action , conditions [i ].MatchField , conditions [i ].WhenValue )
257+ cond := conditions [i ]
258+ if ! conditionHandler (cond )(params ) {
259+ flog .Debugf ("Did not meet condition %v, expected %v to be %v" , cond .Action , cond .MatchField , cond .WhenValue )
262260 return false
263261 }
264262 }
0 commit comments