Trigger Deployment using exernal source -github

Hi,
I was building a gitops process using Octopus Deploy to run terraform plan and terraform apply based on github(self hosted) pull request or merge. Our terraform code is in github and we don’t want to create packages for terraform. We want to deploy directly from github.

I was wondering is there a way to trigger the deployment from github, using webhook.

I saw integrations with github actions. I was thinking to use github actions to trigger the pipeline.

Is there a better way to do this. Please let me know. Do you have any sample code?

Hi @Zenith.Chandrahasan,

Thanks for reaching out, I’d be happy to help with your Terraform deployments from Github without a package!

In order to source the Terraform files directly from Github, you can add a Github External Feed in Octopus:

Which allows for selecting the Terraform code location as if it was a package:

However it will require adding tags to your commit, which Octopus will use for the package’s version:

git tag 0.0.1
git push
git push --tags

Combine this with our Github integration which includes an Action specifically for Deploying Releases and it should allow you to trigger an Octopus Deployment without needing to build a package directly from Github:

Feel free to reach out if you have any questions or run into any issues at all, I’d be more than happy to clarify any part of the process further!

Best Regards,

Hi,
My problem is more complicated. Octopus Cloud with Self hosted Github enterprise - #5 by jeremy.miller

  1. Ours is a self hosted github enterprise which is not exposed to internet. So won’t be able to add it to Octopus Cloud.
  2. We don’t tag the terraform code in git. We just create pull request and merge to a branch.
  3. I have written a script which executes git clone and then terraform apply in octopus deploy. This script runs locally in the worker which has access to the self hosted github.
    3a. I also created the process in Octopus Deploy
  4. I also have a Powershell script which trigger the deployment in Octopus Deploy using the API.

Now one thing pending in the gitops process is the trigger from github(merge or pullrequest) to run the Powershell script which starts the octopus deployment.

Thanks,
Zenith

Hi @Zenith.Chandrahasan,

Ahh thanks for clarifying, that does make it a little more complex!

If you already have a working script then it sounds like you just need to create a SelfHosted Github Runners. They can be specified in the Github Action to run-on.

E.g. to run a local file you will need to make sure it’s executable:

on:
  pull_request:
    branches: [main]
jobs:
  run_tests:
    runs-on: [self-hosted]
    steps:
    - uses: actions/checkout@v2
    - name: Run script file
      run: |
         chmod +x ./scripts/deploy.sh
         ./scripts/deploy.sh
      shell: bash

That should allow you to trigger a script on a specific worker from a PR to the main branch, without requiring a package or proxy to route the connection to a Github Feed.

Let me know if that doesn’t help or if you have any questions at all!

Best Regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.