78ba0011f9
Configure the arrstack Vault secrets engine (backend config + roles) from terraform-vault, matching the schema declared in terraform-vault #127. - Add terraform-plugin-framework provider (local name arrstack) authenticating to Vault/OpenBao via address + token (VAULT_ADDR/VAULT_TOKEN fallback). - Add arrstack_secret_backend resource: mounts the engine and writes <mount>/config. - Add arrstack_secret_backend_role resource: manages <mount>/roles/<name>. - Add Vault client, conversions, unit tests, Makefile, woodpecker CI + tag release to artifactapi terraform-unkin, examples, and README.
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
)
|
|
|
|
// toStringSlice coerces the list shapes Vault returns (a JSON array decodes to
|
|
// []interface{}) into a []string. A nil or non-list value yields an empty slice.
|
|
func toStringSlice(v interface{}) []string {
|
|
switch xs := v.(type) {
|
|
case []string:
|
|
return xs
|
|
case []interface{}:
|
|
out := make([]string, 0, len(xs))
|
|
for _, x := range xs {
|
|
if s, ok := x.(string); ok {
|
|
out = append(out, s)
|
|
}
|
|
}
|
|
return out
|
|
default:
|
|
return []string{}
|
|
}
|
|
}
|
|
|
|
// toInt64 coerces the numeric shapes Vault returns (json.Number, float64, int)
|
|
// into an int64.
|
|
func toInt64(v interface{}) (int64, bool) {
|
|
switch n := v.(type) {
|
|
case json.Number:
|
|
i, err := n.Int64()
|
|
if err != nil {
|
|
f, ferr := n.Float64()
|
|
if ferr != nil {
|
|
return 0, false
|
|
}
|
|
return int64(f), true
|
|
}
|
|
return i, true
|
|
case float64:
|
|
return int64(n), true
|
|
case int64:
|
|
return n, true
|
|
case int:
|
|
return int64(n), true
|
|
default:
|
|
return 0, false
|
|
}
|
|
}
|
|
|
|
// splitBackendName splits an import ID of the form "<backend>/<marker>/<name>"
|
|
// (e.g. "arrstack/roles/all") into its backend and name parts.
|
|
func splitBackendName(id, marker string) (backend, name string, ok bool) {
|
|
sep := "/" + marker + "/"
|
|
idx := strings.LastIndex(id, sep)
|
|
if idx <= 0 {
|
|
return "", "", false
|
|
}
|
|
backend = id[:idx]
|
|
name = id[idx+len(sep):]
|
|
if backend == "" || name == "" {
|
|
return "", "", false
|
|
}
|
|
return backend, name, true
|
|
}
|