Skip to content

Commit

Permalink
Merge pull request #36 from edenlabllc/feature/RMK-34-support-terrafo…
Browse files Browse the repository at this point in the history
…rm-outputs-of-boolean-types

 #34 - add support Terraform outputs of boolean types
  • Loading branch information
apanasiuk-el authored Jul 25, 2024
2 parents 0084df6 + dc97212 commit b3f447c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
27 changes: 17 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"strconv"
"strings"
"text/template"

Expand Down Expand Up @@ -51,8 +52,8 @@ type Config struct {
}

type ExportedVars struct {
TerraformOutput map[string]string `yaml:"terraform-output,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
TerraformOutput map[string]interface{} `yaml:"terraform-output,omitempty"`
Env map[string]string `yaml:"env,omitempty"`
}

type HookMapping struct {
Expand Down Expand Up @@ -117,7 +118,7 @@ func (conf *Config) InitConfig(terraformOutput bool) *Config {
}

conf.ExportedVars = ExportedVars{
TerraformOutput: make(map[string]string),
TerraformOutput: make(map[string]interface{}),
Env: make(map[string]string),
}

Expand Down Expand Up @@ -165,8 +166,8 @@ func (conf *Config) GetConfigs(all bool) error {
func (conf *Config) SetRootDomain(c *cli.Context, gitSpecID string) error {
hostedZoneVar := system.TerraformVarsPrefix + system.TerraformVarHostedZoneName
if !c.IsSet("root-domain") {
if hostedZoneName, ok := conf.TerraformOutput[hostedZoneVar]; ok && len(hostedZoneName) > 0 {
if err := c.Set("root-domain", hostedZoneName); err != nil {
if hostedZoneName, ok := conf.TerraformOutput[hostedZoneVar]; ok && len(hostedZoneName.(string)) > 0 {
if err := c.Set("root-domain", hostedZoneName.(string)); err != nil {
return err
}
} else {
Expand Down Expand Up @@ -225,12 +226,18 @@ func (conf *Config) GetTerraformOutputs() error {
return err
}

if reflect.TypeOf(getVar.Type).Kind() == reflect.String {
conf.TerraformOutput[key] = getVar.Value.(string)
conf.Env[strings.ToUpper(strings.ReplaceAll(key, system.TerraformVarsPrefix, ""))] = getVar.Value.(string)
} else {
envKey := strings.ToUpper(strings.ReplaceAll(key, system.TerraformVarsPrefix, ""))

switch {
case reflect.TypeOf(getVar.Value).Kind() == reflect.String && getVar.Type == reflect.String.String():
conf.TerraformOutput[key] = getVar.Value
conf.Env[envKey] = getVar.Value.(string)
case reflect.TypeOf(getVar.Value).Kind() == reflect.Bool && getVar.Type == reflect.Bool.String():
conf.TerraformOutput[key] = getVar.Value
conf.Env[envKey] = strconv.FormatBool(getVar.Value.(bool))
default:
zap.S().Warnf("Terraform output variable %s will not be exported as environment variable, "+
"does not match the string type, current type: %s", key, getVar.Type)
"does not match string or boolean types, current type: %s", key, getVar.Type)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ exported-vars:

The variables listed in the `env` section will be used when running the `rmk release ...` commands.

> Only the `string` output variables are supported.
> Only the `string` or `boolean` types output variables are supported.
## Default exported variables

Expand Down
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- #33 - Added a new GitHub action for RMK commands documentation generation.
- #34 - Added support for Terraform outputs of a boolean type.

0 comments on commit b3f447c

Please sign in to comment.