diff --git a/ovh/resource_dbaas_logs_input.go b/ovh/resource_dbaas_logs_input.go index ad8bd40f..d75b80ab 100644 --- a/ovh/resource_dbaas_logs_input.go +++ b/ovh/resource_dbaas_logs_input.go @@ -153,10 +153,26 @@ func resourceDbaasLogsInputSchema() map[string]*schema.Schema { Computed: true, }, "nb_instance": { + Type: schema.TypeInt, + Description: "Number of instance running", + Optional: true, + ConflictsWith: []string{"autoscale"}, + }, + "autoscale": { + Type: schema.TypeBool, + Description: "Whether the workload is auto-scaled", + Optional: true, + ConflictsWith: []string{"nb_instance"}, + }, + "min_scale_instance": { Type: schema.TypeInt, - Description: "Number of instance running", + Description: "Minimum number of instances in auto-scaled mode", + Optional: true, + }, + "max_scale_instance": { + Type: schema.TypeInt, + Description: "Maximum number of instances in auto-scaled mode", Optional: true, - Computed: true, }, // computed @@ -201,6 +217,11 @@ func resourceDbaasLogsInputSchema() map[string]*schema.Schema { Description: "Input last update", Computed: true, }, + "current_nb_instance": { + Type: schema.TypeInt, + Description: "Number of instance running (returned by the API)", + Computed: true, + }, } return schema @@ -210,7 +231,7 @@ func resourceDbaasLogsInputImportState(d *schema.ResourceData, meta interface{}) givenID := d.Id() splitID := strings.SplitN(givenID, "/", 2) if len(splitID) != 2 { - return nil, fmt.Errorf("Import Id is not service_name/id formatted") + return nil, fmt.Errorf("import ID is not service_name/id formatted") } serviceName := splitID[0] id := splitID[1] @@ -387,7 +408,7 @@ func dbaasLogsInputConfigurationUpdate(ctx context.Context, d *schema.ResourceDa url.PathEscape(id), ) if err := config.OVHClient.Put(endpoint, flowggerOpts, res); err != nil { - return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err) + return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err) } } @@ -401,7 +422,7 @@ func dbaasLogsInputConfigurationUpdate(ctx context.Context, d *schema.ResourceDa url.PathEscape(id), ) if err := config.OVHClient.Put(endpoint, logstashOpts, res); err != nil { - return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err) + return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err) } } @@ -486,7 +507,7 @@ func dbaasLogsInputStart(ctx context.Context, d *schema.ResourceData, meta inter url.PathEscape(id), ) if err := config.OVHClient.Post(endpoint, nil, res); err != nil { - return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err) + return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err) } } @@ -497,7 +518,7 @@ func dbaasLogsInputStart(ctx context.Context, d *schema.ResourceData, meta inter url.PathEscape(id), ) if err := config.OVHClient.Post(endpoint, nil, res); err != nil { - return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err) + return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err) } } @@ -538,7 +559,7 @@ func dbaasLogsInputEnd(ctx context.Context, d *schema.ResourceData, meta interfa url.PathEscape(id), ) if err := config.OVHClient.Post(endpoint, nil, res); err != nil { - return fmt.Errorf("Error calling Put %s:\n\t %q", endpoint, err) + return fmt.Errorf("error calling Put %s:\n\t %q", endpoint, err) } // Wait for operation status diff --git a/ovh/resource_dbaas_logs_input_test.go b/ovh/resource_dbaas_logs_input_test.go index fce64e85..14747862 100644 --- a/ovh/resource_dbaas_logs_input_test.go +++ b/ovh/resource_dbaas_logs_input_test.go @@ -23,35 +23,75 @@ data "ovh_dbaas_logs_input_engine" "logstash" { } resource "ovh_dbaas_logs_output_graylog_stream" "stream" { - service_name = "%s" - title = "%s" - description = "%s" + service_name = "%s" + title = "%s" + description = "%s" } resource "ovh_dbaas_logs_input" "input" { - service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name - description = ovh_dbaas_logs_output_graylog_stream.stream.description - title = ovh_dbaas_logs_output_graylog_stream.stream.title - engine_id = data.ovh_dbaas_logs_input_engine.logstash.id - stream_id = ovh_dbaas_logs_output_graylog_stream.stream.id - - allowed_networks = ["10.0.0.0/16"] - exposed_port = "6154" - nb_instance = 2 - - configuration { - logstash { - input_section = < 6514 - ssl => true - ssl_certificate => "/etc/ssl/private/server.crt" - ssl_key => "/etc/ssl/private/server.key" + service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name + description = ovh_dbaas_logs_output_graylog_stream.stream.description + title = ovh_dbaas_logs_output_graylog_stream.stream.title + engine_id = data.ovh_dbaas_logs_input_engine.logstash.id + stream_id = ovh_dbaas_logs_output_graylog_stream.stream.id + + allowed_networks = ["10.0.0.0/16"] + exposed_port = "6154" + nb_instance = %d + + configuration { + logstash { + input_section = < 6514 + ssl => true + ssl_certificate => "/etc/ssl/private/server.crt" + ssl_key => "/etc/ssl/private/server.key" + } + EOF + } + } } -EOF +` - } - } +const testAccResourceDbaasLogsInput_updated = ` +data "ovh_dbaas_logs_input_engine" "logstash" { + service_name = "%s" + name = "%s" + version = "%s" +} + +resource "ovh_dbaas_logs_output_graylog_stream" "stream" { + service_name = "%s" + title = "%s" + description = "%s" +} + +resource "ovh_dbaas_logs_input" "input" { + service_name = ovh_dbaas_logs_output_graylog_stream.stream.service_name + description = ovh_dbaas_logs_output_graylog_stream.stream.description + title = ovh_dbaas_logs_output_graylog_stream.stream.title + engine_id = data.ovh_dbaas_logs_input_engine.logstash.id + stream_id = ovh_dbaas_logs_output_graylog_stream.stream.id + + allowed_networks = ["10.0.0.0/16"] + exposed_port = "6154" + autoscale = true + min_scale_instance = 2 + max_scale_instance = 4 + + configuration { + logstash { + input_section = < 6514 + ssl => true + ssl_certificate => "/etc/ssl/private/server.crt" + ssl_key => "/etc/ssl/private/server.key" + } + EOF + } + } } ` @@ -161,15 +201,12 @@ func TestAccResourceDbaasLogsInput_basic(t *testing.T) { title := acctest.RandomWithPrefix(test_prefix) desc := acctest.RandomWithPrefix(test_prefix) - config := fmt.Sprintf( - testAccResourceDbaasLogsInput_basic, - serviceName, - name, - version, - serviceName, - title, - desc, - ) + config := fmt.Sprintf(testAccResourceDbaasLogsInput_basic, + serviceName, name, version, serviceName, title, desc, 2) + configWithMoreInstances := fmt.Sprintf(testAccResourceDbaasLogsInput_basic, + serviceName, name, version, serviceName, title, desc, 4) + configUpdated := fmt.Sprintf(testAccResourceDbaasLogsInput_updated, + serviceName, name, version, serviceName, title, desc) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheckDbaasLogsInput(t) }, @@ -189,6 +226,91 @@ func TestAccResourceDbaasLogsInput_basic(t *testing.T) { "title", title, ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "autoscale", + "false", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "nb_instance", + "2", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "current_nb_instance", + "2", + ), + ), + }, + { + Config: configWithMoreInstances, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "description", + desc, + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "title", + title, + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "autoscale", + "false", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "nb_instance", + "4", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "current_nb_instance", + "4", + ), + ), + }, + { + Config: configUpdated, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "description", + desc, + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "title", + title, + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "autoscale", + "true", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "min_scale_instance", + "2", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "max_scale_instance", + "4", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "nb_instance", + "0", + ), + resource.TestCheckResourceAttr( + "ovh_dbaas_logs_input.input", + "current_nb_instance", + "4", + ), ), }, }, diff --git a/ovh/types_dbaas_logs_input.go b/ovh/types_dbaas_logs_input.go index 8a7092c7..c2ecb88d 100644 --- a/ovh/types_dbaas_logs_input.go +++ b/ovh/types_dbaas_logs_input.go @@ -18,6 +18,9 @@ type DbaasLogsInput struct { InputId string `json:"inputId"` IsRestartRequired bool `json:"isRestartRequired"` NbInstance *int64 `json:"nbInstance"` + Autoscale bool `json:"autoscale"` + MaxScaleInstance *int `json:"maxScaleInstance"` + MinScaleInstance *int `json:"minScaleInstance"` PublicAddress string `json:"publicAddress"` SslCertificate string `json:"sslCertificate"` Status string `json:"status"` @@ -40,6 +43,7 @@ func (v DbaasLogsInput) ToMap() map[string]interface{} { obj["stream_id"] = v.StreamId obj["title"] = v.Title obj["updated_at"] = v.UpdatedAt + obj["autoscale"] = v.Autoscale if v.AllowedNetworks != nil { obj["allowed_networks"] = v.AllowedNetworks @@ -48,20 +52,29 @@ func (v DbaasLogsInput) ToMap() map[string]interface{} { obj["exposed_port"] = *v.ExposedPort } if v.NbInstance != nil { - obj["nb_instance"] = *v.NbInstance + obj["current_nb_instance"] = *v.NbInstance + } + if v.MaxScaleInstance != nil { + obj["max_scale_instance"] = *v.MaxScaleInstance + } + if v.MinScaleInstance != nil { + obj["min_scale_instance"] = *v.MinScaleInstance } return obj } type DbaasLogsInputOpts struct { - Description string `json:"description"` - EngineId string `json:"engineId"` - StreamId string `json:"streamId"` - Title string `json:"title"` - AllowedNetworks []string `json:"allowedNetworks,omitempty"` - ExposedPort *string `json:"exposedPort,omitempty"` - NbInstance *int64 `json:"nbInstance,omitempty"` + Description string `json:"description"` + EngineId string `json:"engineId"` + StreamId string `json:"streamId"` + Title string `json:"title"` + AllowedNetworks []string `json:"allowedNetworks,omitempty"` + ExposedPort *string `json:"exposedPort,omitempty"` + NbInstance *int64 `json:"nbInstance,omitempty"` + Autoscale bool `json:"autoscale"` + MaxScaleInstance *int `json:"maxScaleInstance,omitempty"` + MinScaleInstance *int `json:"minScaleInstance,omitempty"` } func (opts *DbaasLogsInputOpts) FromResource(d *schema.ResourceData) *DbaasLogsInputOpts { @@ -71,7 +84,7 @@ func (opts *DbaasLogsInputOpts) FromResource(d *schema.ResourceData) *DbaasLogsI opts.Title = d.Get("title").(string) networks := d.Get("allowed_networks").([]interface{}) - if networks != nil && len(networks) > 0 { + if len(networks) > 0 { networksString := make([]string, len(networks)) for i, net := range networks { networksString[i] = net.(string) @@ -81,6 +94,12 @@ func (opts *DbaasLogsInputOpts) FromResource(d *schema.ResourceData) *DbaasLogsI opts.ExposedPort = helpers.GetNilStringPointerFromData(d, "exposed_port") opts.NbInstance = helpers.GetNilInt64PointerFromData(d, "nb_instance") + if autoscale, ok := d.GetOk("autoscale"); ok { + opts.Autoscale = autoscale.(bool) + } + opts.MaxScaleInstance = helpers.GetNilIntPointerFromDataAndNilIfNotPresent(d, "max_scale_instance") + opts.MinScaleInstance = helpers.GetNilIntPointerFromDataAndNilIfNotPresent(d, "min_scale_instance") + return opts } diff --git a/website/docs/r/dbaas_logs_input.html.markdown b/website/docs/r/dbaas_logs_input.html.markdown index f74fecb1..1aed228d 100644 --- a/website/docs/r/dbaas_logs_input.html.markdown +++ b/website/docs/r/dbaas_logs_input.html.markdown @@ -63,7 +63,10 @@ The following arguments are supported: * `description` - (Required) Input description * `engine_id` - (Required) Input engine ID * `exposed_port` - Port -* `nb_instance` - Number of instance running +* `nb_instance` - Number of instance running (input, mutually exclusive with parameter `autoscale`) +* `autoscale` - Whether the workload is auto-scaled (mutually exclusive with parameter `nb_instance`) +* `min_scale_instance` - Minimum number of instances in auto-scaled mode +* `max_scale_instance` - Maximum number of instances in auto-scaled mode * `service_name` - (Required) service name * `stream_id` - (Required) Associated Graylog stream * `title` - (Required) Input title @@ -80,3 +83,4 @@ Id is set to the input Id. In addition, the following attributes are exported: * `ssl_certificate` - Input SSL certificate * `status` - init: configuration required, pending: ready to start, running: available * `updated_at` - Input last update +* `current_nb_instance` - Number of instance running (returned by the API)