-
Notifications
You must be signed in to change notification settings - Fork 133
/
data_cloud_project_user_s3_credential.go
70 lines (60 loc) · 1.8 KB
/
data_cloud_project_user_s3_credential.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ovh
import (
"fmt"
"log"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
func dataCloudProjectUserS3Credential() *schema.Resource {
return &schema.Resource{
Read: dataCloudProjectUserS3CredentialRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
Description: "Service name of the resource representing the ID of the cloud project.",
},
"user_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The user ID",
},
"access_key_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The access key",
},
//Computed
"secret_access_key": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
}
}
func dataCloudProjectUserS3CredentialRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
userID := d.Get("user_id").(string)
accessKey := d.Get("access_key_id").(string)
log.Printf("[DEBUG] Will read public cloud secret access key for access key %s user %s on project: %s", accessKey, userID, serviceName)
endpoint := fmt.Sprintf(
"/cloud/project/%s/user/%s/s3Credentials/%s/secret",
url.PathEscape(serviceName),
url.PathEscape(userID),
url.PathEscape(accessKey),
)
s3Credential := &CloudProjectUserS3Secret{}
if err := config.OVHClient.Post(endpoint, nil, &s3Credential); err != nil {
return helpers.CheckDeleted(d, err, endpoint)
}
d.SetId(serviceName)
d.Set("secret_access_key", s3Credential.Secret)
return nil
}