I’m trying to understand how you can “environmentalize” a Github actions workflow, that is, have a workflow use different values depending on the environment. Here is my use-case:
- I have a manual workflow to deploy my application to an environment (development, qa, staging, production) which is specified via a workflow input.
- The environments are hosted in AWS and AWS credentials a different for each environment.
Configuring an environment is as simple as this:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
aws-region: 'us-east-1'
My question is what is the best way to have my workflow ensure all environments will be configured.
I’ve done a bit of searching for this answer, but haven’t found anything. The only option I’ve seen so far is to use Github actions contexts which would result in my workflow having a step for each environment where i have an if
expression to determine which step to actually run. Eg.
- name: Configure Dev AWS credentials
if: ${{ github.event.inputs.env_to_promote_to === 'development' }}
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_DEVELOPMENT }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEVELOPMENT }}
aws-region: 'us-east-1'
That seems like a really suboptimal solution since most of my *.yml file will be conditional steps to configure AWS.
This discussion seemed to offer a potential solution, but the syntax is such that I’m not sure how I’d use it.