terrakube icon indicating copy to clipboard operation
terrakube copied to clipboard

Persist environment variables from commands

Open aacuadras opened this issue 8 months ago • 3 comments

Feature description 💡

Currently when environment variables are set in a BASH command, those variables do not persist in the flow. For example, let's say I want to assume a role in AWS and then run terraform plan. I want to accomplish this with the following template:

flow:
  - type: "terraformPlan"
    name: "Init and Plan"
    step: 100
    commands:
      - runtime: "BASH"
        priority: 100
        before: true
        script: |
          creds=$(aws sts assume-role --role-arn 'arn:aws:iam::123456789012:role/terrakube-role' --role-session-name session --output json)
          export AWS_ACCESS_KEY_ID=$(echo $creds | jq '.Credentials.AccessKeyId')
          export AWS_SECRET_ACCESS_KEY=$(echo $creds | jq '.Credentials.SecretAccessKey')
          export AWS_SESSION_TOKEN=$(echo $creds | jq '.Credentials.SessionToken')

That way, terraform can plan and apply using the designated role

Anything else?

No response

aacuadras avatar Jun 24 '24 16:06 aacuadras