Skip to content

Commit

Permalink
Merge pull request #139 from shalb/no-inputs-module
Browse files Browse the repository at this point in the history
fix 3
  • Loading branch information
romanprog authored Aug 18, 2021
2 parents 8477e9d + f376751 commit f1fdd28
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 35 deletions.
35 changes: 21 additions & 14 deletions pkg/modules/terraform/helm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Module struct {
helmOpts map[string]interface{}
sets map[string]interface{}
kubeconfig string
valuesFilesList [][]byte
valuesFilesList []string
valuesYAML []map[string]interface{}
}

Expand Down Expand Up @@ -58,16 +58,6 @@ func (m *Module) genMainCodeBlock() ([]byte, error) {
setBlock.Body().SetAttributeValue("name", cty.StringVal(key))
setBlock.Body().SetAttributeValue("value", ctyVal)
}
depMarkers, ok := m.ProjectPtr().Markers[common.RemoteStateMarkerCatName]
if ok {
for hash, marker := range depMarkers.(map[string]*project.Dependency) {
if marker.Module == nil {
continue
}
remoteStateRef := fmt.Sprintf("data.terraform_remote_state.%s-%s.outputs.%s", marker.Module.InfraName(), marker.Module.Name(), marker.Output)
hcltools.ReplaceStingMarkerInBody(helmBody, hash, remoteStateRef)
}
}
if len(m.valuesFilesList) > 0 {
ctyValuesList := []cty.Value{}
for _, v := range m.valuesFilesList {
Expand All @@ -76,6 +66,15 @@ func (m *Module) genMainCodeBlock() ([]byte, error) {
helmBody.SetAttributeValue("values", cty.ListVal(ctyValuesList))
//hcltools.ReplaceStingMarkerInBody(helmBody, marker, "file(\"./values.yaml\")")
}
for hash, m := range m.Markers() {
marker, ok := m.(*project.Dependency)
// log.Warnf("kubernetes marker HELM: %v", marker)
refStr := common.DependencyToRemoteStateRef(marker)
if !ok {
return nil, fmt.Errorf("generate main.tf: internal error: incorrect remote state type")
}
hcltools.ReplaceStingMarkerInBody(helmBody, hash, refStr)
}
return f.Bytes(), nil
}

Expand Down Expand Up @@ -116,8 +115,8 @@ func (m *Module) ReadConfig(spec map[string]interface{}, infra *project.Infrastr
if !check {
return fmt.Errorf("read module config: 'values' have unknown type: %v", err)
}
m.valuesFilesList = [][]byte{}
log.Warnf("%v", ok)
m.valuesFilesList = []string{}
//log.Warnf("%v", ok)

for _, valuesCat := range valuesCatList {
valuesCatMap, check := valuesCat.(map[string]interface{})
Expand Down Expand Up @@ -154,7 +153,7 @@ func (m *Module) ReadConfig(spec map[string]interface{}, infra *project.Infrastr
return fmt.Errorf("read module config: unmarshal values file: ", err.Error())
}
m.valuesYAML = append(m.valuesYAML, vYAML)
m.valuesFilesList = append(m.valuesFilesList, values)
m.valuesFilesList = append(m.valuesFilesList, string(values))
}
}
pv, ok := spec["provider_version"].(string)
Expand All @@ -174,6 +173,14 @@ func (m *Module) ReplaceMarkers() error {
if err != nil {
return err
}
err = project.ScanMarkers(m.valuesFilesList, m.RemoteStatesScanner, m)
if err != nil {
return err
}
err = project.ScanMarkers(m.valuesFilesList, m.YamlBlockMarkerScanner, m)
if err != nil {
return err
}
err = project.ScanMarkers(m.helmOpts, m.RemoteStatesScanner, m)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/modules/terraform/helm/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type State struct {
ModType string `json:"type"`
HelmOpts interface{} `json:"helm_opts,omitempty"`
Sets interface{} `json:"sets,omitempty"`
Values [][]byte `json:"values,omitempty"`
Values []string `json:"values,omitempty"`
}

func (m *Module) GetState() interface{} {
Expand All @@ -37,7 +37,7 @@ type StateDiff struct {
Source string `json:"source"`
HelmOpts interface{} `json:"helm_opts,omitempty"`
Sets interface{} `json:"sets,omitempty"`
Values [][]byte `json:"values,omitempty"`
Values []string `json:"values,omitempty"`
}

func (m *Module) GetDiffData() interface{} {
Expand Down
30 changes: 13 additions & 17 deletions pkg/modules/terraform/kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,24 @@ func (m *Module) genMainCodeBlock() ([]byte, error) {
}

moduleBody.SetAttributeValue("manifest", ctyVal)
depMarkers, ok := m.ProjectPtr().Markers[common.RemoteStateMarkerCatName]
if ok {
for hash, marker := range depMarkers.(map[string]*project.Dependency) {
if marker.Module == nil {
continue
}
remoteStateRef := fmt.Sprintf("data.terraform_remote_state.%s-%s.outputs.%s", marker.Module.InfraName(), marker.Module.Name(), marker.Output)
hcltools.ReplaceStingMarkerInBody(moduleBody, hash, remoteStateRef)
for hash, m := range m.Markers() {
marker, ok := m.(*project.Dependency)
refStr := common.DependencyToRemoteStateRef(marker)
if !ok {
return nil, fmt.Errorf("generate main.tf: internal error: incorrect remote state type")
}
hcltools.ReplaceStingMarkerInBody(moduleBody, hash, refStr)
}
}
depMarkers, ok := m.ProjectPtr().Markers[common.RemoteStateMarkerCatName]
if ok {
for hash, marker := range depMarkers.(map[string]*project.Dependency) {
if marker.Module == nil {
continue
}
remoteStateRef := fmt.Sprintf("data.terraform_remote_state.%s-%s.outputs.%s", marker.Module.InfraName(), marker.Module.Name(), marker.Output)
hcltools.ReplaceStingMarkerInBody(providerBody, hash, remoteStateRef)

for hash, m := range m.Markers() {
marker, ok := m.(*project.Dependency)
refStr := common.DependencyToRemoteStateRef(marker)
if !ok {
return nil, fmt.Errorf("generate main.tf: internal error: incorrect remote state type")
}
hcltools.ReplaceStingMarkerInBody(providerBody, hash, refStr)
}

return f.Bytes(), nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/modules/terraform/printer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (m *Module) genMainCodeBlock() ([]byte, error) {
dataBody.SetAttributeValue("value", hclVal)
for hash, m := range m.Markers() {
marker, ok := m.(*project.Dependency)
// log.Warnf("kubernetes marker printer: %v", marker)
refStr := common.DependencyToRemoteStateRef(marker)
if !ok {
return nil, fmt.Errorf("generate main.tf: internal error: incorrect remote state type")
Expand Down
1 change: 0 additions & 1 deletion pkg/modules/terraform/tf_module/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (m *Module) genMainCodeBlock() ([]byte, error) {
return nil, fmt.Errorf("generate main.tf: internal error: incorrect remote state type")
}
refStr := common.DependencyToRemoteStateRef(marker)
// log.Warnf("module markers:", marker.Module.Key())
hcltools.ReplaceStingMarkerInBody(moduleBody, hash, refStr)
}
return f.Bytes(), nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/project/ui/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func getDirSubCats(path string, tFS TmplFS) (cats []string, err error) {
func getTemplateSpec(catDir, templateName string, tFS TmplFS) (res templateConfSpec, err error) {
rs := templateConfSpec{}
confFileName := filepath.Join(catDir, templateName, "config.yaml")
log.Warn(confFileName)
// log.Warn(confFileName)
configRaw, err := tFS.ReadFile(confFileName)
if err != nil {
err = fmt.Errorf("reading template: internal error (file not found %v): %v", confFileName, err.Error())
Expand Down

0 comments on commit f1fdd28

Please sign in to comment.