Skip to content

Latest commit

 

History

History
107 lines (88 loc) · 3.03 KB

README.md

File metadata and controls

107 lines (88 loc) · 3.03 KB

Polytomic Terraform Sync

The polytomic/terraform-sync action exports Polytomic resources to Terraform HCL.

See https://github.com/polytomic/terraform-sync-template for a template repository that configures the action and uses it to create pull requests for changes.

Usage

The only required argument for the action is the Polytomic API key.

- name: Polytomic Terraform Sync
  uses: polytomic/[email protected]
  with:
    api_key: ${{ env.POLYTOMIC_API_KEY }}

The following arguments are supported:

  • api_key: The Polytomic API key to use when exporting resources (required).
  • output_dir: The output directly to write to; defaults to terraform.
  • url: The URL of the Polytomic deployment to sync from; defaults to https://app.polytomic.com.

Examples

This action is typically used with other actions that commit the exported HCL, open a pull request, or use the generated files in some other way.

Commit changes from Polytomic

To fetch changes from Polytomic and commit them to the default branch, you can use the following workflow.

on:
  schedule:
    # Runs "At every 10th minute." (https://crontab.guru/#*/10_*_*_*_*)
    - cron: "*/10 * * * *"

env:
  POLYTOMIC_API_KEY: ${{ secrets.POLYTOMIC_API_KEY }}

jobs:
  update-repo:
    environment: exporter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Create output directory
        run: |
          mkdir -p terraform
      - name: Polytomic Terraform Sync
        uses: polytomic/[email protected]
        with:
          api_key: ${{ env.POLYTOMIC_API_KEY }}
      - name: Commit changes
        uses: EndBug/add-and-commit@v9

Open a PR with changes

The following workflow is an example which fetches changes and opens a PR; this is similar to what the terraform-sync-template repository does.

on:
  schedule:
    # Runs "At every 10th minute." (https://crontab.guru/#*/10_*_*_*_*)
    - cron: "*/10 * * * *"

env:
  POLYTOMIC_API_KEY: ${{ secrets.POLYTOMIC_API_KEY }}

jobs:
  pull-request:
    environment: exporter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Create output directory
        run: |
          mkdir -p terraform
      - name: Polytomic Terraform Sync
        uses: polytomic/[email protected]
        with:
          api_key: ${{ env.POLYTOMIC_API_KEY }}
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v6
        with:
          commit-message: Sync terraform
          title: Polytomic Terraform Sync
          body: |
            This is a pull request by [Polytomic](https://polytomic.com) to sync terraform configuration.
            _Auto-generated by polytomic terraform sync_
          branch: polytomic-terraform