-
Notifications
You must be signed in to change notification settings - Fork 132
/
data_cloud_project_database_m3db_namespace.go
128 lines (116 loc) · 3.84 KB
/
data_cloud_project_database_m3db_namespace.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package ovh
import (
"context"
"fmt"
"log"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceCloudProjectDatabaseM3dbNamespace() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceCloudProjectDatabaseM3dbNamespaceRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("OVH_CLOUD_PROJECT_SERVICE", nil),
},
"cluster_id": {
Type: schema.TypeString,
Description: "Cluster ID",
Required: true,
},
"name": {
Type: schema.TypeString,
Description: "Name of the namespace",
Required: true,
},
//Computed
"resolution": {
Type: schema.TypeString,
Description: "Resolution for an aggregated namespace",
Computed: true,
},
"retention_block_data_expiration_duration": {
Type: schema.TypeString,
Description: "Controls how long we wait before expiring stale data",
Computed: true,
},
"retention_block_size_duration": {
Type: schema.TypeString,
Description: "Controls how long to keep a block in memory before flushing to a fileset on disk",
Computed: true,
},
"retention_buffer_future_duration": {
Type: schema.TypeString,
Description: "Controls how far into the future writes to the namespace will be accepted",
Computed: true,
},
"retention_buffer_past_duration": {
Type: schema.TypeString,
Description: "Controls how far into the past writes to the namespace will be accepted",
Computed: true,
},
"retention_period_duration": {
Type: schema.TypeString,
Description: "Controls the duration of time that M3DB will retain data for the namespace",
Computed: true,
},
"snapshot_enabled": {
Type: schema.TypeBool,
Description: "Defines whether M3DB will create snapshot files for this namespace",
Computed: true,
},
"type": {
Type: schema.TypeString,
Description: "Type of namespace",
Computed: true,
},
"writes_to_commit_log_enabled": {
Type: schema.TypeBool,
Description: "Defines whether M3DB will include writes to this namespace in the commit log",
Computed: true,
},
},
}
}
func dataSourceCloudProjectDatabaseM3dbNamespaceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
clusterId := d.Get("cluster_id").(string)
listEndpoint := fmt.Sprintf("/cloud/project/%s/database/m3db/%s/namespace",
url.PathEscape(serviceName),
url.PathEscape(clusterId),
)
listRes := make([]string, 0)
log.Printf("[DEBUG] Will read namespaces from cluster %s from project %s", clusterId, serviceName)
if err := config.OVHClient.Get(listEndpoint, &listRes); err != nil {
return diag.Errorf("Error calling GET %s:\n\t %q", listEndpoint, err)
}
name := d.Get("name").(string)
for _, id := range listRes {
endpoint := fmt.Sprintf("/cloud/project/%s/database/m3db/%s/namespace/%s",
url.PathEscape(serviceName),
url.PathEscape(clusterId),
url.PathEscape(id),
)
res := &CloudProjectDatabaseM3dbNamespaceResponse{}
log.Printf("[DEBUG] Will read namespace %s from cluster %s from project %s", id, clusterId, serviceName)
if err := config.OVHClient.Get(endpoint, res); err != nil {
return diag.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
}
if res.Name == name {
for k, v := range res.ToMap() {
if k != "id" {
d.Set(k, v)
} else {
d.SetId(fmt.Sprint(v))
}
}
log.Printf("[DEBUG] Read namespace %+v", res)
return nil
}
}
return diag.Errorf("Namespace name %s not found for cluster %s from project %s", name, clusterId, serviceName)
}