-
Notifications
You must be signed in to change notification settings - Fork 0
Port over terraform provider from Trunk2 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
trunk-staging-io
merged 5 commits into
main
from
phil/port-over-merge-terraform-provider
Apr 6, 2026
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - v* | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| goreleaser: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: true | ||
| - name: Import GPG key | ||
| uses: crazy-max/ghaction-import-gpg@v6 | ||
| id: import_gpg | ||
| with: | ||
| gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | ||
| passphrase: ${{ secrets.GPG_PASSPHRASE }} | ||
| - name: Run GoReleaser | ||
| uses: goreleaser/goreleaser-action@v6 | ||
| with: | ||
| args: release --clean | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Tests | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| push: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: true | ||
| - run: go build ./... | ||
| - run: go test ./internal/client/ -v | ||
|
|
||
| acceptance: | ||
| if: github.ref == 'refs/heads/main' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache: true | ||
| - run: go test ./internal/provider/ -v -timeout 10m | ||
| env: | ||
| TF_ACC: "1" | ||
| TRUNK_API_KEY: ${{ secrets.TRUNK_API_KEY }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Build artifacts | ||
| terraform-provider-trunk | ||
| coverage.out | ||
| dist/ | ||
|
|
||
| # Terraform state | ||
| *.tfstate | ||
| *.tfstate.* | ||
| .terraform/ | ||
| .terraform.lock.hcl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| version: 2 | ||
|
|
||
| builds: | ||
| - env: | ||
| - CGO_ENABLED=0 | ||
| mod_timestamp: "{{ .CommitTimestamp }}" | ||
| flags: | ||
| - -trimpath | ||
| ldflags: | ||
| - -s -w -X main.version={{ .Version }} | ||
| goos: | ||
| - linux | ||
| - darwin | ||
| - windows | ||
| goarch: | ||
| - amd64 | ||
| - arm64 | ||
| ignore: | ||
| - goos: windows | ||
| goarch: arm64 | ||
|
|
||
| archives: | ||
| - format: zip | ||
| name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" | ||
|
|
||
| checksum: | ||
| name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS" | ||
| algorithm: sha256 | ||
|
|
||
| signs: | ||
| - artifacts: checksum | ||
| args: | ||
| - --batch | ||
| - --local-user | ||
| - "{{ .Env.GPG_FINGERPRINT }}" | ||
| - --output | ||
| - ${signature} | ||
| - --detach-sign | ||
| - ${artifact} | ||
|
|
||
| release: | ||
| draft: false | ||
|
|
||
| changelog: | ||
| sort: asc | ||
| filters: | ||
| exclude: | ||
| - "^docs:" | ||
| - "^test:" | ||
| - "^chore:" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| *out | ||
| *logs | ||
| *actions | ||
| *notifications | ||
| *tools | ||
| plugins | ||
| user_trunk.yaml | ||
| user.yaml | ||
| tmp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Prettier friendly markdownlint config (all formatting rules disabled) | ||
| extends: markdownlint/style/prettier | ||
| # MD033: tfplugindocs generates <a id="..."> anchors in docs/ — unavoidable | ||
| MD033: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| rules: | ||
| quoted-strings: | ||
| required: only-when-needed | ||
| extra-allowed: ["{|}"] | ||
| key-duplicates: {} | ||
| octal-values: | ||
| forbid-implicit-octal: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # This file controls the behavior of Trunk: https://docs.trunk.io/cli | ||
| # To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml | ||
| version: 0.1 | ||
| cli: | ||
| version: 1.25.0 | ||
| # Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) | ||
| plugins: | ||
| sources: | ||
| - id: trunk | ||
| ref: v1.7.6 | ||
| uri: https://github.com/trunk-io/plugins | ||
| # Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) | ||
| runtimes: | ||
| enabled: | ||
| - go@1.25.8 | ||
| - node@22.16.0 | ||
| - python@3.10.8 | ||
| # This is the section where you manage your linters. (https://docs.trunk.io/check/configuration) | ||
| lint: | ||
| enabled: | ||
| - actionlint@1.7.12 | ||
| - checkov@3.2.517 | ||
| - git-diff-check | ||
| - gofmt@1.20.4 | ||
| - golangci-lint2@2.11.4 | ||
| - markdownlint@0.48.0 | ||
| - osv-scanner@2.3.5 | ||
| - prettier@3.8.1 | ||
| - tflint@0.61.0 | ||
| - trufflehog@3.94.2 | ||
| - yamllint@1.38.0 | ||
| actions: | ||
| enabled: | ||
| - trunk-announce | ||
| - trunk-check-pre-push | ||
| - trunk-fmt-pre-commit | ||
| - trunk-upgrade-available |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI generated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,82 @@ | ||
| # terraform-provider-trunk | ||
| A terraform provider for setting up Trunk managed resources through Terraform. Currently, this supports managing Merge Queues | ||
| # Terraform Provider for Trunk.io | ||
|
|
||
| The Trunk provider lets you manage [Trunk.io](https://trunk.io) services with Terraform. Currently supports merge queue configuration. | ||
|
|
||
| ## Requirements | ||
|
|
||
| - [Terraform](https://www.terraform.io/downloads) >= 1.0 | ||
| - [Go](https://golang.org/dl/) >= 1.24 (to build the provider from source) | ||
|
|
||
| ## Usage | ||
|
|
||
| ```hcl | ||
| terraform { | ||
| required_providers { | ||
| trunk = { | ||
| source = "trunk-io/trunk" | ||
| version = "~> 0.1" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| provider "trunk" { | ||
| # api_key can be set here or via the TRUNK_API_KEY environment variable | ||
| } | ||
|
|
||
| resource "trunk_merge_queue" "example" { | ||
| repo = { | ||
| host = "github.com" | ||
| owner = "my-org" | ||
| name = "my-repo" | ||
| } | ||
| target_branch = "main" | ||
| mode = "parallel" | ||
| concurrency = 3 | ||
| merge_method = "SQUASH" | ||
| } | ||
| ``` | ||
|
|
||
| Full documentation is available on the [Terraform Registry](https://registry.terraform.io/providers/trunk-io/trunk/latest/docs). | ||
|
|
||
| ## Authentication | ||
|
|
||
| Set your Trunk API key via the `TRUNK_API_KEY` environment variable or the `api_key` provider attribute. Org-level API tokens are required. | ||
|
|
||
| ## Development | ||
|
|
||
| ### Build | ||
|
|
||
| ```bash | ||
| go build ./... | ||
| ``` | ||
|
|
||
| ### Test | ||
|
|
||
| ```bash | ||
| # Unit tests (no API key required) | ||
| go test ./internal/client/ -v | ||
|
|
||
| # Acceptance tests (requires a real API key and a test repository) | ||
| TF_ACC=1 TRUNK_API_KEY=<key> go test ./internal/provider/ -v -timeout 10m | ||
| ``` | ||
|
|
||
| ### Local testing with Terraform | ||
|
|
||
| Build the binary and configure `dev_overrides` to bypass the registry: | ||
|
|
||
| ```bash | ||
| go build -o terraform-provider-trunk . | ||
| ``` | ||
|
|
||
| Add to `~/.terraformrc`: | ||
|
|
||
| ```hcl | ||
| provider_installation { | ||
| dev_overrides { | ||
| "registry.terraform.io/trunk-io/trunk" = "/path/to/terraform-provider-trunk" | ||
| } | ||
| direct {} | ||
| } | ||
| ``` | ||
|
|
||
| Then run `terraform plan` in any example directory — no `terraform init` needed with `dev_overrides`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | ||
| page_title: "trunk Provider" | ||
| description: |- | ||
| Interact with Trunk.io services. | ||
| --- | ||
|
|
||
| # trunk Provider | ||
|
|
||
| Interact with Trunk.io services. | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
|
|
||
| ## Schema | ||
|
|
||
| ### Optional | ||
|
|
||
| - `api_key` (String, Sensitive) API key for Trunk.io. Can also be set via the TRUNK_API_KEY environment variable. | ||
| - `base_url` (String) Base URL for the Trunk API. Defaults to `https://api.trunk.io/v1`. Can also be set via the TRUNK_BASE_URL environment variable. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | ||
| page_title: "trunk_merge_queue Resource - terraform-provider-trunk" | ||
| subcategory: "" | ||
| description: |- | ||
| Manages a Trunk merge queue. | ||
| --- | ||
|
|
||
| # trunk_merge_queue (Resource) | ||
|
|
||
| Manages a Trunk merge queue. | ||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
|
|
||
| ## Schema | ||
|
|
||
| ### Required | ||
|
|
||
| - `repo` (Attributes) Repository this queue is associated with. (see [below for nested schema](#nestedatt--repo)) | ||
| - `target_branch` (String) Target branch for the merge queue. | ||
|
|
||
| ### Optional | ||
|
|
||
| - `batch` (Boolean) Enable batching. | ||
| - `batching_max_wait_time_minutes` (Number) Maximum minutes to wait for a batch to fill. | ||
| - `batching_min_size` (Number) Minimum number of PRs per batch. | ||
| - `bisection_concurrency` (Number) Number of concurrent tests during bisection. | ||
| - `can_optimistically_merge` (Boolean) Allow optimistic merge when a lower PR passes. | ||
| - `commands_enabled` (Boolean) Allow /trunk merge comments. | ||
| - `comments_enabled` (Boolean) Post GitHub comments on PRs. | ||
| - `concurrency` (Number) Number of concurrent test slots. | ||
| - `create_prs_for_testing_branches` (Boolean) Create PRs for testing branches. | ||
| - `direct_merge_mode` (String) Direct merge mode: "OFF" or "ALWAYS". | ||
| - `merge_method` (String) Merge method: "MERGE_COMMIT", "SQUASH", or "REBASE". | ||
| - `mode` (String) Queue mode: "single" or "parallel". | ||
| - `optimization_mode` (String) Optimization mode: "OFF" or "BISECTION_SKIP_REDUNDANT_TESTS". | ||
| - `pending_failure_depth` (Number) Number of PRs below a failure to wait for before eviction. | ||
| - `required_statuses` (List of String) Override required status checks. Set to null to revert to branch protection or trunk.yaml defaults; set to [] to explicitly require no statuses. | ||
| - `state` (String) Queue state: "RUNNING", "PAUSED", or "DRAINING". | ||
| - `status_check_enabled` (Boolean) Post GitHub status checks. | ||
| - `testing_timeout_minutes` (Number) Maximum minutes to wait for tests. | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `id` (String) Unique identifier for this queue in the format {host}/{owner}/{name}/{target_branch}. | ||
|
|
||
| <a id="nestedatt--repo"></a> | ||
|
|
||
| ### Nested Schema for `repo` | ||
|
|
||
| Required: | ||
|
|
||
| - `host` (String) Repository host (e.g., "github.com"). | ||
| - `name` (String) Repository name. | ||
| - `owner` (String) Repository owner (organization or user). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| terraform.tfstate* | ||
| .terraform/ | ||
| .terraform.lock.hcl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
| required_providers { | ||
| trunk = { | ||
| source = "trunk-io/trunk" | ||
| version = "~> 0.1" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Configure the Trunk provider. | ||
| # api_key can be set here or via the TRUNK_API_KEY environment variable. | ||
| provider "trunk" {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
| required_providers { | ||
| trunk = { | ||
| source = "trunk-io/trunk" | ||
| version = "~> 0.1" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "trunk_merge_queue" "example" { | ||
| repo = { | ||
| host = "github.com" | ||
| owner = "my-org" | ||
| name = "my-repo" | ||
| } | ||
| target_branch = "main" | ||
| mode = "parallel" | ||
| concurrency = 3 | ||
| merge_method = "SQUASH" | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.