2026-10-12 12:07:42 -07:00
# Terraform Provider for Threshold
A community fork of [hashicorp/terraform-provider-boundary ](https://github.com/hashicorp/terraform-provider-boundary )
for [Threshold ](https://repo.anhonesthost.net/CyberCoveLLC/threshold ), itself a community fork of Boundary CE.
## About this fork
- **Upstream:** `hashicorp/terraform-provider-boundary` , licensed MPL-2.0 (see [LICENSE ](LICENSE ) and [NOTICE ](NOTICE )).
This fork is not affiliated with, endorsed by, or supported by HashiCorp or IBM.
- **What changed:** the Go module is `repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold` ,
it builds against the Threshold `api` and `sdk` Go modules
(`repo.anhonesthost.net/CyberCoveLLC/threshold/api` and `.../sdk` ), and product wording in docs and
schema descriptions says "Threshold". Release plumbing for HashiCorp's CRT/registry pipeline was removed.
- **Compatibility:** resource and data source type names (`boundary_*` ), provider arguments (`addr` ,
`auth_method_id` , ...) and the `BOUNDARY_*` environment variables are unchanged, so existing Terraform
configurations keep working. Because the resource types start with `boundary_` , Terraform infers the
provider local name `boundary` ; keep `boundary = { source = ... }` in `required_providers` .
- **Distribution:** there is no public registry for this provider. Install it from a release zip or a local build
as described below. Its address is `repo.anhonesthost.net/cybercovellc/threshold` .
2020-09-18 14:04:32 -07:00
2026-10-12 12:07:42 -07:00
## Requirements
2020-05-14 17:06:23 -07:00
2026-10-12 12:07:42 -07:00
- [Terraform ](https://www.terraform.io/downloads.html ) >= 0.13.x (or OpenTofu)
- [Go ](https://golang.org/doc/install ) >= 1.26 (see `go.mod` ), with `GOPRIVATE=repo.anhonesthost.net` if the Threshold modules are not publicly fetchable
2020-10-14 15:27:13 -04:00
2026-10-12 12:07:42 -07:00
## Installing
2020-05-14 17:06:23 -07:00
2026-10-12 12:07:42 -07:00
Provider address: `repo.anhonesthost.net/cybercovellc/threshold` . Version `0.1.0` is used in the examples.
2020-05-14 17:06:23 -07:00
2026-10-12 12:07:42 -07:00
### 1. Build locally
2020-05-14 17:06:23 -07:00
2026-10-12 12:07:42 -07:00
```sh
export GOPRIVATE = repo.anhonesthost.net
make build-all VERSION = 0.1.0 # or: scripts/build-release.sh 0.1.0 dist
# single platform, no zip:
go build -o terraform-provider-threshold .
# with goreleaser installed:
goreleaser build --snapshot --clean --single-target
```
`make build-all` writes `dist/terraform-provider-threshold_<version>_<os>_<arch>.zip` for linux, darwin and
windows on amd64 and arm64 (needs `zip` ). Never commit `dist/` .
### 2. Filesystem mirror (recommended for shared hosts)
Terraform's `provider_installation` can serve providers from a local directory. Layout (unpacked form):
```
/usr/share/terraform/providers/
repo.anhonesthost.net/cybercovellc/threshold/0.1.0/linux_amd64/terraform-provider-threshold_v0.1.0
```
or the packed form: `.../repo.anhonesthost.net/cybercovellc/threshold/terraform-provider-threshold_0.1.0_linux_amd64.zip` .
Then in `~/.terraformrc` (`%APPDATA%\terraform.rc` on Windows):
```hcl
provider_installation {
filesystem_mirror {
path = "/usr/share/terraform/providers"
include = [ "repo.anhonesthost.net/cybercovellc/threshold" ]
}
direct {
exclude = [ "repo.anhonesthost.net/cybercovellc/threshold" ]
}
}
```
2020-09-17 16:27:48 -04:00
2026-10-12 12:07:42 -07:00
and in your configuration:
2020-09-17 16:27:48 -04:00
```hcl
terraform {
2023-10-17 19:36:51 -04:00
required_providers {
boundary = {
2026-10-12 12:07:42 -07:00
source = "repo.anhonesthost.net/cybercovellc/threshold"
version = "0.1.0"
2023-10-17 19:36:51 -04:00
}
}
2020-09-17 16:27:48 -04:00
}
2026-10-12 12:07:42 -07:00
provider "boundary" {
addr = "https://threshold.example.com:9200"
# auth_method_id / auth_method_login_name / auth_method_password, token, or recovery_kms_hcl
}
```
### 3. dev_overrides (development)
Build the binary into a directory and point Terraform at it (`terraform init` is not needed, and `terraform plan`
prints a warning):
```hcl
# ~/.terraformrc
provider_installation {
dev_overrides {
"repo.anhonesthost.net/cybercovellc/threshold" = "/home/you/go/bin" # directory holding terraform-provider-threshold
}
direct {}
}
2020-05-14 17:06:23 -07:00
```
2026-10-12 12:07:42 -07:00
`go install .` places `terraform-provider-threshold` in `$GOPATH/bin` . `make dev` installs a `0.0.1` build
into Terraform's implied local mirror under the same address.
## Building The Provider
1. Clone the repository
1. Enter the repository directory
1. Build with `go build -o terraform-provider-threshold .` (or `make dev` , which also builds the optional built-in KMS plugins from `plugins/kms/mains` )
2023-10-17 19:36:51 -04:00
## Adding Dependencies
2020-05-14 17:06:23 -07:00
This provider uses [Go modules ](https://github.com/golang/go/wiki/Modules ).
Please see the Go documentation for the most up to date information about using Go modules.
To add a new dependency `github.com/author/dependency` to your Terraform provider:
2023-10-17 19:36:51 -04:00
```shell
2020-05-14 17:06:23 -07:00
go get github.com/author/dependency
go mod tidy
```
Then commit the changes to `go.mod` and `go.sum` .
2023-10-17 19:36:51 -04:00
## Developing the Provider
2020-10-02 18:16:11 -07:00
If you wish to work on the provider, you'll first need [Go ](http://www.golang.org ) installed on your machine (see [Requirements ](#requirements ) above).
To compile the provider, run `go install` . This will build the provider and put the provider binary in the `$GOPATH/bin` directory.
2026-10-12 12:07:42 -07:00
Unit tests (no controller needed) run with `make test` . All other tests are acceptance tests and require a running
Threshold/Boundary-compatible controller (`BOUNDARY_ADDR` , `BOUNDARY_AUTH_TOKEN` , `BOUNDARY_DEV_RECOVERY_KEY` ) and, for the
Vault tests, Docker. In order to run the full suite of Acceptance tests,
2021-09-21 08:38:48 -04:00
a postgres docker container must be started first:
```sh
$ go mod download # ensure boundary is installed, files are used by the docker image
$ make test-database-up
```
Once the test database is ready the tests can be run using `make testacc` .
2020-10-02 18:16:11 -07:00
*Note:* Acceptance tests create real resources, and often cost money to run.
```sh
$ make testacc
```
2020-05-14 17:06:23 -07:00
2021-09-21 08:38:48 -04:00
For more details on the docker image and troubleshooting see the
2026-10-12 12:07:42 -07:00
[Threshold contributing guide ](https://repo.anhonesthost.net/CyberCoveLLC/threshold ).
2021-09-21 08:38:48 -04:00
2023-10-17 19:36:51 -04:00
## Debugging the provider
2026-10-12 12:07:42 -07:00
If you're using vscode, this provider has delve debugging baked into the [.vscode ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/tree/main/.vscode ) directory. To debug you can find instructions [here. ](https://dev.to/drewmullen/vscode-terraform-provider-development-setup-debugging-6bn#usage )
2023-10-17 19:36:51 -04:00
## Generating Docs
2026-10-12 12:07:42 -07:00
This provider uses the [terraform-plugin-docs ](https://github.com/hashicorp/terraform-plugin-docs/ ) tool to generate documentation. Each resource and data source requires a set of examples [examples ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/tree/main/examples ) then you execute a binary to generate the docs which are placed in [./docs ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/tree/main/docs ). Optionally, you can specify your own [templates ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/tree/main/templates ) for a resource or data source if you want to add custom information (example: [data "boundary_scope" ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/blob/main/templates/data-sources/scope.md.tmpl#L11 ))
2023-10-17 19:36:51 -04:00
### New Resources & Data Sources (documentation templates)
2026-10-12 12:07:42 -07:00
If you're adding a new resource or a data source, you must include a documentation template for your new R/DS in [./templates ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/tree/main/templates ) directory. This provider uses the [terraform-plugin-docs ](https://github.com/hashicorp/terraform-plugin-docs/ ) tool to generate documentation. For full details see the link.
2023-10-17 19:36:51 -04:00
### Documentation Examples for Resources & Data Sources
2026-10-12 12:07:42 -07:00
Examples are required for all resources and data sources. This provider uses the [terraform-plugin-docs ](https://github.com/hashicorp/terraform-plugin-docs/ ) tool to generate documentation. To add examples, add a new file to the [./examples ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/tree/main/examples ) directory or update the existing files. Next make sure the corresponding template in [./templates ](https://repo.anhonesthost.net/CyberCoveLLC/terraform-provider-threshold/tree/main/templates ) directory references this example.
2023-10-17 19:36:51 -04:00
### Generating
2020-10-06 20:34:16 -04:00
From the root of the repo run:
2023-10-17 19:36:51 -04:00
```shell
2020-10-06 20:34:16 -04:00
go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
```
2023-10-17 19:36:51 -04:00
## Using the provider
2026-10-12 12:07:42 -07:00
Please see our detailed docs for individual resource usage. Below is a complex example using the provider to configure all resource types available:
2020-09-03 15:53:29 -07:00
```hcl
provider "boundary" {
2024-07-15 10:02:58 -04:00
addr = "http://127.0.0.1:9200"
auth_method_id = "ampw_1234567890" # changeme
auth_method_login_name = "myuser" # changeme
auth_method_password = "passpass" # changeme
2020-09-03 15:53:29 -07:00
}
2020-10-02 18:16:11 -07:00
variable "users" {
2020-09-16 16:34:26 -04:00
type = set ( string )
2020-09-03 15:53:29 -07:00
default = [
2020-10-02 18:16:11 -07:00
"Jim" ,
"Mike" ,
"Todd" ,
"Jeff" ,
"Randy" ,
"Susmitha"
2020-09-03 15:53:29 -07:00
]
}
2020-10-02 18:16:11 -07:00
variable "readonly_users" {
2020-09-16 16:34:26 -04:00
type = set ( string )
2020-09-03 15:53:29 -07:00
default = [
2020-10-02 18:16:11 -07:00
"Jeff" ,
"Pete" ,
"JT"
2020-09-03 15:53:29 -07:00
]
}
variable "backend_server_ips" {
2020-09-16 16:34:26 -04:00
type = set ( string )
2020-09-03 15:53:29 -07:00
default = [
"10.1.0.1" ,
"10.1.0.2" ,
]
}
2020-09-16 16:34:26 -04:00
resource "boundary_scope" "global" {
global_scope = true
scope_id = "global"
}
resource "boundary_scope" "corp" {
2020-10-13 23:12:03 -04:00
scope_id = boundary_scope . global . id
auto_create_admin_role = true
auto_create_default_role = true
2020-09-16 16:34:26 -04:00
}
2020-09-03 15:53:29 -07:00
2020-10-02 18:16:11 -07:00
resource "boundary_user" "users" {
for_each = var . users
2020-09-03 15:53:29 -07:00
name = each . key
2020-10-02 18:16:11 -07:00
description = "User resource for ${each.key}"
2020-09-16 16:34:26 -04:00
scope_id = boundary_scope . corp . id
2020-09-03 15:53:29 -07:00
}
2023-10-17 19:36:51 -04:00
// organization level group for readonly users
2020-10-02 18:16:11 -07:00
resource "boundary_group" "readonly" {
name = "readonly"
description = "Organization group for readonly users"
member_ids = [ for user in boundary_user . readonly_users : user . id ]
2020-09-16 16:34:26 -04:00
scope_id = boundary_scope . corp . id
2020-09-03 15:53:29 -07:00
}
// add org - level role for readonly access
resource "boundary_role" "organization_readonly" {
name = "readonly"
description = "Read-only role"
2020-10-02 18:16:11 -07:00
principal_ids = [ boundary_group . readonly_users . id ]
2024-02-01 08:36:14 -08:00
grant_strings = ["ids = *;type = *;actions = read " ]
2020-09-16 16:34:26 -04:00
scope_id = boundary_scope . corp . id
2020-09-03 15:53:29 -07:00
}
// add org - level role for administration access
resource "boundary_role" "organization_admin" {
name = "admin"
description = "Administrator role"
2020-09-16 16:34:26 -04:00
principal_ids = concat (
2020-10-02 18:16:11 -07:00
[ for user in boundary_user . user : user . id ]
2020-09-03 15:53:29 -07:00
)
2024-02-01 08:36:14 -08:00
grant_strings = ["ids = *;type = *;actions = create , read , update , delete " ]
2020-09-16 16:34:26 -04:00
scope_id = boundary_scope . corp . id
2020-09-03 15:53:29 -07:00
}
// create a project for core infrastructure
2020-09-16 16:34:26 -04:00
resource "boundary_scope" "core_infra" {
2020-10-13 23:12:03 -04:00
description = "Core infrastrcture"
scope_id = boundary_scope . corp . id
auto_create_admin_role = true
2020-09-03 15:53:29 -07:00
}
resource "boundary_host_catalog" "backend_servers" {
name = "backend_servers"
2020-10-02 18:16:11 -07:00
description = "Backend servers host catalog"
2020-09-16 16:34:26 -04:00
type = "static"
scope_id = boundary_scope . core_infra . id
}
2020-10-02 18:16:11 -07:00
resource "boundary_host" "backend_servers" {
for_each = var . backend_server_ips
type = "static"
name = "backend_server_service_${each.value}"
description = "Backend server host"
address = "${each.key}"
2020-09-03 15:53:29 -07:00
host_catalog_id = boundary_host_catalog . backend_servers . id
}
resource "boundary_host_set" "backend_servers_ssh" {
2020-10-02 18:16:11 -07:00
type = "static"
2020-09-03 15:53:29 -07:00
name = "backend_servers_ssh"
2020-10-02 18:16:11 -07:00
description = "Host set for backend servers"
2020-09-03 15:53:29 -07:00
host_catalog_id = boundary_host_catalog . backend_servers . id
2020-10-02 18:16:11 -07:00
host_ids = [ for host in boundary_host . backend_servers : host . id ]
2020-09-03 15:53:29 -07:00
}
2020-10-02 18:16:11 -07:00
// create target for accessing backend servers on port : 8000
2020-09-03 15:53:29 -07:00
resource "boundary_target" "backend_servers_service" {
2020-10-02 18:16:11 -07:00
type = "tcp"
name = "backend_servers_service"
description = "Backend service target"
scope_id = boundary_scope . core_infra . id
default_port = "8080"
2020-09-03 15:53:29 -07:00
host_set_ids = [
2020-10-02 18:16:11 -07:00
boundary_host_set . backend_servers . id
2020-09-03 15:53:29 -07:00
]
}
2020-10-02 18:16:11 -07:00
// create target for accessing backend servers on port : 22
2020-09-03 15:53:29 -07:00
resource "boundary_target" "backend_servers_ssh" {
2020-10-02 18:16:11 -07:00
type = "tcp"
name = "backend_servers_ssh"
description = "Backend SSH target"
scope_id = boundary_scope . core_infra . id
default_port = "22"
2020-09-03 15:53:29 -07:00
host_set_ids = [
2020-09-16 16:34:26 -04:00
boundary_host_set . backend_servers_ssh . id
2020-09-03 15:53:29 -07:00
]
}
2020-05-14 17:06:23 -07:00
```