Skip to content

Commit da8ada2

Browse files
authored
blocks support block name in generated project (#1998)
* support additiona parsing arguments * propagate projectName to projects
1 parent 1c23cbd commit da8ada2

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

libs/digger_config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type AssumeRoleForProject struct {
4242
}
4343

4444
type Project struct {
45+
BlockName string // the block name if this is a generated project
4546
Name string
4647
Dir string
4748
Workspace string

libs/digger_config/converters.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ func copyProjects(projects []*ProjectYaml) []Project {
6969
workspace = p.Workspace
7070
}
7171

72-
item := Project{p.Name,
72+
item := Project{
73+
p.BlockName,
74+
p.Name,
7375
p.Dir,
7476
workspace,
7577
p.Terragrunt,

libs/digger_config/digger_config.go

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ func HandleYamlProjectGeneration(config *DiggerConfigYaml, terraformDir string,
329329
slog.Warn("terragrunt generation using top level config is deprecated",
330330
"recommendation", "https://docs.digger.dev/howto/generate-projects#blocks-syntax-with-terragrunt")
331331

332-
err := hydrateDiggerConfigYamlWithTerragrunt(config, *config.GenerateProjectsConfig.TerragruntParsingConfig, terraformDir)
332+
err := hydrateDiggerConfigYamlWithTerragrunt(config, *config.GenerateProjectsConfig.TerragruntParsingConfig, terraformDir, "")
333333
if err != nil {
334334
slog.Error("failed to hydrate config with terragrunt", "error", err)
335335
return err
@@ -338,7 +338,7 @@ func HandleYamlProjectGeneration(config *DiggerConfigYaml, terraformDir string,
338338
slog.Warn("terragrunt generation using top level config is deprecated",
339339
"recommendation", "https://docs.digger.dev/howto/generate-projects#blocks-syntax-with-terragrunt")
340340

341-
err := hydrateDiggerConfigYamlWithTerragrunt(config, TerragruntParsingConfig{}, terraformDir)
341+
err := hydrateDiggerConfigYamlWithTerragrunt(config, TerragruntParsingConfig{}, terraformDir, "")
342342
if err != nil {
343343
slog.Error("failed to hydrate config with terragrunt", "error", err)
344344
return err
@@ -408,16 +408,19 @@ func HandleYamlProjectGeneration(config *DiggerConfigYaml, terraformDir string,
408408
workflow = b.Workflow
409409
}
410410

411-
tgParsingConfig := TerragruntParsingConfig{
412-
CreateProjectName: true,
413-
DefaultWorkflow: workflow,
414-
WorkflowFile: b.WorkflowFile,
415-
FilterPath: path.Join(terraformDir, *b.RootDir),
416-
AwsRoleToAssume: b.AwsRoleToAssume,
417-
AwsCognitoOidcConfig: b.AwsCognitoOidcConfig,
411+
// load the parsing config and override the block values
412+
tgParsingConfig := b.TerragruntParsingConfig
413+
if tgParsingConfig == nil {
414+
tgParsingConfig = &TerragruntParsingConfig{}
418415
}
419-
420-
err := hydrateDiggerConfigYamlWithTerragrunt(config, tgParsingConfig, terraformDir)
416+
tgParsingConfig.CreateProjectName = true
417+
tgParsingConfig.DefaultWorkflow = workflow
418+
tgParsingConfig.WorkflowFile = b.WorkflowFile
419+
tgParsingConfig.FilterPath = path.Join(terraformDir, *b.RootDir)
420+
tgParsingConfig.AwsRoleToAssume = b.AwsRoleToAssume
421+
tgParsingConfig.AwsCognitoOidcConfig = b.AwsCognitoOidcConfig
422+
423+
err := hydrateDiggerConfigYamlWithTerragrunt(config, *tgParsingConfig, terraformDir, b.BlockName)
421424
if err != nil {
422425
slog.Error("failed to hydrate config with terragrunt",
423426
"error", err,
@@ -696,7 +699,7 @@ func ValidateDiggerConfig(config *DiggerConfig) error {
696699
return nil
697700
}
698701

699-
func hydrateDiggerConfigYamlWithTerragrunt(configYaml *DiggerConfigYaml, parsingConfig TerragruntParsingConfig, workingDir string) error {
702+
func hydrateDiggerConfigYamlWithTerragrunt(configYaml *DiggerConfigYaml, parsingConfig TerragruntParsingConfig, workingDir string, blockName string) error {
700703
slog.Info("hydrating config with terragrunt projects",
701704
"workingDir", workingDir,
702705
"filterPath", parsingConfig.FilterPath)
@@ -803,6 +806,7 @@ func hydrateDiggerConfigYamlWithTerragrunt(configYaml *DiggerConfigYaml, parsing
803806
"workspace", atlantisProject.Workspace)
804807

805808
diggerProject := &ProjectYaml{
809+
BlockName: blockName,
806810
Name: atlantisProject.Name,
807811
Dir: projectDir,
808812
Workspace: atlantisProject.Workspace,

libs/digger_config/yaml.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type DependencyConfigurationYaml struct {
3535
}
3636

3737
type ProjectYaml struct {
38+
BlockName string `yaml:"block_name"`
3839
Name string `yaml:"name"`
3940
Dir string `yaml:"dir"`
4041
Workspace string `yaml:"workspace"`
@@ -108,8 +109,9 @@ type BlockYaml struct {
108109
ExcludePatterns []string `yaml:"exclude_patterns,omitempty"`
109110

110111
// these flags are only for terragrunt
111-
Terragrunt bool `yaml:"terragrunt"`
112-
RootDir *string `yaml:"root_dir"`
112+
Terragrunt bool `yaml:"terragrunt"`
113+
RootDir *string `yaml:"root_dir"`
114+
TerragruntParsingConfig *TerragruntParsingConfig `yaml:"terragrunt_parsing,omitempty"`
113115

114116
// these flags are only for opentofu
115117
OpenTofu bool `yaml:"opentofu"`

0 commit comments

Comments
 (0)