Skip to content

Commit 916747f

Browse files
committed
feat: add support for credential SSH key
1 parent 23105b9 commit 916747f

File tree

13 files changed

+623
-5
lines changed

13 files changed

+623
-5
lines changed

docs/data-sources/entry_credential_api_key.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A DVLS API Key Credential Entry
1313
## Example Usage
1414

1515
```terraform
16-
data "dvls_entry_credential_api_Key" "example" {
16+
data "dvls_entry_credential_api_key" "example" {
1717
id = "00000000-0000-0000-0000-000000000000"
1818
vault_id = "00000000-0000-0000-0000-000000000000"
1919
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "dvls_entry_credential_ssh_key Data Source - terraform-provider-dvls"
4+
subcategory: ""
5+
description: |-
6+
A DVLS SSH Key Credential Entry
7+
---
8+
9+
# dvls_entry_credential_ssh_key (Data Source)
10+
11+
A DVLS SSH Key Credential Entry
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "dvls_entry_credential_ssh_key" "example" {
17+
id = "00000000-0000-0000-0000-000000000000"
18+
vault_id = "00000000-0000-0000-0000-000000000000"
19+
}
20+
```
21+
22+
<!-- schema generated by tfplugindocs -->
23+
## Schema
24+
25+
### Required
26+
27+
- `id` (String) The ID of the entry.
28+
- `vault_id` (String) The ID of the vault.
29+
30+
### Read-Only
31+
32+
- `description` (String) The description of the entry.
33+
- `folder` (String) The folder path of the entry.
34+
- `name` (String) The name of the entry.
35+
- `passphrase` (String, Sensitive) The entry credential passphrase.
36+
- `password` (String, Sensitive) The entry credential password.
37+
- `private_key_data` (String, Sensitive) The entry credential private key data.
38+
- `public_key` (String, Sensitive) The entry credential public key data.
39+
- `tags` (List of String) A list of tags added to the entry.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "dvls_entry_credential_ssh_key Resource - terraform-provider-dvls"
4+
subcategory: ""
5+
description: |-
6+
A DVLS SSH Key Credential Entry
7+
---
8+
9+
# dvls_entry_credential_ssh_key (Resource)
10+
11+
A DVLS SSH Key Credential Entry
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "dvls_entry_credential_ssh_key" "example" {
17+
vault_id = "00000000-0000-0000-0000-000000000000"
18+
name = "foo"
19+
folder = "foo\\bar"
20+
description = "bar"
21+
tags = ["foo"]
22+
23+
password = "foo"
24+
passphrase = "bar"
25+
private_key_data = "foo"
26+
public_key = "bar"
27+
}
28+
```
29+
30+
<!-- schema generated by tfplugindocs -->
31+
## Schema
32+
33+
### Required
34+
35+
- `name` (String) The name of the entry.
36+
- `vault_id` (String) The ID of the vault.
37+
38+
### Optional
39+
40+
- `description` (String) The description of the entry.
41+
- `folder` (String) The folder path where the entry is created.
42+
- `passphrase` (String, Sensitive) The entry credential passphrase.
43+
- `password` (String, Sensitive) The entry credential password.
44+
- `private_key_data` (String, Sensitive) The entry credential private key.
45+
- `public_key` (String, Sensitive) The entry credential public key.
46+
- `tags` (List of String) A list of tags to add to the entry.
47+
48+
### Read-Only
49+
50+
- `id` (String) The ID of the entry. This is set by the provider after creation.
51+
52+
## Import
53+
54+
Import is supported using the following syntax:
55+
56+
```shell
57+
# This resource can be imported using `<vault_id>/<entry_id>` format, e.g.
58+
terraform import dvls_entry_credential_ssh_key.example 00000000-0000-0000-0000-000000000000/00000000-0000-0000-0000-000000000000
59+
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
data "dvls_entry_credential_api_Key" "example" {
1+
data "dvls_entry_credential_api_key" "example" {
22
id = "00000000-0000-0000-0000-000000000000"
33
vault_id = "00000000-0000-0000-0000-000000000000"
44
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data "dvls_entry_credential_ssh_key" "example" {
2+
id = "00000000-0000-0000-0000-000000000000"
3+
vault_id = "00000000-0000-0000-0000-000000000000"
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This resource can be imported using `<vault_id>/<entry_id>` format, e.g.
2+
terraform import dvls_entry_credential_ssh_key.example 00000000-0000-0000-0000-000000000000/00000000-0000-0000-0000-000000000000
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "dvls_entry_credential_ssh_key" "example" {
2+
vault_id = "00000000-0000-0000-0000-000000000000"
3+
name = "foo"
4+
folder = "foo\\bar"
5+
description = "bar"
6+
tags = ["foo"]
7+
8+
password = "foo"
9+
passphrase = "bar"
10+
private_key_data = "foo"
11+
public_key = "bar"
12+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23.0
55
toolchain go1.24.3
66

77
require (
8-
github.com/Devolutions/go-dvls v0.12.1
8+
github.com/Devolutions/go-dvls v0.12.2
99
github.com/google/uuid v1.6.0
1010
github.com/hashicorp/terraform-plugin-docs v0.21.0
1111
github.com/hashicorp/terraform-plugin-framework v1.15.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
22
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
33
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
44
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
5-
github.com/Devolutions/go-dvls v0.12.1 h1:wrcI5tJ4+ZjpX0/0tnu2ENqgCzYPq+ZsIxLyAqLtJHc=
6-
github.com/Devolutions/go-dvls v0.12.1/go.mod h1:4O3lb/RK1P1cDwU5auVi7CM4gRER7EuwyLwMVuEZjgg=
5+
github.com/Devolutions/go-dvls v0.12.2 h1:7qptA5gw8JVtEJuTBmfDHOFfkGY6XMRobvg6InIEa+4=
6+
github.com/Devolutions/go-dvls v0.12.2/go.mod h1:4O3lb/RK1P1cDwU5auVi7CM4gRER7EuwyLwMVuEZjgg=
77
github.com/Kunde21/markdownfmt/v3 v3.1.0 h1:KiZu9LKs+wFFBQKhrZJrFZwtLnCCWJahL+S+E/3VnM0=
88
github.com/Kunde21/markdownfmt/v3 v3.1.0/go.mod h1:tPXN1RTyOzJwhfHoon9wUr4HGYmWgVxSQN6VBJDkrVc=
99
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package provider
2+
3+
import (
4+
"github.com/Devolutions/go-dvls"
5+
"github.com/hashicorp/terraform-plugin-framework/types"
6+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
7+
)
8+
9+
func newEntryCredentialSSHKeyFromResourceModel(data *EntryCredentialSSHKeyResourceModel) dvls.Entry {
10+
var tags []string
11+
12+
for _, v := range data.Tags {
13+
tags = append(tags, v.ValueString())
14+
}
15+
16+
entryCredentialSSHKey := dvls.Entry{
17+
Id: data.Id.ValueString(),
18+
VaultId: data.VaultId.ValueString(),
19+
Name: data.Name.ValueString(),
20+
Path: data.Folder.ValueString(),
21+
Type: dvls.EntryCredentialType,
22+
SubType: dvls.EntryCredentialSubTypePrivateKey,
23+
Description: data.Description.ValueString(),
24+
Tags: tags,
25+
Data: dvls.EntryCredentialPrivateKeyData{
26+
OverridePassword: data.Password.ValueString(),
27+
Passphrase: data.Passphrase.ValueString(),
28+
PrivateKey: data.PrivateKeyData.ValueString(),
29+
PublicKey: data.PublicKey.ValueString(),
30+
},
31+
}
32+
33+
return entryCredentialSSHKey
34+
}
35+
36+
func setEntryCredentialSSHKeyResourceModel(entryCredentialSSHKey dvls.Entry, data *EntryCredentialSSHKeyResourceModel) {
37+
var model EntryCredentialSSHKeyResourceModel
38+
39+
// VALIDATE IF THE ENTRY IS THE CORRECT SUBTYPE
40+
41+
model.Id = basetypes.NewStringValue(entryCredentialSSHKey.Id)
42+
model.VaultId = basetypes.NewStringValue(entryCredentialSSHKey.VaultId)
43+
model.Name = basetypes.NewStringValue(entryCredentialSSHKey.Name)
44+
45+
if entryCredentialSSHKey.Path != "" {
46+
model.Folder = basetypes.NewStringValue(entryCredentialSSHKey.Path)
47+
}
48+
49+
if entryCredentialSSHKey.Description != "" {
50+
model.Description = basetypes.NewStringValue(entryCredentialSSHKey.Description)
51+
}
52+
53+
if entryCredentialSSHKey.Tags != nil {
54+
var tagsBase []types.String
55+
56+
for _, v := range entryCredentialSSHKey.Tags {
57+
tagsBase = append(tagsBase, basetypes.NewStringValue(v))
58+
}
59+
60+
model.Tags = tagsBase
61+
}
62+
63+
if entryCredentialSSHKey.Data != nil {
64+
data, ok := entryCredentialSSHKey.GetCredentialPrivateKeyData()
65+
if ok {
66+
if data.OverridePassword != "" {
67+
model.Password = basetypes.NewStringValue(data.OverridePassword)
68+
}
69+
70+
if data.Passphrase != "" {
71+
model.Passphrase = basetypes.NewStringValue(data.Passphrase)
72+
}
73+
74+
if data.PrivateKey != "" {
75+
model.PrivateKeyData = basetypes.NewStringValue(data.PrivateKey)
76+
}
77+
78+
if data.PublicKey != "" {
79+
model.PublicKey = basetypes.NewStringValue(data.PublicKey)
80+
}
81+
}
82+
}
83+
84+
*data = model
85+
}
86+
87+
func setEntryCredentialSSHKeyDataModel(entryCredentialSSHKey dvls.Entry, data *EntryCredentialSSHKeyDataSourceModel) {
88+
var model EntryCredentialSSHKeyDataSourceModel
89+
90+
model.Id = basetypes.NewStringValue(entryCredentialSSHKey.Id)
91+
model.VaultId = basetypes.NewStringValue(entryCredentialSSHKey.VaultId)
92+
model.Name = basetypes.NewStringValue(entryCredentialSSHKey.Name)
93+
94+
if entryCredentialSSHKey.Path != "" {
95+
model.Folder = basetypes.NewStringValue(entryCredentialSSHKey.Path)
96+
}
97+
98+
if entryCredentialSSHKey.Description != "" {
99+
model.Description = basetypes.NewStringValue(entryCredentialSSHKey.Description)
100+
}
101+
102+
if entryCredentialSSHKey.Tags != nil {
103+
var tagsBase []types.String
104+
105+
for _, v := range entryCredentialSSHKey.Tags {
106+
tagsBase = append(tagsBase, basetypes.NewStringValue(v))
107+
}
108+
109+
model.Tags = tagsBase
110+
}
111+
112+
if entryCredentialSSHKey.Data != nil {
113+
data, ok := entryCredentialSSHKey.GetCredentialPrivateKeyData()
114+
if ok {
115+
if data.OverridePassword != "" {
116+
model.Password = basetypes.NewStringValue(data.OverridePassword)
117+
}
118+
119+
if data.Passphrase != "" {
120+
model.Passphrase = basetypes.NewStringValue(data.Passphrase)
121+
}
122+
123+
if data.PrivateKey != "" {
124+
model.PrivateKeyData = basetypes.NewStringValue(data.PrivateKey)
125+
}
126+
127+
if data.PublicKey != "" {
128+
model.PublicKey = basetypes.NewStringValue(data.PublicKey)
129+
}
130+
}
131+
}
132+
133+
*data = model
134+
}

0 commit comments

Comments
 (0)