cloudposse / cloudposse/atmos

Add flag to atmos terraform generate planfile

Open
#1,403 5 comments 0 reactions 1 assignee Claimed by @Cerebrovinny View on GitHub
Dominant language
Go
Stars
1.4k
Forks
175
Avg merge
2d 3h
Merged PRs (30d)
134

Description

### 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:

```yaml
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

```yaml
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

```yaml
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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.