https://github.com/stacklet/terraform-provider-stacklet
Terraform provider for Stacklet Platform
https://github.com/stacklet/terraform-provider-stacklet
go prod prod-public terraform
Last synced: about 2 months ago
JSON representation
Terraform provider for Stacklet Platform
- Host: GitHub
- URL: https://github.com/stacklet/terraform-provider-stacklet
- Owner: stacklet
- Created: 2025-03-09T22:04:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-02-26T15:37:28.000Z (3 months ago)
- Last Synced: 2026-02-26T21:44:28.099Z (3 months ago)
- Topics: go, prod, prod-public, terraform
- Language: Go
- Homepage: https://registry.terraform.io/providers/stacklet/stacklet
- Size: 17.4 MB
- Stars: 2
- Watchers: 9
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Terraform Provider for Stacklet
This Terraform Provider allows you to interact with Stacklet's GraphQL API to
manage your resources through Infrastructure as Code.
## Using the provider
The provider is configured as follows:
```terraform
terraform {
required_providers {
stacklet = {
source = "stacklet/stacklet"
}
}
}
provider "stacklet" {
endpoint = "https://api..stacklet.io/"
api_key = ""
}
```
### Environment variables
As an alternative, endpoint and key can be defined as environment variables:
```bash
export STACKLET_ENDPOINT="https://api..stacklet.io/"
export STACKLET_API_KEY=""
```
### Login via `stacklet-admin` CLI
The provider can also look up authentication details from the
[`stacklet-admin`](https://github.com/stacklet/stacklet-admin) CLI.
After configuring and logging in to the instance via the CLI (`stacklet-admin
login`), the provider will be able to connect to it without needing to specify
credentials in the configuration or via environment variables.
### Example configuration
Below is a full example of a configuration to create a few resources in Stacklet.
```terraform
terraform {
required_providers {
stacklet = {
source = "stacklet/stacklet"
}
}
}
provider "stacklet" {
endpoint = "https://api..stacklet.io/"
api_key = ""
}
data "stacklet_policy_collection" "example" {
name = "aws policies for cis-aws"
}
data "stacklet_policy" "one" {
name = "aws-neptune-cluster-encrypted-rtc"
}
resource "stacklet_policy_collection" "example" {
name = "example-collection"
cloud_provider = "AWS"
description = "Example policy collection"
auto_update = true
}
resource "stacklet_account_group" "example" {
name = "example-account-group"
cloud_provider = "AWS"
description = "Example account group"
regions = ["us-east-1", "us-east-2"]
}
data "stacklet_account" "one" {
cloud_provider = "AWS"
key = "123456789012"
}
resource "stacklet_account_group_mapping" "one" {
group_uuid = stacklet_account_group.example.uuid
account_key = data.stacklet_account.one.key
}
resource "stacklet_policy_collection_mapping" "one" {
collection_uuid = stacklet_policy_collection.example.uuid
policy_uuid = data.stacklet_policy.one.uuid
policy_version = 2
}
resource "stacklet_account" "two" {
cloud_provider = "AWS"
key = "000000000000" # AWS account ID
name = "test-acccount"
short_name = "tftest"
description = "Test account"
email = "cloud-team@example.com"
}
resource "stacklet_binding" "binding" {
name = "test-binding"
description = "Created with terraform"
account_group_uuid = stacklet_account_group.example.uuid
policy_collection_uuid = stacklet_policy_collection.example.uuid
}
data "stacklet_binding" "binding" {
name = "AWS Posture"
}
```
## Local development
For local development, make sure you have the tools declared in the
[`.tool-versions`](./.tool-versions) file installed.
### Building the provider
1. Clone the repository:
```bash
git clone https://github.com/stacklet/terraform-provider-stacklet.git
cd terraform-provider-stacklet
```
2. Build the provider:
```bash
just build
```
### Running locally built provider
To run the locally built copy of the provider, terraform must be configured as
follows:
1. Override the provider location for development, by creating a
`~/.terraformrc` with the following content:
```terraform
provider_installation {
dev_overrides {
"stacklet/stacklet" = ""
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use the
# dev_overrides block, and so no other providers will be available.
direct {}
}
```
2. Declare the provider in your terraform configuration as
```terraform
terraform {
required_providers {
stacklet = {
source = "stacklet/stacklet"
}
}
}
provider "stacklet" {
endpoint = "https://api..stacklet.io/" # Or set STACKLET_ENDPOINT env var
api_key = "" # Or set STACKLET_API_KEY env var
}
```
3. Run `terraform plan` or `terraform apply` with the local resources configuration.
**Note**: `terraform init` must not be run when working with a locally installed provider.
### Debugging
Debug messages and output are not visible when running the provider directly
from terraform. To enable debug:
1. Run `./terraform-provider-stacklet -debug` in one terminal.
2. In a separate terminal, export the value for the `TF_REATTACH_PROVIDERS`
variable provided in the output of the previous command, and run
`terraform`.
## Release process
1. Update the [Changelog](./CHANGELOG.md) with an entry for the new release.
2. Create a release tag with `just tag-release X.Y.Z ` on the desired
commit (default `HEAD`).
3. Push the tag upstream. This will start the Release workflow which creates
the release on GitHub and builds packages. Once it completes, the relase
will be published and the Terraform registry will pick up the new release
automatically.