Skip to content

Commit 4442d8a

Browse files
author
Arthur Amstutz
committed
fix: Add missing autoscaling params to resource ovh_dbaas_logs_input
1 parent 3351440 commit 4442d8a

4 files changed

+185
-51
lines changed

Diff for: ovh/resource_dbaas_logs_input.go

+29-8
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,26 @@ func resourceDbaasLogsInputSchema() map[string]*schema.Schema {
153153
Computed: true,
154154
},
155155
"nb_instance": {
156+
Type: schema.TypeInt,
157+
Description: "Number of instance running",
158+
Optional: true,
159+
ConflictsWith: []string{"autoscale"},
160+
},
161+
"autoscale": {
162+
Type: schema.TypeBool,
163+
Description: "Whether the workload is auto-scaled",
164+
Optional: true,
165+
ConflictsWith: []string{"nb_instance"},
166+
},
167+
"min_scale_instance": {
156168
Type: schema.TypeInt,
157-
Description: "Number of instance running",
169+
Description: "Minimum number of instances in auto-scaled mode",
170+
Optional: true,
171+
},
172+
"max_scale_instance": {
173+
Type: schema.TypeInt,
174+
Description: "Maximum number of instances in auto-scaled mode",
158175
Optional: true,
159-
Computed: true,
160176
},
161177

162178
// computed
@@ -201,6 +217,11 @@ func resourceDbaasLogsInputSchema() map[string]*schema.Schema {
201217
Description: "Input last update",
202218
Computed: true,
203219
},
220+
"current_nb_instance": {
221+
Type: schema.TypeInt,
222+
Description: "Number of instance running (returned by the API)",
223+
Computed: true,
224+
},
204225
}
205226

206227
return schema
@@ -210,7 +231,7 @@ func resourceDbaasLogsInputImportState(d *schema.ResourceData, meta interface{})
210231
givenID := d.Id()
211232
splitID := strings.SplitN(givenID, "/", 2)
212233
if len(splitID) != 2 {
213-
return nil, fmt.Errorf("Import Id is not service_name/id formatted")
234+
return nil, fmt.Errorf("import ID is not service_name/id formatted")
214235
}
215236
serviceName := splitID[0]
216237
id := splitID[1]
@@ -387,7 +408,7 @@ func dbaasLogsInputConfigurationUpdate(ctx context.Context, d *schema.ResourceDa
387408
url.PathEscape(id),
388409
)
389410
if err := config.OVHClient.Put(endpoint, flowggerOpts, res); err != nil {
390-
return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err)
411+
return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err)
391412
}
392413
}
393414

@@ -401,7 +422,7 @@ func dbaasLogsInputConfigurationUpdate(ctx context.Context, d *schema.ResourceDa
401422
url.PathEscape(id),
402423
)
403424
if err := config.OVHClient.Put(endpoint, logstashOpts, res); err != nil {
404-
return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err)
425+
return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err)
405426
}
406427
}
407428

@@ -486,7 +507,7 @@ func dbaasLogsInputStart(ctx context.Context, d *schema.ResourceData, meta inter
486507
url.PathEscape(id),
487508
)
488509
if err := config.OVHClient.Post(endpoint, nil, res); err != nil {
489-
return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err)
510+
return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err)
490511
}
491512
}
492513

@@ -497,7 +518,7 @@ func dbaasLogsInputStart(ctx context.Context, d *schema.ResourceData, meta inter
497518
url.PathEscape(id),
498519
)
499520
if err := config.OVHClient.Post(endpoint, nil, res); err != nil {
500-
return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err)
521+
return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err)
501522
}
502523
}
503524

@@ -538,7 +559,7 @@ func dbaasLogsInputEnd(ctx context.Context, d *schema.ResourceData, meta interfa
538559
url.PathEscape(id),
539560
)
540561
if err := config.OVHClient.Post(endpoint, nil, res); err != nil {
541-
return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err)
562+
return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err)
542563
}
543564

