diff --git a/vcd/resource_vcd_lb_service_monitor.go b/vcd/resource_vcd_lb_service_monitor.go index c94dd6ea9..cf2abcfdf 100644 --- a/vcd/resource_vcd_lb_service_monitor.go +++ b/vcd/resource_vcd_lb_service_monitor.go @@ -60,10 +60,10 @@ func ResourceVcdLbServiceMonitor() *schema.Resource { Description: "Number of times the specified monitoring Method must fail sequentially before the server is declared down", }, "type": &schema.Schema{ - Type: schema.TypeString, - Required: true, - // ValidateFunc: validation.StringInSlice([]string{"http", "https", "tcp", "icmp", "udp"}, false), - Description: "Way in which you want to send the health check request to the server", + Type: schema.TypeString, + Required: true, + Description: "Way in which you want to send the health check request to the server", + ValidateFunc: validateLowerCase(), }, "expected": &schema.Schema{ Type: schema.TypeString, @@ -71,10 +71,10 @@ func ResourceVcdLbServiceMonitor() *schema.Resource { Description: "String that the monitor expects to match in the status line of the HTTP or HTTPS response (for example, HTTP/1.1)", }, "method": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - // ValidateFunc: validation.StringInSlice([]string{"GET", "OPTIONS", "POST"}, false), - Description: "Method to be used to detect server status", + Type: schema.TypeString, + Optional: true, + Description: "Method to be used to detect server status", + ValidateFunc: validateUpperCase(), }, "url": &schema.Schema{ Type: schema.TypeString, @@ -100,6 +100,40 @@ func ResourceVcdLbServiceMonitor() *schema.Resource { } } +// validateUpperCase checks that a string is upper cased +func validateUpperCase() schema.SchemaValidateFunc { + return func(i interface{}, k string) (s []string, es []error) { + v, ok := i.(string) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be string", k)) + return + } + + if strings.ToUpper(v) != v { + es = append(es, fmt.Errorf( + "expected string to be upper cased, got: %s", v)) + } + return + } +} + +// validateUpperCase checks that a string is upper cased +func validateLowerCase() schema.SchemaValidateFunc { + return func(i interface{}, k string) (s []string, es []error) { + v, ok := i.(string) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be string", k)) + return + } + + if strings.ToLower(v) != v { + es = append(es, fmt.Errorf( + "expected string to be lower cased, got: %s", v)) + } + return + } +} + func resourceVcdLbServiceMonitorCreate(d *schema.ResourceData, meta interface{}) error { vcdClient := meta.(*VCDClient) vcdClient.lockParentEdgeGtw(d) @@ -126,8 +160,6 @@ func resourceVcdLbServiceMonitorCreate(d *schema.ResourceData, meta interface{}) func resourceVcdLbServiceMonitorRead(d *schema.ResourceData, meta interface{}) error { vcdClient := meta.(*VCDClient) - vcdClient.lockParentEdgeGtw(d) - defer vcdClient.unLockParentEdgeGtw(d) edgeGateway, err := vcdClient.GetEdgeGatewayFromResource(d) if err != nil { diff --git a/vcd/resource_vcd_lb_service_monitor_test.go b/vcd/resource_vcd_lb_service_monitor_test.go index b16cf32b3..2142629c9 100644 --- a/vcd/resource_vcd_lb_service_monitor_test.go +++ b/vcd/resource_vcd_lb_service_monitor_test.go @@ -31,7 +31,7 @@ func TestAccVcdLbServiceMonitor(t *testing.T) { "Interval": 5, "Timeout": 10, "MaxRetries": 3, - "Method": "ASD", + "Method": "POST", "Tags": "lb lbServiceMonitor", } @@ -49,7 +49,7 @@ func TestAccVcdLbServiceMonitor(t *testing.T) { Steps: []resource.TestStep{ resource.TestStep{ Config: configText, - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "name", params["ServiceMonitorName"].(string)), resource.TestMatchResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "id", regexp.MustCompile(`^monitor-\d*$`)), resource.TestCheckResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "method", params["Method"].(string)), @@ -70,7 +70,7 @@ func TestAccVcdLbServiceMonitor(t *testing.T) { }, resource.TestStep{ Config: configTextStep1, - Check: resource.ComposeTestCheckFunc( + Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "name", params["ServiceMonitorName"].(string)), resource.TestMatchResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "id", regexp.MustCompile(`^monitor-\d*$`)), resource.TestCheckResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "type", "tcp"), diff --git a/vcd/test-templates/misc3.tf b/vcd/test-templates/misc3.tf index c652b7b60..2f0975e14 100644 --- a/vcd/test-templates/misc3.tf +++ b/vcd/test-templates/misc3.tf @@ -1,8 +1,10 @@ # Remove the first '#' from the next two lines to enable options for terraform executable -# apply-options -parallelism=1 -# destroy-options -parallelism=1 +## apply-options -parallelism=1 +## destroy-options -parallelism=1 + +# Edge gateway load balancer configuration. It will get more details, but for now is used to +# make sure that locks work fine and it does not fail -# Edge gateway load balancer configuration # v2.4.0+ variable "service_monitor_count" { diff --git a/website/docs/r/lb_service_monitor.html.markdown b/website/docs/r/lb_service_monitor.html.markdown index bf13bbf95..dd6946494 100644 --- a/website/docs/r/lb_service_monitor.html.markdown +++ b/website/docs/r/lb_service_monitor.html.markdown @@ -41,7 +41,7 @@ resource "vcd_lb_service_monitor" "monitor" { timeout = "20" max_retries = "3" type = "http" - http_method = "get" + http_method = "GET" extension = { content-type = "application/json" linespan = "" @@ -61,14 +61,14 @@ The following arguments are supported: * `interval` - (Required) Interval at which a server is to be monitored using the specified Method. * `timeout` - (Required) Maximum time in seconds within which a response from the server must be received * `max_retries` - (Required) Number of times the specified monitoring Method must fail sequentially before the server is declared down -* `type` - (Required) Select the way in which you want to send the health check request to the server— `HTTP`, `HTTPS`, -`TCP`, `ICMP`, or `UDP`. Depending on the type selected, the remaining attributes are allowed or not -* `method` - (Optional) For types `HTTP` and `HTTPS`. Select the method to be used to detect server status -* `url` - (Optional) For types `HTTP` and `HTTPS`. URL to be used in the server status request -* `send` - (Optional) For types `HTTP`, `HTTPS`, and `UDP`. The data to be sent. -* `expected` - (Optional) For types `HTTP` and `HTTPS`. String that the monitor expects to match in the status line of +* `type` - (Required) Select the way in which you want to send the health check request to the server — `http`, `https`, +`tcp`, `icmp`, or `udp`. Depending on the type selected, the remaining attributes are allowed or not +* `method` - (Optional) For types `http` and `https`. Select http method to be used to detect server status +* `url` - (Optional) For types `http` and `https`. URL to be used in the server status request +* `send` - (Optional) For types `http`, `https`, and `udp`. The data to be sent. +* `expected` - (Optional) For types `http` and `https`. String that the monitor expects to match in the status line of the HTTP or HTTPS response (for example, `HTTP/1.1`) -* `receive` - (Optional) For types `HTTP`, `HTTPS`, and `UDP`. The string to be matched in the response content. +* `receive` - (Optional) For types `http`, `https`, and `udp`. The string to be matched in the response content. **Note**: When `expected` is not matched, the monitor does not try to match the Receive content * `extension` - (Required) A map of advanced monitor parameters as key=value pairs (i.e. `max-age=SECONDS`, `invert-regex`) **Note**: When you need a value of `key` only format just set value to empty string (i.e. `linespan = ""`)