Merge pull request #2408 from yoo/develop

fix(apps): pass environment variables to tf/tofu init
This commit is contained in:
Denis Gukov 2024-10-21 12:20:23 +05:00 committed by GitHub
commit d99940fcd6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 18 deletions

View File

@ -69,7 +69,7 @@ func (t *AnsibleApp) Log(msg string) {
t.Logger.Log(msg)
}
func (t *AnsibleApp) InstallRequirements() error {
func (t *AnsibleApp) InstallRequirements(environmentVars *[]string) error {
if err := t.installCollectionsRequirements(); err != nil {
return err
}

View File

@ -33,6 +33,6 @@ func removeSensitiveEnvs(envs []string) (res []string) {
type LocalApp interface {
SetLogger(logger task_logger.Logger) task_logger.Logger
InstallRequirements() error
InstallRequirements(environmentVars *[]string) error
Run(args []string, environmentVars *[]string, inputs map[string]string, cb func(*os.Process)) error
}

View File

@ -75,7 +75,7 @@ func (t *ShellApp) SetLogger(logger task_logger.Logger) task_logger.Logger {
return logger
}
func (t *ShellApp) InstallRequirements() error {
func (t *ShellApp) InstallRequirements(environmentVars *[]string) error {
return nil
}

View File

@ -83,8 +83,8 @@ func (t *TerraformApp) SetLogger(logger task_logger.Logger) task_logger.Logger {
return logger
}
func (t *TerraformApp) init() error {
cmd := t.makeCmd(t.Name, []string{"init"}, nil)
func (t *TerraformApp) init(environmentVars *[]string) error {
cmd := t.makeCmd(t.Name, []string{"init"}, environmentVars)
t.Logger.LogCmd(cmd)
err := cmd.Start()
if err != nil {
@ -94,8 +94,8 @@ func (t *TerraformApp) init() error {
return cmd.Wait()
}
func (t *TerraformApp) selectWorkspace(workspace string) error {
cmd := t.makeCmd(string(t.Name), []string{"workspace", "select", "-or-create=true", workspace}, nil)
func (t *TerraformApp) selectWorkspace(workspace string, environmentVars *[]string) error {
cmd := t.makeCmd(string(t.Name), []string{"workspace", "select", "-or-create=true", workspace}, environmentVars)
t.Logger.LogCmd(cmd)
err := cmd.Start()
if err != nil {
@ -105,8 +105,8 @@ func (t *TerraformApp) selectWorkspace(workspace string) error {
return cmd.Wait()
}
func (t *TerraformApp) InstallRequirements() (err error) {
err = t.init()
func (t *TerraformApp) InstallRequirements(environmentVars *[]string) (err error) {
err = t.init(environmentVars)
if err != nil {
return
}
@ -117,7 +117,7 @@ func (t *TerraformApp) InstallRequirements() (err error) {
workspace = t.Inventory.Inventory
}
err = t.selectWorkspace(workspace)
err = t.selectWorkspace(workspace, environmentVars)
return
}

View File

@ -399,7 +399,12 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
t.SetStatus(task_logger.TaskRunningStatus) // It is required for local mode. Don't delete
err = t.prepareRun()
environmentVariables, err := t.getEnvironmentENV()
if err != nil {
return
}
err = t.prepareRun(&environmentVariables)
if err != nil {
return err
}
@ -425,11 +430,6 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
return
}
environmentVariables, err := t.getEnvironmentENV()
if err != nil {
return
}
if t.Inventory.SSHKey.Type == db.AccessKeySSH && t.Inventory.SSHKeyID != nil {
environmentVariables = append(environmentVariables, fmt.Sprintf("SSH_AUTH_SOCK=%s", t.sshKeyInstallation.SSHAgent.SocketFile))
}
@ -457,7 +457,7 @@ func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
}
func (t *LocalJob) prepareRun() error {
func (t *LocalJob) prepareRun(environmentVars *[]string) error {
t.Log("Preparing: " + strconv.Itoa(t.Task.ID))
if err := checkTmpDir(util.Config.TmpPath); err != nil {
@ -496,7 +496,7 @@ func (t *LocalJob) prepareRun() error {
return err
}
if err := t.App.InstallRequirements(); err != nil {
if err := t.App.InstallRequirements(environmentVars); err != nil {
t.Log("Running galaxy failed: " + err.Error())
return err
}