Skip to content

Commit ad7f4a4

Browse files
authored
chore(account): refactor data ressource workflow (#680)
1 parent 95d35a6 commit ad7f4a4

File tree

2 files changed

+499
-64
lines changed

2 files changed

+499
-64
lines changed

scaleway/data_source_account_ssh_key.go

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,25 @@ import (
1111
)
1212

1313
func dataSourceScalewayAccountSSHKey() *schema.Resource {
14+
dsSchema := datasourceSchemaFromResourceSchema(resourceScalewayAccountSSKKey().Schema)
15+
addOptionalFieldsToSchema(dsSchema, "name")
16+
17+
dsSchema["name"].ConflictsWith = []string{"ssh_key_id"}
18+
dsSchema["ssh_key_id"] = &schema.Schema{
19+
Type: schema.TypeString,
20+
Optional: true,
21+
Description: "The ID of the SSH key",
22+
ValidateFunc: validationUUID(),
23+
}
24+
1425
return &schema.Resource{
1526
ReadContext: dataSourceScalewayAccountSSHKeyRead,
16-
Schema: map[string]*schema.Schema{
17-
"name": {
18-
Type: schema.TypeString,
19-
Optional: true,
20-
Computed: true,
21-
Description: "The name of the SSH key",
22-
},
23-
"ssh_key_id": {
24-
Type: schema.TypeString,
25-
Optional: true,
26-
Computed: true,
27-
Description: "The ID of the SSH key",
28-
ValidateFunc: validationUUIDorUUIDWithLocality(),
29-
},
30-
"public_key": {
31-
Type: schema.TypeString,
32-
Computed: true,
33-
Description: "The public SSH key",
34-
},
35-
"organization_id": organizationIDSchema(),
36-
"project_id": projectIDSchema(),
37-
},
27+
Schema: dsSchema,
3828
}
3929
}
4030

41-
func dataSourceScalewayAccountSSHKeyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
42-
accountAPI := accountAPI(m)
31+
func dataSourceScalewayAccountSSHKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
32+
accountAPI := accountAPI(meta)
4333

4434
var sshKey *account.SSHKey
4535
sshKeyID, ok := d.GetOk("ssh_key_id")
@@ -67,11 +57,7 @@ func dataSourceScalewayAccountSSHKeyRead(ctx context.Context, d *schema.Resource
6757
}
6858

6959
d.SetId(sshKey.ID)
70-
_ = d.Set("name", sshKey.Name)
7160
_ = d.Set("ssh_key_id", sshKey.ID)
72-
_ = d.Set("public_key", sshKey.PublicKey)
73-
_ = d.Set("organization_id", sshKey.OrganizationID)
74-
_ = d.Set("project_id", sshKey.ProjectID)
7561

76-
return nil
62+
return resourceScalewayAccountSSHKeyRead(ctx, d, meta)
7763
}

0 commit comments

Comments
 (0)