dflook / terraform-github-actions

GitHub actions for terraform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support repository_dispatch event type to allow advance workflows to take place

DanyC97 opened this issue Β· comments

Suggestion

Hey @dflook πŸ‘‹ ,

I'd like to suggest an enhancements which i think will add massive value in addition to what already does (and does well!).

Use case

The current issue_comment event type which is supported to trigger plan || apply works however things are getting complicated if you need to pass various input variables as comment as that requires a lot of parsing inside the GHA workflow.

An flow like here done with the help of repository_dispatch & client_payload will give folks with complex / multiple variables to dynamically workout which envs/ which projects (gcp ) which OIDC details or var-files to pass to current set of actions

Couple of examples of input vars which are setup as GH repo secrets and non infra developers don't need to care about it.

  • project_id || pool_name || service_account
  • var-file 1 & 1.1 & var-file 2 & 2.2 (located in env/dev ) maps to layer 1 respective 2 folders (aka root modules)

With accessing the context i can extract the commands which were passed as Pr comment w/o going into too much complexity in GHA workflow using conditional steps / jobs and load of github_env

Problem

Triggering any of the current action works with the exception of tf plan where the GH comment is not being pushed because only a set of event type are being supported - see here & hence the "bucket" will stop here

Potential solution

I think there are 2 parts which needs to be touched:

  • relaxing the bash if condition to support the new event type
  • check if the code here does work with the payload below (snippet)
{
  "action": "terraform-plan-command",
  "branch": "main",
  "client_payload": {
    "github": {
      "action": "__peter-evans_slash-command-dispatch",
      "actor": "user1",
      "apiUrl": "https://api.github.com/",
      "eventName": "issue_comment",
      "graphqlUrl": "https://api.github.com/graphql",
      "job": "chatOps-Command-Dispatch",
      "payload": {
        "action": "created",
        "comment": {

Let me know wdyt ?

This has been added in v1.36.0.

dflook/terraform-plan and dflook/terraform-apply should work when triggered by repository_dispatch events that have a client payload that includes the PR api url, e.g.

{
  "pull_request": {
    "url": "https://api.github.com/repos/dflook/terraform-github-actions/pulls/1"
  }
}

Wow, thank you for quick response, extremely appreciate it !

Closing as being fixed