-
Notifications
You must be signed in to change notification settings - Fork 0
Add terraform output variables to environment #1104
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
Conversation
…h output to the list of environment variables, has another child function for formatting the json returned by the terraform output command
| // Each output is prefixed with 'TF_VAR_' to make it available as a Terraform variable. | ||
| // Returns a map of environment variable names to their formatted values, or an error if the command fails. | ||
| func (e *TerraformEnvPrinter) getTerraformOutputs(projectPath string) (map[string]string, error) { | ||
| cmd := e.shims.Command("terraform", "-chdir="+projectPath, "output", "-json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For command/exec specifically, the shell package is used when executing commands. This approach abstracts execution so that in the future, we could execute commands against other types of shells--docker exec, SSH, etc.
You can find examples of this elsewhere, but it will end up being something like shell.ExecSilent("terraform", "-chdir=...")
| return nil, fmt.Errorf("failed to run terraform output: %w", err) | ||
| } | ||
| var outputs TerraformOutputs | ||
| if err := json.Unmarshal(outputJSON, &outputs); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be shimmed for test coverage
|
Very close! Other than a couple small things, the key piece is that, if you're in a terraform project folder, the If an if Then when you are in the |
d52bbb4 to
42a726f
Compare
|
Implemented in #1478 |
Child function for GetEnvVars that runs terraform output and adds each output to the list of environment variables, has another child function for formatting the json returned by the terraform output command