-
Notifications
You must be signed in to change notification settings - Fork 132
/
data_cloud_project_user_s3_policy.go
56 lines (47 loc) · 1.58 KB
/
data_cloud_project_user_s3_policy.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
package ovh
import (
"context"
"log"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
func dataCloudProjectUserS3Policy() *schema.Resource {
return &schema.Resource{
ReadContext: dataCloudProjectUserS3PolicyRead,
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",
},
"policy": {
Type: schema.TypeString,
Computed: true,
Description: "The policy document. This is a JSON formatted string.",
},
},
}
}
func dataCloudProjectUserS3PolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
userId := d.Get("user_id").(string)
s3Policy := &CloudProjectUserS3Policy{}
log.Printf("[DEBUG] Will read the S3 Policy for user: %s from project: %s", userId, serviceName)
endpoint := buildUserS3PolicyEndpoint(serviceName, userId)
if err := config.OVHClient.Get(endpoint, s3Policy); err != nil {
return diag.FromErr(helpers.CheckDeleted(d, err, endpoint))
}
d.SetId(buildUserS3PolicyId(serviceName, userId))
d.Set("policy", s3Policy.Policy)
return nil
}