Merge pull request #15 from beatz174-bit/codex/add-binary-version-metadata-to-provider

Add ldflags-based version metadata to provider binary
This commit is contained in:
beatz174-bit
2026-04-23 13:46:51 +10:00
committed by GitHub
3 changed files with 57 additions and 1 deletions
+9
View File
@@ -18,3 +18,12 @@ jobs:
- name: Verify formatting and run quality gate
run: ./scripts/check.sh
- name: Build provider binary (stamped metadata)
run: |
VERSION="${GITHUB_REF_NAME:-dev}"
COMMIT="$(git rev-parse --short HEAD)"
DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
go build -o terraform-provider-dynu \
-ldflags="-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}"
+32
View File
@@ -14,6 +14,11 @@ This provider is **not published** to the Terraform Registry yet. For local deve
go build -o terraform-provider-dynu
```
By default, local builds use embedded metadata values:
- `version=dev`
- `commit=none`
- `built=unknown`
2. Configure `~/.terraformrc`:
```hcl
@@ -53,6 +58,33 @@ terraform plan
When provider configuration or code changes, rebuild the provider binary first, then re-run `terraform validate` and `terraform plan`.
### Version metadata in binaries
The provider embeds build metadata (`version`, `commit`, `date`) in the binary.
- Local builds (no `-ldflags`) default to:
- `version=dev`
- `commit=none`
- `built=unknown`
- You can inspect metadata from the binary with either:
- `./terraform-provider-dynu --version`
- `./terraform-provider-dynu version`
Build a stamped binary with standard Go `-ldflags`:
```bash
VERSION=${VERSION:-v0.2.0}
COMMIT=$(git rev-parse --short HEAD)
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
go build -o terraform-provider-dynu \
-ldflags="-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}"
```
Release tag/version mapping:
- Git tag `v0.1.0` -> build with `VERSION=v0.1.0`
- Git tag `v0.2.0` -> build with `VERSION=v0.2.0`
## Copy/paste starter configuration
```hcl
+16 -1
View File
@@ -2,15 +2,30 @@ package main
import (
"context"
"fmt"
"log"
"os"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/dynu/terraform-provider-dynu/internal/provider"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
err := providerserver.Serve(context.Background(), provider.New("dev"), providerserver.ServeOpts{
if len(os.Args) == 2 && (os.Args[1] == "--version" || os.Args[1] == "version") {
fmt.Printf("terraform-provider-dynu version=%s commit=%s built=%s\n", version, commit, date)
return
}
log.Printf("starting terraform-provider-dynu version=%s commit=%s built=%s", version, commit, date)
err := providerserver.Serve(context.Background(), provider.New(version), providerserver.ServeOpts{
Address: "registry.terraform.io/dynu/dynu",
})
if err != nil {