This repository contains a Terraform provider for Chalk, enabling infrastructure-as-code management of Chalk resources.
- Clone the repository
- Enter the repository directory
- Build the provider using the Go
installcommand:
go installConfigure the provider in your Terraform configuration:
terraform {
required_providers {
chalk = {
source = "chalk-ai/chalk"
version = "~> 0.1"
}
}
}
provider "chalk" {
api_token = var.chalk_api_token # or use CHALK_API_TOKEN environment variable
api_url = "https://api.chalk.ai" # optional, defaults to https://api.chalk.ai
}The provider supports authentication via:
api_tokenprovider configurationCHALK_API_TOKENenvironment variable
Query environment information:
data "chalk_environment" "prod" {
name = "production"
}
output "environment_id" {
value = data.chalk_environment.prod.id
}Tests are organized into two categories:
-
Unit Tests: Located alongside the source files (e.g.,
provider_test.go)func TestAccEnvironmentDataSource(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, Steps: []resource.TestStep{ { Config: testAccEnvironmentDataSourceConfig("production"), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.chalk_environment.test", "name", "production"), resource.TestCheckResourceAttrSet("data.chalk_environment.test", "id"), ), }, }, }) }
-
Acceptance Tests: Run against a real Chalk API
# Run acceptance tests make testacc # Run specific test TF_ACC=1 go test ./internal/provider -v -run TestAccEnvironmentDataSource
Before running acceptance tests:
export CHALK_API_TOKEN="your-api-token"
export TF_ACC=1-
Build and install the provider locally:
make install
-
Create a test Terraform configuration:
# main.tf terraform { required_providers { chalk = { source = "registry.terraform.io/chalk-ai/chalk" version = "0.1.0" } } } provider "chalk" { api_token = "your-test-token" } data "chalk_environment" "test" { name = "production" } output "env_info" { value = data.chalk_environment.test }
-
Run Terraform commands:
terraform init terraform plan
For active development, use a Terraform CLI configuration file to override the provider:
-
Create
~/.terraformrc:provider_installation { dev_overrides { "chalk-ai/chalk" = "/Users/yourusername/go/bin" } direct {} }
-
Build the provider:
go build -o /Users/yourusername/go/bin/terraform-provider-chalk
-
Now Terraform will use your local build without requiring
terraform init.
chalk_environment- Query information about a Chalk environment
- Make your changes
- Run tests:
make test - Run linter:
make lint - Format code:
make fmt - Build provider:
make build
To run the provider with debug output:
# Build with debug flag
go build -gcflags="all=-N -l" -o terraform-provider-chalk
# Run Terraform with debug logging
TF_LOG=DEBUG terraform planTo attach a debugger:
# Start provider in debug mode
./terraform-provider-chalk -debug
# Provider will output something like:
# Provider started, to attach Terraform set the TF_REATTACH_PROVIDERS env var:
# TF_REATTACH_PROVIDERS='{"chalk-ai/chalk":{"Protocol":"grpc","Pid":12345,"Test":true,"Addr":{"Network":"unix","String":"/tmp/plugin123456"}}}'
# In another terminal, use the provided environment variable
export TF_REATTACH_PROVIDERS='...'
terraform planmake build- Build the providermake install- Build and install the provider locallymake test- Run unit testsmake testacc- Run acceptance testsmake fmt- Format Go code and Terraform examplesmake lint- Run linters
Provider documentation is generated from the schema descriptions. To view the documentation for a data source or resource, refer to the schema definitions in the source code.
This provider is distributed under the MIT License.