ljfranklin / terraform-resource

A concourse resource to create infrastructure via Terraform
MIT License
185 stars 85 forks source link

[feature request] Ability to customize the `name`, `metadata`, `plan.json` filenames (support for across step) #160

Closed ari-becker closed 3 years ago

ari-becker commented 3 years ago

Request

Currently, when using put.get_params.output_planfile: true, the resource will create a file called plan.json with the plan output. Similarly, when running the put, files name and metadata will be created with the env_name and Terraform Outputs. None of these filenames can currently be changed - I cannot change plan.json to plan-X.json, name to name-X, or metadata to metadata-X.

To be able to change the name of the files, I would like to be able to define the following options:

Why?

Concourse is adding an across step that allows for many steps to be executed in parallel across a dynamic range of values. Together with a task that runs terraform workspace list, this means that a pipeline can do something like:

jobs:
- name: plan-everything
  plan:
  - get: pull-request
    trigger: true
    version: every
  - task: get-terraform-environments
    file: pull-request/concourse/tasks/get-terraform-environments.yaml # runs terraform workspace list, outputs to a JSON list
  - load_var: terraform-environments
    format: json
    file: get-terraform-environments-output/environments.json
  - across:
    - var: environment
      values: ((.:terraform-environments))
      max_in_flight: 4
    do:
    - put: pull-request
      params:
        path: pull-request
        status: pending
        context: ((.:environment))
    - put: terraform
      params:
        terraform_source: pull-request
        env_name: ((.:environment))
        vars:
          environment_picker: ((.:environment))
        plan_only: true
      get_params:
        output_planfile: true
        output_planfile_filename: plan-((.:environment)).json
    - task: prepare-pr-description
      file: pull-request/concourse/tasks/prepare-pr-description.yaml # prepares a description.txt
      vars:
        environment: ((.:environment))
    - put: pull-request
      params:
        path: pull-request
        status: success
        context: ((.:environment))
        description_file: pr-description/((.:name))/description.txt

Which allows the Concourse pipeline to dynamically run a terraform plan for each and every workspace. But for this to work, the Terraform resource needs to be configured appropriately so that the different instantiations of the resource don't clobber each others' plan / name / metadata files.

ljfranklin commented 3 years ago

I haven't tried using the new across feature, but I can't imagine the Concourse team intends for every resources to add support for a bunch of new _filename properties. What about using a put alias:

- put: terraform-((.:environment))
  resource: terraform

If that doesn't work please open an issue on the Concourse repo to see how they would recommend handling this.

ari-becker commented 3 years ago

The team made it clear that the across step limits scope not just for the variable but also for the artifacts created per variable value, so this is irrelevant. Thanks anyway