Skip to content

nikitadugar/github-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/github-actions@master
        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/github-actions@master
        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/github-actions@master
        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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published