Skip to content

Commit 2037857

Browse files
authored
Merge pull request #33 from arangodb-managed/OAS-3738
OAS-3738 | Add support for setting disk_autosize_settings
2 parents 15aadbd + 44fff7b commit 2037857

File tree

4 files changed

+64
-27
lines changed

4 files changed

+64
-27
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/arangodb-managed/terraform-provider-oasis
22

33
require (
4-
github.com/arangodb-managed/apis v0.71.2
4+
github.com/arangodb-managed/apis v0.72.5
55
github.com/arangodb-managed/log-helper v0.2.0
66
github.com/gogo/protobuf v1.3.0
77
github.com/hashicorp/hcl v1.0.0 // indirect
@@ -19,7 +19,7 @@ go 1.16
1919

2020
replace github.com/Azure/go-autorest => github.com/Azure/go-autorest v14.2.0+incompatible
2121

22-
replace github.com/arangodb/kube-arangodb => github.com/arangodb/kube-arangodb v0.0.0-20210528082542-41972ad9b013
22+
replace github.com/arangodb/kube-arangodb => github.com/arangodb/kube-arangodb v0.0.0-20211215105125-4d01e402c9c9
2323

2424
replace github.com/coreos/go-systemd => github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a
2525

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 h1:MzVXffFU
4545
github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
4646
github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0=
4747
github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk=
48-
github.com/arangodb-managed/apis v0.71.2 h1:I5SAcZzAzzOJG5GvFwXBYG57btSx/YNEDo4IBW33ZJ4=
49-
github.com/arangodb-managed/apis v0.71.2/go.mod h1:dSEV+DTPdZNH06qVqFWA+F0OcaL2ePGEo+odyMaU72Y=
48+
github.com/arangodb-managed/apis v0.72.5 h1:hzE4xZNxSFpO/rhvMxxHz5LPbX4L+qQzWUdqM0TFqNw=
49+
github.com/arangodb-managed/apis v0.72.5/go.mod h1:dSEV+DTPdZNH06qVqFWA+F0OcaL2ePGEo+odyMaU72Y=
5050
github.com/arangodb-managed/log-helper v0.2.0 h1:QK85i0a+mGM++wK625Oe1z4HuXhvaN3vR/Nunwa1qAA=
5151
github.com/arangodb-managed/log-helper v0.2.0/go.mod h1:WJogNCCXWM5OQx/ZYvtRo/1zwm/IpKj+f4QVtM8hNJw=
5252
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=

pkg/resource_deployment.go

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const (
5555
deplConfigurationNodeSizeIdFieldName = "node_size_id"
5656
deplConfigurationNodeCountFieldName = "node_count"
5757
deplConfigurationNodeDiskSizeFieldName = "node_disk_size"
58+
deplConfigurationMaximumNodeDiskSizeFieldName = "maximum_node_disk_size"
5859
deplNotificationConfigurationFieldName = "notification_settings"
5960
deplNotificationConfigurationEmailAddressesFieldName = "email_addresses"
6061
)
@@ -179,6 +180,13 @@ func resourceDeployment() *schema.Resource {
179180
return new == "0"
180181
},
181182
},
183+
deplConfigurationMaximumNodeDiskSizeFieldName: {
184+
Type: schema.TypeInt,
185+
Optional: true,
186+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
187+
return new == ""
188+
},
189+
},
182190
},
183191
},
184192
},
@@ -219,11 +227,11 @@ func resourceDeploymentCreate(d *schema.ResourceData, m interface{}) error {
219227
if v, ok := d.GetOk(deplTAndCAcceptedFieldName); ok {
220228
if !v.(bool) {
221229
client.log.Error().Str("name", deplTAndCAcceptedFieldName).Msg("Field should be set to accept Terms and Conditions")
222-
return fmt.Errorf("Field '%s' should be set to accept Terms and Conditions", deplTAndCAcceptedFieldName)
230+
return fmt.Errorf("field '%s' should be set to accept Terms and Conditions", deplTAndCAcceptedFieldName)
223231
}
224232
} else {
225233
client.log.Error().Str("name", deplTAndCAcceptedFieldName).Msg("Unable to find field, which is required to accept Terms and Conditions")
226-
return fmt.Errorf("Unable to find field %s", deplTAndCAcceptedFieldName)
234+
return fmt.Errorf("unable to find field %s", deplTAndCAcceptedFieldName)
227235
}
228236

229237
datac := data.NewDataServiceClient(client.conn)
@@ -265,7 +273,7 @@ func resourceDeploymentCreate(d *schema.ResourceData, m interface{}) error {
265273

266274
if expandedDepl.Certificates.CaCertificateId == "" {
267275
client.log.Error().Err(err).Str("project-id", expandedDepl.ProjectId).Msg("Unable to find default certificate for project. Please select one manually.")
268-
return fmt.Errorf("Unable to find default certificate for project %s. Please select one manually.", expandedDepl.GetProjectId())
276+
return fmt.Errorf("unable to find default certificate for project %s. Please select one manually", expandedDepl.GetProjectId())
269277
}
270278
}
271279

@@ -277,11 +285,11 @@ func resourceDeploymentCreate(d *schema.ResourceData, m interface{}) error {
277285
})
278286
if err != nil {
279287
client.log.Fatal().Err(err).Msg("Failed to fetch node size list.")
280-
return fmt.Errorf("Failed to fetch node size list for region %s", expandedDepl.RegionId)
288+
return fmt.Errorf("failed to fetch node size list for region %s", expandedDepl.RegionId)
281289
}
282290
if len(list.Items) < 1 {
283291
client.log.Fatal().Msg("No available node sizes found.")
284-
return fmt.Errorf("No available node sizes found for region %s", expandedDepl.RegionId)
292+
return fmt.Errorf("no available node sizes found for region %s", expandedDepl.RegionId)
285293
}
286294
sort.SliceStable(list.Items, func(i, j int) bool {
287295
return list.Items[i].MemorySize < list.Items[j].MemorySize
@@ -341,10 +349,11 @@ type securityFields struct {
341349

342350
// configuration is a convenient wrapper around the configuration schema for easy parsing
343351
type configuration struct {
344-
model string
345-
nodeSizeId string
346-
nodeCount int
347-
nodeDiskSize int
352+
model string
353+
nodeSizeId string
354+
nodeCount int
355+
nodeDiskSize int
356+
maximumNodeDiskSize int
348357
}
349358

350359
// expandDeploymentResource creates an oasis deployment structure out of a terraform schema model.
@@ -399,6 +408,12 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d
399408
return nil, err
400409
}
401410
}
411+
var autoSizeSettings *data.Deployment_DiskAutoSizeSettings
412+
if conf.maximumNodeDiskSize > 0 {
413+
autoSizeSettings = &data.Deployment_DiskAutoSizeSettings{
414+
MaximumNodeDiskSize: int32(conf.maximumNodeDiskSize),
415+
}
416+
}
402417

403418
return &data.Deployment{
404419
Name: name,
@@ -416,6 +431,7 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d
416431
NodeSizeId: conf.nodeSizeId,
417432
},
418433
NotificationSettings: notificationSetting,
434+
DiskAutoSizeSettings: autoSizeSettings,
419435
}, nil
420436
}
421437

