Skip to content

Commit 2cdaea4

Browse files
authored
Merge pull request #720 from ovh/dev/aamstutz/fix-dedicated-input
fix: Add missing autoscaling params to resource ovh_dbaas_logs_input
2 parents 2dc82b1 + 8fb14ca commit 2cdaea4

File tree

4 files changed

+217
-51
lines changed

4 files changed

+217
-51
lines changed

ovh/resource_dbaas_logs_input.go

Lines changed: 29 additions & 8 deletions
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

ovh/resource_dbaas_logs_input_test.go

Lines changed: 155 additions & 33 deletions
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 = %d
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+
`
5256

53-
}
54-
}
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
82+
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,12 @@ 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, 2)
206+
configWithMoreInstances := fmt.Sprintf(testAccResourceDbaasLogsInput_basic,
207+
serviceName, name, version, serviceName, title, desc, 4)
208+
configUpdated := fmt.Sprintf(testAccResourceDbaasLogsInput_updated,
209+
serviceName, name, version, serviceName, title, desc)
173210

174211
resource.Test(t, resource.TestCase{
175212
PreCheck: func() { testAccPreCheckDbaasLogsInput(t) },
@@ -189,6 +226,91 @@ func TestAccResourceDbaasLogsInput_basic(t *testing.T) {
189226
"title",
190227
title,
191228
),
229+
resource.TestCheckResourceAttr(
230+
"ovh_dbaas_logs_input.input",
231+
"autoscale",
232+
"false",
233+
),
234+
resource.TestCheckResourceAttr(
235+
"ovh_dbaas_logs_input.input",
236+
"nb_instance",
237+
"2",
238+
),
239+
resource.TestCheckResourceAttr(
240+
"ovh_dbaas_logs_input.input",
241+
"current_nb_instance",
242+
"2",
243+
),
244+
),
245+
},
246+
{
247+
Config: configWithMoreInstances,
248+
Check: resource.ComposeTestCheckFunc(
249+
resource.TestCheckResourceAttr(
250+
"ovh_dbaas_logs_input.input",
251+
"description",
252+
desc,
253+
),
254+
resource.TestCheckResourceAttr(
255+
"ovh_dbaas_logs_input.input",
256+
"title",
257+
title,
258+
),
259+
resource.TestCheckResourceAttr(
260+
"ovh_dbaas_logs_input.input",
261+
"autoscale",
262+
"false",
263+
),
264+
resource.TestCheckResourceAttr(
265+
"ovh_dbaas_logs_input.input",
266+
"nb_instance",
267+
"4",
268+
),
269+
resource.TestCheckResourceAttr(
270+
"ovh_dbaas_logs_input.input",
271+
"current_nb_instance",
272+
"4",
273+
),
274+
),
275+
},
276+
{
277+
Config: configUpdated,
278+
Check: resource.ComposeTestCheckFunc(
279+
resource.TestCheckResourceAttr(
280+
"ovh_dbaas_logs_input.input",
281+
"description",
282+
desc,
283+
),
284+
resource.TestCheckResourceAttr(
285+
"ovh_dbaas_logs_input.input",
286+
"title",
287+
title,
288+
),
289+
resource.TestCheckResourceAttr(
290+
"ovh_dbaas_logs_input.input",
291+
"autoscale",
292+
"true",
293+
),
294+
resource.TestCheckResourceAttr(
295+
"ovh_dbaas_logs_input.input",
296+
"min_scale_instance",
297+
"2",
298+
),
299+
resource.TestCheckResourceAttr(
300+
"ovh_dbaas_logs_input.input",
301+
"max_scale_instance",
302+
"4",
303+
),
304+
resource.TestCheckResourceAttr(
305+
"ovh_dbaas_logs_input.input",
306+
"nb_instance",
307+
"0",
308+
),
309+
resource.TestCheckResourceAttr(
310+
"ovh_dbaas_logs_input.input",
311+
"current_nb_instance",
312+
"4",
313+
),
192314
),
193315
},
194316
},

ovh/types_dbaas_logs_input.go

Lines changed: 28 additions & 9 deletions
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

0 commit comments

Comments
 (0)