š„Letās Do DevOps: Terraform GitHub Action Targeting from Web Console User Input
--
This blog series focuses on presenting complex DevOps projects as simple and approachable via plain language and lots of pictures. You can do it!
Hey all!
Iām helping a team migrate their automation from AWS CodeBuild into GitHub Actions, including Terraform automation. CodeBuild is relatively clunky, but it has something useful that is absolutely critical to this team ā you can run a pipeline and target a specific version of your source code ā a branch or tag.
Until recently GitHub Actions didnāt support this ā they are strong proponents of GitOps, where pure git
actions drive all automation, and user input isnāt gathered. However, that has changed!
Actions now support both workflow_dispatch
(launching an action manually from the web console) and inputs
, a way of gathering input from the user when launching an action. We can combine these to have highly dynamic Actions.
Letās walk through my implementation of a Terraform validation and deploy Action that takes input on launch of:
- Branch/tag target
- Custom field: Environment and Region of AWS to target
Gathering Action Inputs
The first part of our pipeline names it, and then immediately gathers some inputs. Line 1 names our pipeline. Line 3, on:
, is where weād normally set the triggers for our pipeline, line on_push
and filters like the path of files changes.
Here, instead, we set a trigger of workflow_dispatch
, which means this action will be triggerable from the github web page console. We set an input called āenvironmentā and add custom fields for description, set it required (line 10), and set some options (line 11). I made up the options on line 11 ā put whatever youād like! This will appear as a required drop-down when launching this pipeline from the web console.