Giter VIP home page Giter VIP logo

github-actions's Introduction

Github Actions

GitHub Actions allow you to execute Terraform commands within GitHub Actions.


Usage

terraform and terratest

The most common workflow is to run terratest terraform fmt, terraform init, terraform validate, and terraform plan on all of the Terraform files in the root of the repository when a pull request is opened or updated. A comment will be posted to the pull request depending on the output of the Terraform subcommand being executed. This workflow can be configured by adding the following content to the GitHub Actions workflow YAML file.

name: 'Terraform GitHub Actions'
on:
  - pull_request

jobs:
  terraform:
    name: 'Terraform'
    runs-on: ubuntu-latest
    steps:

      - name: 'Checkout'
        uses: actions/checkout@master

      - name: 'Terraform format'
        uses: clouddrove/github-actions@master
        with:
          actions_subcommand: 'fmt'

      - name: 'Terraform init fot public-private-subnet'
        uses: clouddrove/github-actions@master
        with:
          actions_subcommand: 'init'
          tf_actions_working_dir: ./_example/public-private-subnet    
      
      - name: Configure aws credentials
        uses: clouddrove/configure-aws-credentials@v1
        with:
         aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
         aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
         aws-region: us-east-2      
     
      - name: 'Terraform plan for public-private-subnet'
        uses: clouddrove/[email protected]
        with:
          actions_subcommand: 'plan'
          tf_actions_working_dir: ./_example/public-private-subnet
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: 'Terratest for public-private-subnet'
        uses: clouddrove/[email protected]
        with:
          actions_subcommand: 'terratest'
          tf_actions_working_dir: ./_test/public-private-subnet
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: 'Terratest for public-subnet'
        uses: clouddrove/[email protected]
        with:
          actions_subcommand: 'terratest'
          tf_actions_working_dir: ./_test/public-subnet
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: 'Slack notification'
        uses: clouddrove/action-slack@v2
        with:
          status: ${{ job.status }}
          fields: repo,author
          author_name: 'CloudDrove'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required
        if: always()

This was a simplified example showing the basic features of these Terraform GitHub Actions. Please refer to the examples within the examples directory for other common workflows.

Inputs

Inputs configure Terraform GitHub Actions to perform different actions.

  • actions_subcommand - (Required) The Terraform subcommand to execute. Valid values are terratest fmt, init, validate, plan, and apply.
  • tf_actions_version - (Required) The Terraform version to install and execute.
  • tf_actions_cli_credentials_hostname - (Optional) Hostname for the CLI credentials file. Defaults to app.terraform.io.
  • tf_actions_cli_credentials_token - (Optional) Token for the CLI credentials file.
  • tf_actions_comment - (Optional) Whether or not to comment on GitHub pull requests. Defaults to true.
  • tf_actions_working_dir - (Optional) The working directory to change into before executing Terraform subcommands. Defaults to . which means use the root of the GitHub repository.
  • terratest - (Optional) If you want to run terratest of terraform module.

Outputs

Outputs are used to pass information to subsequent GitHub Actions steps.

  • tf_actions_output - The Terraform outputs in JSON format.
  • tf_actions_plan_has_changes - Whether or not the Terraform plan contained changes.

Secrets

Secrets are similar to inputs except that they are encrypted and only used by GitHub Actions. It's a convenient way to keep sensitive data out of the GitHub Actions workflow YAML file.

  • GITHUB_TOKEN - (Optional) The GitHub API token used to post comments to pull requests. Not required if the tf_actions_comment input is set to false.

Other secrets may be needed to authenticate with Terraform backends and providers.

WARNING: These secrets could be exposed if the action is executed on a malicious Terraform file. To avoid this, it is recommended not to use these Terraform GitHub Actions on repositories where untrusted users can submit pull requests.

Feedback

If you come accross a bug or have any feedback, please log it in our issue tracker, or feel free to drop us an email at [email protected].

If you have found it worth your time, go ahead and give us a * on our GitHub!

About us

At CloudDrove, we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering.

We are The Cloud Experts!


We ❤️ Open Source and you can check out our other modules to get help with your new Cloud ideas.

github-actions's People

Contributors

anmolnagpal avatar clouddrove-ci avatar dhyanio avatar himanshu-uniyal avatar nileshgadgi avatar omsharma07 avatar sohanyadav avatar tanveer143s avatar vishwajitnagulkar avatar yadavprakash avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.