Skip to content

Commit

Permalink
feat: Depends on Globs (#275)
Browse files Browse the repository at this point in the history
Fixes:
- #274

Add ability to depend on globs for Atlantis autoplan whenModified customization.
  • Loading branch information
vincenthsh authored Apr 14, 2024
1 parent dea585e commit 5aaa83f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ type Hook struct {
type DependsOn struct {
Accounts []string `yaml:"accounts"`
Components []string `yaml:"components"`
//RelativeGlobs to the component
RelativeGlobs []string `yaml:"relative_globs"`
}

type CIProviderConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions config/v2/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1348,3 +1348,10 @@ func DependsOnComponentsGetter(comm Common) []string {
}
return comm.DependsOn.Components
}

func DependsOnRelativeGlobsGetter(comm Common) []string {
if comm.DependsOn == nil {
return nil
}
return comm.DependsOn.RelativeGlobs
}
6 changes: 5 additions & 1 deletion plan/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ func (p *Plan) buildAtlantisConfig(c *v2.Config, foggVersion string) AtlantisCon
}
}
autoplanRemoteState := autoplanRemoteStates && d.HasDependsOn
whenModified := generateWhenModified(uniqueModuleSources, d.PathToRepoRoot, modulePrefixes, autoplanRemoteState)
if d.AutoplanRelativeGlobs != nil {
whenModified = append(whenModified, d.AutoplanRelativeGlobs...)
}
projects = append(projects, atlantis.Project{
Name: util.Ptr(fmt.Sprintf("%s_%s", envName, cName)),
Dir: util.Ptr(fmt.Sprintf("terraform/envs/%s/%s", envName, cName)),
Expand All @@ -416,7 +420,7 @@ func (p *Plan) buildAtlantisConfig(c *v2.Config, foggVersion string) AtlantisCon
ApplyRequirements: []string{atlantis.ApprovedRequirement},
Autoplan: &atlantis.Autoplan{
Enabled: util.Ptr(true),
WhenModified: generateWhenModified(uniqueModuleSources, d.PathToRepoRoot, modulePrefixes, autoplanRemoteState),
WhenModified: whenModified,
},
})
}
Expand Down
2 changes: 2 additions & 0 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ComponentCommon struct {
Accounts map[string]*json.Number `yaml:"all_accounts"`
Backend Backend `yaml:"backend"`
ComponentBackends map[string]Backend `yaml:"comonent_backends"`
AutoplanRelativeGlobs []string `yaml:"autoplan_relative_globs"`
HasDependsOn bool `yaml:"comonent_backends_filtered"`
Env string ` yaml:"env"`
ExtraVars map[string]string `yaml:"extra_vars"`
Expand Down Expand Up @@ -680,6 +681,7 @@ func (p *Plan) buildEnvs(conf *v2.Config) (map[string]Env, error) {
}

c.ComponentBackends = filtered
c.AutoplanRelativeGlobs = v2.ResolveOptionalStringSlice(v2.DependsOnRelativeGlobsGetter, defaults.Common, envConf.Common, componentConf.Common)
envPlan.Components[name] = c
}

Expand Down
1 change: 1 addition & 0 deletions testdata/v2_atlantis_depends_on/atlantis.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions testdata/v2_atlantis_depends_on/fogg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ envs:
depends_on:
components:
- vpc
relative_globs:
- "../../foo.yaml"
modules:
- source: "terraform/modules/my_module"
modules:
Expand Down

0 comments on commit 5aaa83f

Please sign in to comment.