Skip to content

Commit

Permalink
return nkey seed
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencosta committed Nov 18, 2024
1 parent 81c8090 commit 375e16f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/resources/nkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions internal/provider/nkey_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
},
},
}
}
Expand Down Expand Up @@ -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
}

0 comments on commit 375e16f

Please sign in to comment.