Skip to content

generate_projects: support multiple projects per directory with different workflows (multi-environment) #2611

@quinyx-max

Description

@quinyx-max

Problem

When using generate_projects, there's no way to create multiple projects from the same directory with different workflows. This is needed for multi-environment setups where environments (dev, staging, prod, etc.) share the same Terraform code but use different var files and workflows.

Currently, project names are derived from the directory path (dir.replace("/", "_")), so two blocks matching the same directory produce a duplicate name error:

project name 'terraform_airflow' is duplicated

This forces users to maintain a fully explicit projects: list, which defeats the purpose of generate_projects for repos with many Terraform modules and environments.

Use case:

A repo with N Terraform modules and M environments:

terraform/
    airflow/
      main.tf
      vars_dev.euc1.tfvars
      vars_staging.euc1.tfvars
      vars_prod.euc1.tfvars
    ecs/
      main.tf
      vars_dev.euc1.tfvars
      vars_staging.euc1.tfvars
      vars_prod.euc1.tfvars
    ... (many modules)

Each module needs a project per environment, each with its own workflow (different var files, workspaces, credentials, account_ids, etc.). The Terraform code is shared; only the configuration differs.

Today this requires N × M explicit project entries that all follow the same pattern. Every time a module or environment is added, multiple entries must be manually created.

Desired behavior

Something like:

generate_projects:
    blocks:
      - include: "terraform/*"
        exclude_patterns: ["terraform/scripts/**"]
        workflow: dev-euc1
        project_name_suffix: "_dev_eu-central-1"

      - include: "terraform/*"
        exclude_patterns: ["terraform/scripts/**"]
        workflow: staging-euc1
        project_name_suffix: "_staging_eu-central-1"

      - include: "terraform/*"
        exclude_patterns: ["terraform/scripts/**"]
        workflow: prod-euc1
        project_name_suffix: "_prod_eu-central-1"

This would generate:

terraform_airflow_dev_eu-central-1       -> terraform/airflow  (workflow: dev-euc1)                                                                                                                                                       
terraform_airflow_staging_eu-central-1   -> terraform/airflow  (workflow: staging-euc1)                            
terraform_airflow_prod_eu-central-1      -> terraform/airflow  (workflow: prod-euc1)
terraform_ecs_dev_eu-central-1           -> terraform/ecs      (workflow: dev-euc1)
terraform_ecs_staging_eu-central-1       -> terraform/ecs      (workflow: staging-euc1)
terraform_ecs_prod_eu-central-1          -> terraform/ecs      (workflow: prod-euc1)
...

The key requirements:

  1. Multiple blocks can match the same directory without a duplicate name error
  2. Project name suffix (or a naming template) to disambiguate generated names
  3. Ideally also support apply_requirements per block (related: support apply_requirements with generate_projects block #2140)

Current workaround

Maintaining a fully explicit projects: list with manually written entries per module per environment. This works but scales poorly — N modules × M environments — and is easy to forget when adding new modules.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions