From 375e16f59603a82cf08bc3bf9843d8f57790d9d8 Mon Sep 17 00:00:00 2001 From: Ruben Costa Date: Mon, 18 Nov 2024 09:49:53 +0100 Subject: [PATCH] return nkey seed --- docs/resources/nkey.md | 1 + internal/provider/nkey_resource.go | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/docs/resources/nkey.md b/docs/resources/nkey.md index 22d1ac8..9298efe 100644 --- a/docs/resources/nkey.md +++ b/docs/resources/nkey.md @@ -23,3 +23,4 @@ An nkey is an ed25519 key pair formatted for use with NATS. - `private_key` (String, Sensitive) Private key of the nkey to be given to the client for authentication - `public_key` (String) Public key of the nkey to be given in config to the nats server +- `seed` (String, Sensitive) Seed of the nkey to be given to the client for authentication diff --git a/internal/provider/nkey_resource.go b/internal/provider/nkey_resource.go index 6bf34f4..3cf3059 100644 --- a/internal/provider/nkey_resource.go +++ b/internal/provider/nkey_resource.go @@ -36,6 +36,7 @@ type NkeyModel struct { KeyType types.String `tfsdk:"type"` PublicKey types.String `tfsdk:"public_key"` PrivateKey types.String `tfsdk:"private_key"` + Seed types.String `tfsdk:"seed"` } func (r *Nkey) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { @@ -66,6 +67,11 @@ func (r *Nkey) Schema(ctx context.Context, req resource.SchemaRequest, resp *res MarkdownDescription: "Private key of the nkey to be given to the client for authentication", Sensitive: true, }, + "seed": schema.StringAttribute{ + Computed: true, + MarkdownDescription: "Seed of the nkey to be given to the client for authentication", + Sensitive: true, + }, }, } } @@ -160,9 +166,14 @@ func (m *NkeyModel) generateKeys() (err error) { if err != nil { return err } + seed, err := keys.Seed() + if err != nil { + return err + } m.PublicKey = types.StringValue(pubKey) m.PrivateKey = types.StringValue(string(privKey)) + m.Seed = types.StringValue(string(seed)) return nil }