Skip to content

Add flag to atmos terraform generate planfile #1403

@cfsb-jrose

Description

@cfsb-jrose

Describe the Feature

I would like to propose adding --dir as a supported flag when running atmos terraform generate planfile so that I can configure a custom directory outside of the default (e.g. /atmos/component/terraform/terraform-aws-vpc). The driving force behind this request is that the existing --file flag does not permit templating (e.g. use of {{ .atmos.stack }}) when optimizing Atmos workflows. For example:

config:
  plan: &plan
    - command: terraform generate planfile plan transit-gateway --file /atmos/tenable/{{ .atmos.stack}}-transit-gateway
    - command: terraform generate planfile tgw-routing --file /atmos/tenable/{{ .atmos.stack}}-tgw-routing
workflows:
  plan-ue1:
    description: |
      The steps in this workflow are run when a pull request is opened or updated.
      This workflow will plan the component with mock outputs for dependencies.
      It will not apply any changes.
    stack: cfsb-it-network-ue1
    steps: *plan

The above would file because {{ .atmos.stack }} would not template correctly. However, if --dir /atmos/tenable was supported, the need for templating would not be needed because the file would already have the desired naming convention and placed in the desired directory.

Expected Behavior

config:
  plan: &plan
    - command: terraform generate planfile plan transit-gateway --dir /atmos/tenable
    - command: terraform generate planfile tgw-routing --dir /atmos/tenable
workflows:
  plan-ue1:
    description: |
      The steps in this workflow are run when a pull request is opened or updated.
      This workflow will plan the component with mock outputs for dependencies.
      It will not apply any changes.
    stack: cfsb-it-network-ue1
    steps: *plan

The above would generate the following files:

/atmos/tenable/cfsb-it-network-ue1-transit-gateway.planfile.json
/atmos/tenable/cfsb-it-network-ue1-tgw-routing.planfile.json

Use Case

For a given workflow file, there might be 3-5 stacks based on the number of environments for a given project. If each stack has the same steps that need to be ran, it's more effective to implement a config so the workflow steps are promote a DRY strategy.

Describe Ideal Solution

Support --dir flag that supports a custom directory to place generated files. It should be documented that --dir and --file should not be used together.

Alternatives Considered

workflows:
  plan-ue1:
    description: |
      The steps in this workflow are run when a pull request is opened or updated.
      This workflow will plan the component with mock outputs for dependencies.
      It will not apply any changes.
    stack: cfsb-it-network-ue1
    steps:
      - command: terraform generate planfile plan transit-gateway --file "/atmos/tenable/{{ .atmos.stack }}-transit-gateway.planfile.json"
      - command: terraform generate planfile tgw-routing "/atmos/tenable/{{ .atmos.stack }}-tgw-routing.planfile.json"

The issue with this solution is that it doesn't scale and isn't DRY. For example, if I had 5 stacks, 20 components each, I would have to repeat myself 100 times.

Additional Context

No response

Metadata

Metadata

Assignees

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