@@ -480,6 +496,9 @@ func expandConfiguration(s []interface{}) (conf configuration, err error) {
480496
if i, ok := item[deplConfigurationNodeDiskSizeFieldName]; ok && i.(int) != 0 {
481497
conf.nodeDiskSize = i.(int)
482498
}
499+
if i, ok := item[deplConfigurationMaximumNodeDiskSizeFieldName]; ok && i.(int) != 0 {
500+
conf.maximumNodeDiskSize = i.(int)
501+
}
483502
}
484503
return
485504
}
@@ -583,13 +602,17 @@ func flattenLocationData(depl *data.Deployment) []interface{} {
583602

584603
// flattenConfigurationData takes the configuration part of a deployment and creates a sub map for terraform schema.
585604
func flattenConfigurationData(depl *data.Deployment) []interface{} {
605+
conf := map[string]interface{}{
606+
deplConfigurationModelFieldName: depl.GetModel().GetModel(),
607+
deplConfigurationNodeSizeIdFieldName: depl.GetModel().GetNodeSizeId(),
608+
deplConfigurationNodeDiskSizeFieldName: int(depl.GetModel().GetNodeDiskSize()),
609+
deplConfigurationNodeCountFieldName: int(depl.GetModel().GetNodeCount()),
610+
}
611+
if autoSizeSettings := depl.GetDiskAutoSizeSettings(); autoSizeSettings != nil {
612+
conf[deplConfigurationMaximumNodeDiskSizeFieldName] = int(autoSizeSettings.GetMaximumNodeDiskSize())
613+
}
586614
return []interface{}{
587-
map[string]interface{}{
588-
deplConfigurationModelFieldName: depl.GetModel().GetModel(),
589-
deplConfigurationNodeSizeIdFieldName: depl.GetModel().GetNodeSizeId(),
590-
deplConfigurationNodeDiskSizeFieldName: int(depl.GetModel().GetNodeDiskSize()),
591-
deplConfigurationNodeCountFieldName: int(depl.GetModel().GetNodeCount()),
592-
},
615+
conf,
593616
}
594617
}
595618

@@ -662,6 +685,12 @@ func resourceDeploymentUpdate(d *schema.ResourceData, m interface{}) error {
662685
if conf.nodeCount != 0 {
663686
depl.Model.NodeCount = int32(conf.nodeCount)
664687
}
688+
if conf.maximumNodeDiskSize != 0 {
689+
if depl.DiskAutoSizeSettings == nil {
690+
depl.DiskAutoSizeSettings = &data.Deployment_DiskAutoSizeSettings{}
691+
}
692+
depl.DiskAutoSizeSettings.MaximumNodeDiskSize = int32(conf.maximumNodeDiskSize)
693+
}
665694
}
666695
// if we have change on NotificationSettings apply it
667696
if d.HasChange(deplNotificationConfigurationFieldName) {

pkg/resource_deployment_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func TestFlattenDeploymentResource(t *testing.T) {
8484
NodeCount: 3,
8585
NodeDiskSize: 32,
8686
},
87+
DiskAutoSizeSettings: &data.Deployment_DiskAutoSizeSettings{
88+
MaximumNodeDiskSize: 40,
89+
},
8790
}
8891
flattened := flattenDeployment(depl)
8992
expected := map[string]interface{}{
@@ -109,10 +112,11 @@ func TestFlattenDeploymentResource(t *testing.T) {
109112
},
110113
deplConfigurationFieldName: []interface{}{
111114
map[string]interface{}{
112-
deplConfigurationModelFieldName: "oneshard",
113-
deplConfigurationNodeSizeIdFieldName: "a8",
114-
deplConfigurationNodeCountFieldName: 3,
115-
deplConfigurationNodeDiskSizeFieldName: 32,
115+
deplConfigurationModelFieldName: "oneshard",
116+
deplConfigurationNodeSizeIdFieldName: "a8",
117+
deplConfigurationNodeCountFieldName: 3,
118+
deplConfigurationNodeDiskSizeFieldName: 32,
119+
deplConfigurationMaximumNodeDiskSizeFieldName: 40,
116120
},
117121
},
118122
}
@@ -251,6 +255,9 @@ func TestExpandingDeploymentResource(t *testing.T) {
251255
NodeCount: 3,
252256
NodeDiskSize: 32,
253257
},
258+
DiskAutoSizeSettings: &data.Deployment_DiskAutoSizeSettings{
259+
MaximumNodeDiskSize: 40,
260+
},
254261
}
255262
raw := map[string]interface{}{
256263
deplProjectFieldName: "123456789",
@@ -275,10 +282,11 @@ func TestExpandingDeploymentResource(t *testing.T) {
275282
},
276283
deplConfigurationFieldName: []interface{}{
277284
map[string]interface{}{
278-
deplConfigurationModelFieldName: "oneshard",
279-
deplConfigurationNodeSizeIdFieldName: "a8",
280-
deplConfigurationNodeCountFieldName: 3,
281-
deplConfigurationNodeDiskSizeFieldName: 32,
285+
deplConfigurationModelFieldName: "oneshard",
286+
deplConfigurationNodeSizeIdFieldName: "a8",
287+
deplConfigurationNodeCountFieldName: 3,
288+
deplConfigurationNodeDiskSizeFieldName: 32,
289+
deplConfigurationMaximumNodeDiskSizeFieldName: 40,
282290
},
283291
},
284292
}

0 commit comments

Comments
 (0)