544565
// Wait for operation status

Diff for: ovh/resource_dbaas_logs_input_test.go

+123-33
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,75 @@ data "ovh_dbaas_logs_input_engine" "logstash" {
2323
}
2424
2525
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
26-
service_name = "%s"
27-
title = "%s"
28-
description = "%s"
26+
service_name = "%s"
27+
title = "%s"
28+
description = "%s"
2929
}
3030
3131
resource "ovh_dbaas_logs_input" "input" {
32-
service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name
33-
description = ovh_dbaas_logs_output_graylog_stream.stream.description
34-
title = ovh_dbaas_logs_output_graylog_stream.stream.title
35-
engine_id = data.ovh_dbaas_logs_input_engine.logstash.id
36-
stream_id = ovh_dbaas_logs_output_graylog_stream.stream.id
37-
38-
allowed_networks = ["10.0.0.0/16"]
39-
exposed_port = "6154"
40-
nb_instance = 2
41-
42-
configuration {
43-
logstash {
44-
input_section = <<EOF
45-
beats {
46-
port => 6514
47-
ssl => true
48-
ssl_certificate => "/etc/ssl/private/server.crt"
49-
ssl_key => "/etc/ssl/private/server.key"
32+
service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name
33+
description = ovh_dbaas_logs_output_graylog_stream.stream.description
34+
title = ovh_dbaas_logs_output_graylog_stream.stream.title
35+
engine_id = data.ovh_dbaas_logs_input_engine.logstash.id
36+
stream_id = ovh_dbaas_logs_output_graylog_stream.stream.id
37+
38+
allowed_networks = ["10.0.0.0/16"]
39+
exposed_port = "6154"
40+
nb_instance = 2
41+
42+
configuration {
43+
logstash {
44+
input_section = <<EOF
45+
beats {
46+
port => 6514
47+
ssl => true
48+
ssl_certificate => "/etc/ssl/private/server.crt"
49+
ssl_key => "/etc/ssl/private/server.key"
50+
}
51+
EOF
52+
}
53+
}
5054
}
51-
EOF
55+
`
56+
57+
const testAccResourceDbaasLogsInput_updated = `
58+
data "ovh_dbaas_logs_input_engine" "logstash" {
59+
service_name = "%s"
60+
name = "%s"
61+
version = "%s"
62+
}
63+
64+
resource "ovh_dbaas_logs_output_graylog_stream" "stream" {
65+
service_name = "%s"
66+
title = "%s"
67+
description = "%s"
68+
}
69+
70+
resource "ovh_dbaas_logs_input" "input" {
71+
service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name
72+
description = ovh_dbaas_logs_output_graylog_stream.stream.description
73+
title = ovh_dbaas_logs_output_graylog_stream.stream.title
74+
engine_id = data.ovh_dbaas_logs_input_engine.logstash.id
75+
stream_id = ovh_dbaas_logs_output_graylog_stream.stream.id
76+
77+
allowed_networks = ["10.0.0.0/16"]
78+
exposed_port = "6154"
79+
autoscale = true
80+
min_scale_instance = 2
81+
max_scale_instance = 4
5282
53-
}
54-
}
83+
configuration {
84+
logstash {
85+
input_section = <<EOF
86+
beats {
87+
port => 6514
88+
ssl => true
89+
ssl_certificate => "/etc/ssl/private/server.crt"
90+
ssl_key => "/etc/ssl/private/server.key"
91+
}
92+
EOF
93+
}
94+
}
5595
}
5696
`
5797

@@ -161,15 +201,10 @@ func TestAccResourceDbaasLogsInput_basic(t *testing.T) {
161201
title := acctest.RandomWithPrefix(test_prefix)
162202
desc := acctest.RandomWithPrefix(test_prefix)
163203

164-
config := fmt.Sprintf(
165-
testAccResourceDbaasLogsInput_basic,
166-
serviceName,
167-
name,
168-
version,
169-
serviceName,
170-
title,
171-
desc,
172-
)
204+
config := fmt.Sprintf(testAccResourceDbaasLogsInput_basic,
205+
serviceName, name, version, serviceName, title, desc)
206+
configUpdated := fmt.Sprintf(testAccResourceDbaasLogsInput_updated,
207+
serviceName, name, version, serviceName, title, desc)
173208

174209
resource.Test(t, resource.TestCase{
175210
PreCheck: func() { testAccPreCheckDbaasLogsInput(t) },
@@ -189,6 +224,61 @@ func TestAccResourceDbaasLogsInput_basic(t *testing.T) {
189224
"title",
190225
title,
191226
),
227+
resource.TestCheckResourceAttr(
228+
"ovh_dbaas_logs_input.input",
229+
"autoscale",
230+
"false",
231+
),
232+
resource.TestCheckResourceAttr(
233+
"ovh_dbaas_logs_input.input",
234+
"nb_instance",
235+
"2",
236+
),
237+
resource.TestCheckResourceAttr(
238+
"ovh_dbaas_logs_input.input",
239+
"current_nb_instance",
240+
"2",
241+
),
242+
),
243+
},
244+
{
245+
Config: configUpdated,
246+
Check: resource.ComposeTestCheckFunc(
247+
resource.TestCheckResourceAttr(
248+
"ovh_dbaas_logs_input.input",
249+
"description",
250+
desc,
251+
),
252+
resource.TestCheckResourceAttr(
253+
"ovh_dbaas_logs_input.input",
254+
"title",
255+
title,
256+
),
257+
resource.TestCheckResourceAttr(
258+
"ovh_dbaas_logs_input.input",
259+
"autoscale",
260+
"true",
261+
),
262+
resource.TestCheckResourceAttr(
263+
"ovh_dbaas_logs_input.input",
264+
"min_scale_instance",
265+
"2",
266+
),
267+
resource.TestCheckResourceAttr(
268+
"ovh_dbaas_logs_input.input",
269+
"max_scale_instance",
270+
"4",
271+
),
272+
resource.TestCheckResourceAttr(
273+
"ovh_dbaas_logs_input.input",
274+
"nb_instance",
275+
"0",
276+
),
277+
resource.TestCheckResourceAttr(
278+
"ovh_dbaas_logs_input.input",
279+
"current_nb_instance",
280+
"2",
281+
),
192282
),
193283
},
194284
},

Diff for: ovh/types_dbaas_logs_input.go

+28-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ type DbaasLogsInput struct {
1818
InputId string `json:"inputId"`
1919
IsRestartRequired bool `json:"isRestartRequired"`
2020
NbInstance *int64 `json:"nbInstance"`
21+
Autoscale bool `json:"autoscale"`
22+
MaxScaleInstance *int `json:"maxScaleInstance"`
23+
MinScaleInstance *int `json:"minScaleInstance"`
2124
PublicAddress string `json:"publicAddress"`
2225
SslCertificate string `json:"sslCertificate"`
2326
Status string `json:"status"`
@@ -40,6 +43,7 @@ func (v DbaasLogsInput) ToMap() map[string]interface{} {
4043
obj["stream_id"] = v.StreamId
4144
obj["title"] = v.Title
4245
obj["updated_at"] = v.UpdatedAt
46+
obj["autoscale"] = v.Autoscale
4347

4448
if v.AllowedNetworks != nil {
4549
obj["allowed_networks"] = v.AllowedNetworks
@@ -48,20 +52,29 @@ func (v DbaasLogsInput) ToMap() map[string]interface{} {
4852
obj["exposed_port"] = *v.ExposedPort
4953
}
5054
if v.NbInstance != nil {
51-
obj["nb_instance"] = *v.NbInstance
55+
obj["current_nb_instance"] = *v.NbInstance
56+
}
57+
if v.MaxScaleInstance != nil {
58+
obj["max_scale_instance"] = *v.MaxScaleInstance
59+
}
60+
if v.MinScaleInstance != nil {
61+
obj["min_scale_instance"] = *v.MinScaleInstance
5262
}
5363

5464
return obj
5565
}
5666

5767
type DbaasLogsInputOpts struct {
58-
Description string `json:"description"`
59-
EngineId string `json:"engineId"`
60-
StreamId string `json:"streamId"`
61-
Title string `json:"title"`
62-
AllowedNetworks []string `json:"allowedNetworks,omitempty"`
63-
ExposedPort *string `json:"exposedPort,omitempty"`
64-
NbInstance *int64 `json:"nbInstance,omitempty"`
68+
Description string `json:"description"`
69+
EngineId string `json:"engineId"`
70+
StreamId string `json:"streamId"`
71+
Title string `json:"title"`
72+
AllowedNetworks []string `json:"allowedNetworks,omitempty"`
73+
ExposedPort *string `json:"exposedPort,omitempty"`
74+
NbInstance *int64 `json:"nbInstance,omitempty"`
75+
Autoscale bool `json:"autoscale"`
76+
MaxScaleInstance *int `json:"maxScaleInstance,omitempty"`
77+
MinScaleInstance *int `json:"minScaleInstance,omitempty"`
6578
}
6679

6780
func (opts *DbaasLogsInputOpts) FromResource(d *schema.ResourceData) *DbaasLogsInputOpts {
@@ -71,7 +84,7 @@ func (opts *DbaasLogsInputOpts) FromResource(d *schema.ResourceData) *DbaasLogsI
7184
opts.Title = d.Get("title").(string)
7285

7386
networks := d.Get("allowed_networks").([]interface{})
74-
if networks != nil && len(networks) > 0 {
87+
if len(networks) > 0 {
7588
networksString := make([]string, len(networks))
7689
for i, net := range networks {
7790
networksString[i] = net.(string)
@@ -81,6 +94,12 @@ func (opts *DbaasLogsInputOpts) FromResource(d *schema.ResourceData) *DbaasLogsI
8194

8295
opts.ExposedPort = helpers.GetNilStringPointerFromData(d, "exposed_port")
8396
opts.NbInstance = helpers.GetNilInt64PointerFromData(d, "nb_instance")
97+
if autoscale, ok := d.GetOk("autoscale"); ok {
98+
opts.Autoscale = autoscale.(bool)
99+
}
100+
opts.MaxScaleInstance = helpers.GetNilIntPointerFromDataAndNilIfNotPresent(d, "max_scale_instance")
101+
opts.MinScaleInstance = helpers.GetNilIntPointerFromDataAndNilIfNotPresent(d, "min_scale_instance")
102+
84103
return opts
85104
}
86105

Diff for: website/docs/r/dbaas_logs_input.html.markdown

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ The following arguments are supported:
6363
* `description` - (Required) Input description
6464
* `engine_id` - (Required) Input engine ID
6565
* `exposed_port` - Port
66-
* `nb_instance` - Number of instance running
66+
* `nb_instance` - Number of instance running (input, mutually exclusive with parameter `autoscale`)
67+
* `autoscale` - Whether the workload is auto-scaled (mutually exclusive with parameter `nb_instance`)
68+
* `min_scale_instance` - Minimum number of instances in auto-scaled mode
69+
* `max_scale_instance` - Maximum number of instances in auto-scaled mode
6770
* `service_name` - (Required) service name
6871
* `stream_id` - (Required) Associated Graylog stream
6972
* `title` - (Required) Input title
@@ -80,3 +83,4 @@ Id is set to the input Id. In addition, the following attributes are exported:
8083
* `ssl_certificate` - Input SSL certificate
8184
* `status` - init: configuration required, pending: ready to start, running: available
8285
* `updated_at` - Input last update
86+
* `current_nb_instance` - Number of instance running (returned by the API)

0 commit comments

Comments
 (0)