CircleCI-Public / terraform-orb

Deploy your infrastructure via a CircleCI pipeline using the Terraform orb. Integrate Infrastructure-as-Code (IaC) to help provision and manage any cloud, infrastructure, or service of your choice.
https://circleci.com/orbs/registry/orb/circleci/terraform
MIT License
10 stars 44 forks source link

var_file path is not absolute #80

Open grasbergerm opened 2 years ago

grasbergerm commented 2 years ago

Is your feature request related to a problem? Please describe. When trying to use a dynamic value with a plan or apply job, it is very difficult to pass the dynamically created value as a var or a var_file.

Describe the solution you'd like The var_file attribute should accept an absolute path instead of expecting a var file from within the module path.

Describe alternatives you've considered I've tried passing a variable directly, with the var attribute, but it does not seem that the plan/apply reads from environment variables set in a pre-step step.

Additional context Here's my current setup, please let me know if there's a better way to do this:

The pre-step command, grabbing a variable created in another job:

commands:
  set-image-tag-terraform-var:
    steps:
      - attach_workspace:
          at: /tmp/deploy/workspace
      - run: |
          cat /tmp/deploy/workspace/new-env-vars >> $BASH_ENV
          source $BASH_ENV
          echo "image_tag=\"$VERSION\"" >> /tmp/vars.tfvars

and the plan job:

- terraform/plan:
    pre-steps:
      - set-image-tag-terraform-var
    name: terraform-plan-staging
    path: terraform-cluster-service
    checkout: true
    context: aws
    persist-workspace: true
    workspace: staging
    var_file: ../../../tmp/vars.tfvars
    requires:
      - terraform-validate-staging
      - pipeline/build-deploy

I have tried unsuccessfully with the pre-step command, grabbing a variable created in another job and creating a new variable:

commands:
  set-image-tag-terraform-var:
    steps:
      - attach_workspace:
          at: /tmp/deploy/workspace
      - run: |
          cat /tmp/deploy/workspace/new-env-vars >> $BASH_ENV
          source $BASH_ENV
          echo $VERSION

and the plan job:

- terraform/plan:
    pre-steps:
      - set-image-tag-terraform-var
    name: terraform-plan-staging
    path: terraform-cluster-service
    checkout: true
    context: aws
    persist-workspace: true
    workspace: staging
    var: image_tag=${VERSION}
    requires:
      - terraform-validate-staging
      - pipeline/build-deploy

but it seems $BASH_ENV is not loaded as $VERSION is empty.