Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
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
Comment thread
pv72895 marked this conversation as resolved.
Outdated
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 }}
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
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 }}
10 changes: 10 additions & 0 deletions .gitignore
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
50 changes: 50 additions & 0 deletions .goreleaser.yml
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:"
9 changes: 9 additions & 0 deletions .trunk/.gitignore
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
4 changes: 4 additions & 0 deletions .trunk/configs/.markdownlint.yaml
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
7 changes: 7 additions & 0 deletions .trunk/configs/.yamllint.yaml
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
37 changes: 37 additions & 0 deletions .trunk/trunk.yaml
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
84 changes: 82 additions & 2 deletions README.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI generated

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`.
19 changes: 19 additions & 0 deletions docs/index.md
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.
55 changes: 55 additions & 0 deletions docs/resources/merge_queue.md
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).
3 changes: 3 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
terraform.tfstate*
.terraform/
.terraform.lock.hcl
13 changes: 13 additions & 0 deletions examples/provider/main.tf
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" {}
21 changes: 21 additions & 0 deletions examples/resources/trunk_merge_queue/main.tf
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"
}
Loading
Loading