Skip to content

Commit

Permalink
feat: add dependency on modules invocation (#283)
Browse files Browse the repository at this point in the history
* chore: add dependency on modules invocation

* feat: add depends on for module array

* fix: remove unnecessary ModuleDependsOn

* fix: drop DependsOn
  • Loading branch information
zackhee997 authored Apr 23, 2024
1 parent 37611ae commit aef1949
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ type moduleData struct {
Outputs []*tfconfig.Output
IntegrationRegistryEntries []*IntegrationRegistryEntry
ProvidersMap map[string]string
DependsOn []string
}

type IntegrationRegistryEntry struct {
Expand Down Expand Up @@ -738,6 +739,7 @@ func applyModuleInvocation(
Outputs: outputs,
IntegrationRegistryEntries: integrationRegistryEntries,
ProvidersMap: mi.module.ProvidersMap,
DependsOn: mi.module.DependsOn,
})
}

Expand Down
2 changes: 2 additions & 0 deletions config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ type ComponentModule struct {
ProvidersMap map[string]string `yaml:"providers,omitempty"`
// For Each metadata argument https://developer.hashicorp.com/terraform/language/modules/syntax#meta-arguments
ForEach *string `yaml:"for_each,omitempty"`
// Dependencies of this module
DependsOn []string `yaml:"depends_on,omitempty"`
}

type ModuleIntegrationConfig struct {
Expand Down
8 changes: 8 additions & 0 deletions templates/templates/module-invocation/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@ module "{{.ModuleName}}" {
{{- end}}
}
{{- end }}

{{- if .DependsOn }}
depends_on = [
{{- range .DependsOn }}
module.{{ . }},
{{- end }}
]
{{- end }}
}
{{ end }}
6 changes: 6 additions & 0 deletions testdata/v2_atlantis_depends_on/fogg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ envs:
- tags
- banana
- source: "terraform/modules/my_module"
name: "my_module"
depends_on:
- "vpc"
- source: "foo_modules/bar"
depends_on:
- "vpc"
- "my_module"
db:
depends_on:
components:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ module "vpc" {

module "my_module" {
source = "../../../modules/my_module"
depends_on = [
module.vpc,
]
}

module "bar" {
source = "../../../../foo_modules/bar"
depends_on = [
module.vpc,
module.my_module,
]
}

0 comments on commit aef1949

Please sign in to comment.