Skip to content

Commit

Permalink
feat: added depends_on to hash outputs to ensure hashes are only upda… (
Browse files Browse the repository at this point in the history
#373)

…ted when module is updated

<!--

Describe in detail the changes you are proposing, and the rationale.

-->

<!--

Link all GitHub issues fixed by this PR, and add references to prior
related PRs.

-->

Fixes #

### NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES |
EXPERIMENTS

<!--

Write a short description of your changes. Examples:

- Fixed a bug
- Added a new feature
- Updated documentation

--> 

-  Added `depends_on` to hash outputs
  • Loading branch information
demeyerthom authored Mar 5, 2024
2 parents 3173fe9 + 525d15d commit 13b19f4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changes/unreleased/Fixed-20240305-133037.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Fixed
body: Added depends_on to hash outputs
time: 2024-03-05T13:30:37.090548781+01:00
2 changes: 1 addition & 1 deletion internal/generator/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func renderSiteComponent(ctx context.Context, cfg *config.MachConfig, n graph.No
result = append(result, val)

// Render hash output
val, err = renderHashOutput(n)
val, err = renderHashOutput(n, []config.SiteComponentConfig{siteComponent})
if err != nil {
return "", fmt.Errorf("failed to render hash output: %w", err)
}
Expand Down
14 changes: 11 additions & 3 deletions internal/generator/hash_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package generator

import (
"embed"
"github.com/mach-composer/mach-composer-cli/internal/config"
"github.com/mach-composer/mach-composer-cli/internal/graph"
"github.com/mach-composer/mach-composer-cli/internal/utils"
)
Expand All @@ -10,7 +11,7 @@ import (
var hashOutputTmpl embed.FS

// renderHashOutput uses templates/hash_output.tmpl to generate a terraform snippet for each node
func renderHashOutput(n graph.Node) (string, error) {
func renderHashOutput(n graph.Node, siteComponents []config.SiteComponentConfig) (string, error) {
tpl, err := hashOutputTmpl.ReadFile("templates/hash_output.tmpl")
if err != nil {
return "", err
Expand All @@ -21,9 +22,16 @@ func renderHashOutput(n graph.Node) (string, error) {
return "", err
}

var componentNames []string
for _, component := range siteComponents {
componentNames = append(componentNames, component.Name)
}

return utils.RenderGoTemplate(string(tpl), struct {
NodeHash string
NodeHash string
ComponentNames []string
}{
NodeHash: hash,
NodeHash: hash,
ComponentNames: componentNames,
})
}
2 changes: 1 addition & 1 deletion internal/generator/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func renderSite(ctx context.Context, cfg *config.MachConfig, n graph.Node) (stri
}

// Render hash output
val, err = renderHashOutput(n)
val, err = renderHashOutput(n, nestedComponents)
if err != nil {
return "", fmt.Errorf("failed to render hash output: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/generator/templates/hash_output.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
output "hash" {
value = "{{ .NodeHash }}"

depends_on = [
{{range .ComponentNames}}
module.{{.}},
{{end}}
]
}

0 comments on commit 13b19f4

Please sign in to comment.