@@ -55,6 +55,8 @@ func resourceCloudProjectDatabaseM3dbNamespace() *schema.Resource {
55
55
Required : true ,
56
56
DiffSuppressFunc : DiffDurationRfc3339 ,
57
57
},
58
+
59
+ // Optional
58
60
"retention_block_data_expiration_duration" : {
59
61
Type : schema .TypeString ,
60
62
Description : "Controls how long we wait before expiring stale data" ,
@@ -73,30 +75,34 @@ func resourceCloudProjectDatabaseM3dbNamespace() *schema.Resource {
73
75
Optional : true ,
74
76
DiffSuppressFunc : DiffDurationRfc3339 ,
75
77
},
78
+
79
+ // Optional/Computed
80
+ "retention_block_size_duration" : {
81
+ Type : schema .TypeString ,
82
+ Description : "Controls how long to keep a block in memory before flushing to a fileset on disk" ,
83
+ ForceNew : true ,
84
+ Optional : true ,
85
+ Computed : true ,
86
+ DiffSuppressFunc : DiffDurationRfc3339 ,
87
+ },
76
88
"retention_period_duration" : {
77
89
Type : schema .TypeString ,
78
90
Description : "Controls the duration of time that M3DB will retain data for the namespace" ,
79
- Required : true ,
91
+ Optional : true ,
92
+ Computed : true ,
80
93
DiffSuppressFunc : DiffDurationRfc3339 ,
81
94
},
82
95
"snapshot_enabled" : {
83
96
Type : schema .TypeBool ,
84
97
Description : "Defines whether M3db will create snapshot files for this namespace" ,
85
98
Optional : true ,
99
+ Computed : true ,
86
100
},
87
101
"writes_to_commit_log_enabled" : {
88
102
Type : schema .TypeBool ,
89
103
Description : "Defines whether M3db will include writes to this namespace in the commit log" ,
90
104
Optional : true ,
91
- },
92
-
93
- //Optional/Computed
94
- "retention_block_size_duration" : {
95
- Type : schema .TypeString ,
96
- Description : "Controls how long to keep a block in memory before flushing to a fileset on disk" ,
97
- Optional : true ,
98
- Computed : true ,
99
- DiffSuppressFunc : DiffDurationRfc3339 ,
105
+ Computed : true ,
100
106
},
101
107
102
108
// Computed
@@ -110,52 +116,83 @@ func resourceCloudProjectDatabaseM3dbNamespace() *schema.Resource {
110
116
}
111
117
112
118
func resourceCloudProjectDatabaseM3dbNamespaceImportState (d * schema.ResourceData , meta interface {}) ([]* schema.ResourceData , error ) {
113
- givenId := d .Id ()
119
+ givenID := d .Id ()
114
120
n := 3
115
- splitId := strings .SplitN (givenId , "/" , n )
116
- if len (splitId ) != n {
121
+ splitID := strings .SplitN (givenID , "/" , n )
122
+ if len (splitID ) != n {
117
123
return nil , fmt .Errorf ("import Id is not service_name/cluster_id/id formatted" )
118
124
}
119
- serviceName := splitId [0 ]
120
- clusterId := splitId [1 ]
121
- id := splitId [2 ]
125
+ serviceName := splitID [0 ]
126
+ clusterID := splitID [1 ]
127
+ id := splitID [2 ]
122
128
d .SetId (id )
123
- d .Set ("cluster_id" , clusterId )
129
+ d .Set ("cluster_id" , clusterID )
124
130
d .Set ("service_name" , serviceName )
125
131
126
132
results := make ([]* schema.ResourceData , 1 )
127
133
results [0 ] = d
128
134
return results , nil
129
135
}
130
136
137
+ func m3dbNamespaceToMap (d * schema.ResourceData ) map [string ]interface {} {
138
+ obj := make (map [string ]interface {})
139
+ obj ["resolution" ] = d .Get ("resolution" )
140
+ obj ["retention_block_data_expiration_duration" ] = d .Get ("retention_block_data_expiration_duration" )
141
+ obj ["retention_block_size_duration" ] = d .Get ("retention_block_size_duration" )
142
+ obj ["retention_buffer_future_duration" ] = d .Get ("retention_buffer_future_duration" )
143
+ obj ["retention_buffer_past_duration" ] = d .Get ("retention_buffer_past_duration" )
144
+ obj ["retention_period_duration" ] = d .Get ("retention_period_duration" )
145
+ obj ["snapshot_enabled" ] = d .Get ("snapshot_enabled" )
146
+ obj ["type" ] = d .Get ("type" )
147
+ obj ["writes_to_commit_log_enabled" ] = d .Get ("writes_to_commit_log_enabled" )
148
+
149
+ return obj
150
+ }
151
+
131
152
func resourceCloudProjectDatabaseM3dbNamespaceCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
153
+ name := d .Get ("name" ).(string )
154
+ if name == "default" {
155
+ obj := m3dbNamespaceToMap (d )
156
+
157
+ diags := dataSourceCloudProjectDatabaseM3dbNamespaceRead (ctx , d , meta )
158
+ if diags .HasError () {
159
+ return diags
160
+ }
161
+
162
+ for k , v := range obj {
163
+ d .Set (k , v )
164
+ }
165
+
166
+ return resourceCloudProjectDatabaseM3dbNamespaceUpdate (ctx , d , meta )
167
+ }
168
+
132
169
config := meta .(* Config )
133
170
serviceName := d .Get ("service_name" ).(string )
134
- clusterId := d .Get ("cluster_id" ).(string )
171
+ clusterID := d .Get ("cluster_id" ).(string )
135
172
136
173
endpoint := fmt .Sprintf ("/cloud/project/%s/database/m3db/%s/namespace" ,
137
174
url .PathEscape (serviceName ),
138
- url .PathEscape (clusterId ),
175
+ url .PathEscape (clusterID ),
139
176
)
140
177
141
178
// Should read one time to
142
179
listRes := make ([]string , 0 )
143
- log .Printf ("[DEBUG] Will read namespaces from cluster %s from project %s" , clusterId , serviceName )
180
+ log .Printf ("[DEBUG] Will read namespaces from cluster %s from project %s" , clusterID , serviceName )
144
181
if err := config .OVHClient .GetWithContext (ctx , endpoint , & listRes ); err != nil {
145
182
return diag .Errorf ("Error calling GET %s:\n \t %q" , endpoint , err )
146
183
}
147
184
148
185
params := (& CloudProjectDatabaseM3dbNamespaceCreateOpts {}).FromResource (d )
149
186
res := & CloudProjectDatabaseM3dbNamespaceResponse {}
150
187
151
- log .Printf ("[DEBUG] Will create namespace: %+v for cluster %s from project %s" , params , clusterId , serviceName )
188
+ log .Printf ("[DEBUG] Will create namespace: %+v for cluster %s from project %s" , params , clusterID , serviceName )
152
189
err := config .OVHClient .PostWithContext (ctx , endpoint , params , res )
153
190
if err != nil {
154
191
return diag .Errorf ("calling Post %s with params %+v:\n \t %q" , endpoint , params , err )
155
192
}
156
193
157
194
log .Printf ("[DEBUG] Waiting for namespace %s to be READY" , res .Id )
158
- err = waitForCloudProjectDatabaseM3dbNamespaceReady (ctx , config .OVHClient , serviceName , clusterId , res .Id , d .Timeout (schema .TimeoutCreate ))
195
+ err = waitForCloudProjectDatabaseM3dbNamespaceReady (ctx , config .OVHClient , serviceName , clusterID , res .Id , d .Timeout (schema .TimeoutCreate ))
159
196
if err != nil {
160
197
return diag .Errorf ("timeout while waiting namespace %s to be READY: %s" , res .Id , err .Error ())
161
198
}
@@ -169,17 +206,17 @@ func resourceCloudProjectDatabaseM3dbNamespaceCreate(ctx context.Context, d *sch
169
206
func resourceCloudProjectDatabaseM3dbNamespaceRead (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
170
207
config := meta .(* Config )
171
208
serviceName := d .Get ("service_name" ).(string )
172
- clusterId := d .Get ("cluster_id" ).(string )
209
+ clusterID := d .Get ("cluster_id" ).(string )
173
210
id := d .Id ()
174
211
175
212
endpoint := fmt .Sprintf ("/cloud/project/%s/database/m3db/%s/namespace/%s" ,
176
213
url .PathEscape (serviceName ),
177
- url .PathEscape (clusterId ),
214
+ url .PathEscape (clusterID ),
178
215
url .PathEscape (id ),
179
216
)
180
217
res := & CloudProjectDatabaseM3dbNamespaceResponse {}
181
218
182
- log .Printf ("[DEBUG] Will read namespace %s from cluster %s from project %s" , id , clusterId , serviceName )
219
+ log .Printf ("[DEBUG] Will read namespace %s from cluster %s from project %s" , id , clusterID , serviceName )
183
220
if err := config .OVHClient .GetWithContext (ctx , endpoint , res ); err != nil {
184
221
return diag .FromErr (helpers .CheckDeleted (d , err , endpoint ))
185
222
}
@@ -198,24 +235,24 @@ func resourceCloudProjectDatabaseM3dbNamespaceRead(ctx context.Context, d *schem
198
235
func resourceCloudProjectDatabaseM3dbNamespaceUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
199
236
config := meta .(* Config )
200
237
serviceName := d .Get ("service_name" ).(string )
201
- clusterId := d .Get ("cluster_id" ).(string )
238
+ clusterID := d .Get ("cluster_id" ).(string )
202
239
id := d .Id ()
203
240
204
241
endpoint := fmt .Sprintf ("/cloud/project/%s/database/m3db/%s/namespace/%s" ,
205
242
url .PathEscape (serviceName ),
206
- url .PathEscape (clusterId ),
243
+ url .PathEscape (clusterID ),
207
244
url .PathEscape (id ),
208
245
)
209
246
params := (& CloudProjectDatabaseM3dbNamespaceUpdateOpts {}).FromResource (d )
210
247
211
- log .Printf ("[DEBUG] Will update namespace: %+v from cluster %s from project %s" , params , clusterId , serviceName )
248
+ log .Printf ("[DEBUG] Will update namespace: %+v from cluster %s from project %s" , params , clusterID , serviceName )
212
249
err := config .OVHClient .PutWithContext (ctx , endpoint , params , nil )
213
250
if err != nil {
214
251
return diag .Errorf ("calling Put %s with params %+v:\n \t %q" , endpoint , params , err )
215
252
}
216
253
217
254
log .Printf ("[DEBUG] Waiting for namespace %s to be READY" , id )
218
- err = waitForCloudProjectDatabaseM3dbNamespaceReady (ctx , config .OVHClient , serviceName , clusterId , id , d .Timeout (schema .TimeoutUpdate ))
255
+ err = waitForCloudProjectDatabaseM3dbNamespaceReady (ctx , config .OVHClient , serviceName , clusterID , id , d .Timeout (schema .TimeoutUpdate ))
219
256
if err != nil {
220
257
return diag .Errorf ("timeout while waiting namespace %s to be READY: %s" , id , err .Error ())
221
258
}
@@ -225,25 +262,31 @@ func resourceCloudProjectDatabaseM3dbNamespaceUpdate(ctx context.Context, d *sch
225
262
}
226
263
227
264
func resourceCloudProjectDatabaseM3dbNamespaceDelete (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
265
+ name := d .Get ("name" ).(string )
266
+ if name == "default" {
267
+ d .SetId ("" )
268
+ return nil
269
+ }
270
+
228
271
config := meta .(* Config )
229
272
serviceName := d .Get ("service_name" ).(string )
230
- clusterId := d .Get ("cluster_id" ).(string )
273
+ clusterID := d .Get ("cluster_id" ).(string )
231
274
id := d .Id ()
232
275
233
276
endpoint := fmt .Sprintf ("/cloud/project/%s/database/m3db/%s/namespace/%s" ,
234
277
url .PathEscape (serviceName ),
235
- url .PathEscape (clusterId ),
278
+ url .PathEscape (clusterID ),
236
279
url .PathEscape (id ),
237
280
)
238
281
239
- log .Printf ("[DEBUG] Will delete namespace %s from cluster %s from project %s" , id , clusterId , serviceName )
282
+ log .Printf ("[DEBUG] Will delete namespace %s from cluster %s from project %s" , id , clusterID , serviceName )
240
283
err := config .OVHClient .DeleteWithContext (ctx , endpoint , nil )
241
284
if err != nil {
242
285
return diag .FromErr (helpers .CheckDeleted (d , err , endpoint ))
243
286
}
244
287
245
288
log .Printf ("[DEBUG] Waiting for namespace %s to be DELETED" , id )
246
- err = waitForCloudProjectDatabaseM3dbNamespaceDeleted (ctx , config .OVHClient , serviceName , clusterId , id , d .Timeout (schema .TimeoutDelete ))
289
+ err = waitForCloudProjectDatabaseM3dbNamespaceDeleted (ctx , config .OVHClient , serviceName , clusterID , id , d .Timeout (schema .TimeoutDelete ))
247
290
if err != nil {
248
291
return diag .Errorf ("timeout while waiting namespace %s to be DELETED: %s" , id , err .Error ())
249
292
}
0 commit comments