diff --git a/.gitignore b/.gitignore index af17b90f9b..b645999118 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ website/node_modules *~ .*.swp .idea +.vscode *.iml *.test *.iml diff --git a/go.mod b/go.mod index cacab37dbb..0adda99789 100644 --- a/go.mod +++ b/go.mod @@ -7,4 +7,4 @@ require ( github.com/vmware/go-vcloud-director/v2 v2.2.0 ) -replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190603073202-811d7fc79f20 +replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190607082001-562a09fad118 diff --git a/go.sum b/go.sum index ea9276abfa..74069ca10e 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4= github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190603073202-811d7fc79f20 h1:u0AW0XwavNi0qQQJVYFqMbVbunwZje2we5obpWRUFlg= github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190603073202-811d7fc79f20/go.mod h1:+Hq7ryFfgZqsO6mXH29RQFnpIMSujCOMI57otHoXHhQ= +github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190607082001-562a09fad118 h1:dgXaMkmp1GIpXHFbYqvpEqFErUE/bh6pdFu33EorvuU= +github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190607082001-562a09fad118/go.mod h1:+Hq7ryFfgZqsO6mXH29RQFnpIMSujCOMI57otHoXHhQ= github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292/go.mod h1:KYCjqMOeHpNuTOiFQU6WEcTG7poCJrUs0YgyHNtn1no= github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw= github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= diff --git a/vcd/resource_vcd_lb_service_monitor.go b/vcd/resource_vcd_lb_service_monitor.go index c205c40998..658fcf5cfc 100644 --- a/vcd/resource_vcd_lb_service_monitor.go +++ b/vcd/resource_vcd_lb_service_monitor.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/helper/validation" "github.com/vmware/go-vcloud-director/v2/types/v56" ) @@ -67,10 +66,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, + // 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", }, "expected": &schema.Schema{ Type: schema.TypeString, @@ -78,10 +77,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, + // ValidateFunc: validation.StringInSlice([]string{"GET", "OPTIONS", "POST"}, false), + Description: "Method to be used to detect server status", }, "url": &schema.Schema{ Type: schema.TypeString, diff --git a/vcd/resource_vcd_lb_service_monitor_test.go b/vcd/resource_vcd_lb_service_monitor_test.go index dd017dd602..b16cf32b33 100644 --- a/vcd/resource_vcd_lb_service_monitor_test.go +++ b/vcd/resource_vcd_lb_service_monitor_test.go @@ -1,4 +1,4 @@ -// +build gateway lb lbsm ALL functional +// +build gateway lb lbServiceMonitor ALL functional package vcd @@ -16,8 +16,7 @@ import ( "github.com/hashicorp/terraform/helper/resource" ) -func TestAccVcdLbServiceMonitor_Basic(t *testing.T) { - //var vpnName string = t.Name() +func TestAccVcdLbServiceMonitor(t *testing.T) { if vcdShortTest { t.Skip(acceptanceTestsSkipped) @@ -32,8 +31,8 @@ func TestAccVcdLbServiceMonitor_Basic(t *testing.T) { "Interval": 5, "Timeout": 10, "MaxRetries": 3, - "Method": "POST", - "Tags": "lb lbsm", + "Method": "ASD", + "Tags": "lb lbServiceMonitor", } configText := templateFill(testAccVcdLbServiceMonitor_Basic, params) @@ -43,8 +42,6 @@ func TestAccVcdLbServiceMonitor_Basic(t *testing.T) { configTextStep1 := templateFill(testAccVcdLbServiceMonitor_Basic2, params) debugPrintf("#[DEBUG] CONFIGURATION for step 1: %s", configTextStep1) - - resource.Test(t, resource.TestCase{ Providers: testAccProviders, PreCheck: func() { testAccPreCheck(t) }, @@ -79,6 +76,13 @@ func TestAccVcdLbServiceMonitor_Basic(t *testing.T) { resource.TestCheckResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "type", "tcp"), ), }, + // Check that import works + resource.TestStep{ + ResourceName: "vcd_lb_service_monitor.service-monitor-import", + ImportState: true, + ImportStateVerify: true, + ImportStateIdFunc: importStateIdByOrgVdcEdge(testConfig, params["ServiceMonitorName"].(string)), + }, }, }) } @@ -100,6 +104,20 @@ func testAccCheckVcdLbServiceMonitorDestroy(serviceMonitorName string) resource. } } +// importStateIdByOrgVdcEdge constructs an import path (ID in Terraform import terms) in the format of: +// organization.vdc.edge-gateway-nane.import-object-name (i.e. my-org.my-vdc.my-edge-gw.objectName) from TestConfig and +// object state. +func importStateIdByOrgVdcEdge(vcd TestConfig, objectName string) resource.ImportStateIdFunc { + return func(*terraform.State) (string, error) { + importId := testConfig.VCD.Org + "." + testConfig.VCD.Vdc + "." + testConfig.Networking.EdgeGateway + "." + objectName + if testConfig.VCD.Org == "" || testConfig.VCD.Vdc == "" || testConfig.Networking.EdgeGateway == "" || objectName == "" { + return "", fmt.Errorf("missing information to generate import path: %s", importId) + } + + return importId, nil + } +} + const testAccVcdLbServiceMonitor_Basic = ` resource "vcd_lb_service_monitor" "lb-service-monitor" { org = "{{.Org}}" @@ -144,4 +162,3 @@ resource "vcd_lb_service_monitor" "lb-service-monitor" { max_retries = {{.MaxRetries}} } ` - diff --git a/vcd/test-templates/misc3.tf b/vcd/test-templates/misc3.tf new file mode 100644 index 0000000000..c652b7b608 --- /dev/null +++ b/vcd/test-templates/misc3.tf @@ -0,0 +1,43 @@ +# Remove the first '#' from the next two lines to enable options for terraform executable +# apply-options -parallelism=1 +# destroy-options -parallelism=1 + +# Edge gateway load balancer configuration +# v2.4.0+ + +variable "service_monitor_count" { + default = 20 +} + +resource "vcd_lb_service_monitor" "test" { + count = "${var.service_monitor_count}" + + org = "{{.Org}}" + vdc = "{{.Vdc}}" + edge_gateway = "{{.EdgeGateway}}" + + name = "test-monitor-${count.index}" + interval = 5 + timeout = 5 + max_retries = 3 + type = "http" + method = "POST" + send = "{\"key\": \"value\"}" + expected = "HTTP/1.1" + receive = "OK" + + extension = { + "content-type" = "application/json" + "no-body" = "" + } +} + + +data "vcd_lb_service_monitor" "ds-lb" { + count = "${var.service_monitor_count}" + + org = "{{.Org}}" + vdc = "{{.Vdc}}" + edge_gateway = "{{.EdgeGateway}}" + name = "${vcd_lb_service_monitor.test[count.index].name}" +}