Skip to content

Commit

Permalink
Bugfix/fixing env vars (#40)
Browse files Browse the repository at this point in the history
* chore: added env vars consts

* chore: reversed temp change

* fix:fixed bug with list of objects

---------

Co-authored-by: osher.elmakaies <[email protected]>
  • Loading branch information
osherElm and osher.elmakaies authored May 15, 2023
1 parent 9d56f95 commit 8caf30b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/templates/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module "consul_sync" {
affinity = module.kafka.affinity
eks_cluster = module.zookeeper.eks_cluster

# Configurable Variables - Optinal Fields
# Configurable Variables - Optinal Fields
{{(GetDefaults "consul_sync" .)}}
}

Expand All @@ -16,7 +16,7 @@ module "zookeeper" {
affinity = module.kafka.affinity
eks_cluster = module.zookeeper.eks_cluster

# Configurable Variables - Optinal Fields
# Configurable Variables - Optinal Fields
{{(GetDefaults "consul_sync" .)}}
}

Expand Down
13 changes: 7 additions & 6 deletions internal/services/drivers/version_control/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ package version_control

import (
"fmt"
"os"
"strings"

log "github.com/AppsFlyer/go-logger"
"github.com/go-git/go-git/v5" /// with go modules disabled
"github.com/go-git/go-git/v5/plumbing/transport/http"
cp "github.com/otiai10/copy"
"github.com/pkg/errors"
"os"
"strings"
)

const (
FolderPathFormat = "%s/%s"
TempFolderPath = "%s/temp_clone_path/%s"
GitlabTokenENV = ""
GithubTokenENV = ""
GitlabUserENV = ""
GithubUserENV = ""
GitlabTokenENV = "GITLAB_TOKEN"
GitlabUserENV = "GITLAB_USER"
GithubTokenENV = "GITHUB_TOKEN"
GithubUserENV = "GITHUB_USER"
)

type RemoteModule struct {
Expand Down
31 changes: 29 additions & 2 deletions internal/services/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package services

import (
"fmt"
"regexp"
"strings"

logger "github.com/AppsFlyer/go-logger"

"github.com/AppsFlyer/terra-crust/internal/services/templates"
"github.com/AppsFlyer/terra-crust/internal/types"
)
Expand Down Expand Up @@ -77,7 +79,26 @@ func (t *Terraform) GenerateModuleVariableObject(modulesFilePath, destinationPat

for _, v := range m.Variables {
if v.Default != nil && string(v.Default.Bytes()) != emptyStringWrapped {
out[moduleName].ObjectTypeMapping[v.Name] = strings.ReplaceAll(string(v.Type.Bytes()), " ", emptyString)
value := strings.ReplaceAll(string(v.Type.Bytes()), " ", emptyString)
if strings.Contains(string(v.Type.Bytes()), "object") && strings.Contains(string(v.Type.Bytes()), "list") {
pattern := `(\w+)\s*=\s*(\w+)`
regex := regexp.MustCompile(pattern)
matches := regex.FindAllStringSubmatch(string(v.Type.Bytes()), -1)
var sb strings.Builder

sb.WriteString("optional(list(object({")
for _, match := range matches {
key := match[1]
val := match[2]

sb.WriteString(fmt.Sprintf("%s=%s\n", key, val))
}

sb.WriteString("})))")

value = sb.String()
}
out[moduleName].ObjectTypeMapping[v.Name] = value
out[moduleName].DefaultValues[v.Name] = string(v.Default.Bytes())
}
}
Expand Down Expand Up @@ -110,7 +131,9 @@ func (t *Terraform) GenerateModuleDefaultLocals(modulesFilePath, destinationPath

for _, v := range m.Variables {
if v.Default != nil && string(v.Default.Bytes()) != emptyStringWrapped && !strings.Contains(string(v.Type.Bytes()), "map") {
out.Module[k].SimpleLocals[v.Name] = string(v.Default.Bytes())
value := string(v.Default.Bytes())
out.Module[k].SimpleLocals[v.Name] = value

}

if v.Default != nil && string(v.Default.Bytes()) != emptyStringWrapped && strings.Contains(string(v.Type.Bytes()), "map") {
Expand Down Expand Up @@ -207,6 +230,10 @@ func (t *Terraform) parseModule(m *types.Module, moduleName string, out *templat
rawDefault = strings.TrimSpace(rawDefault)
splittedRawString := strings.Split(rawDefault, "\n")

if v.Name == "taints" {
t.log.Errorf("FOUND map TAINTS : %+v", splittedRawString)
}

separator := "="
if strings.Contains(rawDefault, ":") {
separator = ":"
Expand Down

0 comments on commit 8caf30b

Please sign in to comment.