leg100/otf

VCS Always trigger runs

Closed this issue · 3 comments

When using a VCS repo, I want my workspace to trigger runs only if a file in a folder of my repository changes (i.e. file trigger).

In TFC the Workspace creation data structure attribute file-triggers-enabled has a default value of "true" and reads:

Whether to filter runs based on the changed files in a VCS push. If enabled, it uses either trigger-prefixes in conjunction with working_directory or trigger-patterns to describe the set of changed files that will start a run. If disabled, any push will trigger a run.

https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces#create-a-workspace

However in OTF it seems like it always behaves as the value is "False". Indeed it is false even when I force a value of True.

My data structure is:

    payload = {
      "data": {
        "attributes": {
          "name": workspace_name,
          "auto-apply": True,
          "resource-count": 0,
          "terraform-version": terraform_version,
          "working-directory": working_directory,
          "file-triggers-enabled": True,                            <<<<<<<< HERE
          "trigger-prefixes": [f"/{working_directory}"],    <<<<<<<< AND HERE
          "vcs-repo": {
            "identifier": repo_name,
            "oauth-token-id": vcs_repo_oauth_token,
            "branch": branch
          }
        },
        "type": "workspaces"
      }
    }

However when the workspace is created, the trigger still reads:

Screenshot 2023-09-01 at 2 07 03 am

In other words, the value as if the file triggers attribute was set to False.

Ah, reading the code... trigger-prefixes is not used in OTF. Also there is this "always-trigger" attribute which is not part of TFC. Anyway I adjusted my payload to:

   payload = {
      "data": {
        "attributes": {
          "name": workspace_name,
          "auto-apply": True,
          "resource-count": 0,
          "terraform-version": terraform_version,
          "working-directory": working_directory,
          "file-triggers-enabled": True,
          "always-trigger": False,
          "trigger-patterns": [f"/{working_directory}/*.tf"],
          "vcs-repo": {
            "identifier": repo_name,
            "oauth-token-id": vcs_repo_oauth_token,
            "branch": branch
          }
        },
        "type": "workspaces"
      }
    }
 

And now it worked:
Screenshot 2023-09-01 at 2 50 57 pm

Working but not the same as in TFC.

leg100 commented

Yes this does deviate from TFC. I didn't see the point in implementing trigger prefixes because trigger patterns are more powerful and permit setting prefixes as well.

But yes this is not clear to anyone using the API. It would be good to document the API and to note where there are discrepancies. This is no small task because the API is vast and there are a fair few discrepancies.