Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
Add load balancer service monitor resource and datasource (vmware#256)
Browse files Browse the repository at this point in the history
* Add load balancer service monitor resource and datasource
  • Loading branch information
Didainius committed Jun 14, 2019
1 parent 21ec5fd commit 52ebf04
Show file tree
Hide file tree
Showing 25 changed files with 1,575 additions and 140 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -20,6 +20,7 @@ website/node_modules
*~
.*.swp
.idea
.vscode/
*.iml
*.test
*.iml
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,12 @@
## 2.4.0 (Unreleased)
IMPROVEMENTS:

* Change resource handling to use locking mechanism when resource parallel handling is not supported by vCD. [GH-#255]
* Change resource handling to use locking mechanism when resource parallel handling is not supported by vCD. [GH-255]

FEATURES:

* **New Resource:** Load Balancer Service Monitor `vcd_lb_service_monitor` - [GH-256]
* **New Data Source:** Load Balancer Service Monitor `vcd_lb_service_monitor` - [GH-256]

## 2.3.0 (May 29, 2019)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -4,5 +4,5 @@ go 1.12

require (
github.com/hashicorp/terraform v0.12.0
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.1
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.3
)
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -301,8 +301,8 @@ github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4A
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU=
github.com/vmihailenco/msgpack v4.0.1+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.1 h1:zQD5RbcompjwAeACoJjtMgTeUc4lZaLceBv66j5Ayy8=
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.1/go.mod h1:HonlGxbjJ1NAibWh99eE4/S2l6ZOZ5KJzKK1rh2a9vc=
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.3 h1:cgQGF5SmFtHPbwUESzlKu6C8mXBoCei/Wqkji8aScBM=
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.3/go.mod h1:+Hq7ryFfgZqsO6mXH29RQFnpIMSujCOMI57otHoXHhQ=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20161029104018-1d6e34225557/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg=
Expand Down
92 changes: 92 additions & 0 deletions vcd/datasource_vcd_lb_service_monitor.go
@@ -0,0 +1,92 @@
package vcd

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/vmware/go-vcloud-director/v2/types/v56"
)

func datasourceVcdLbServiceMonitor() *schema.Resource {
return &schema.Resource{
Read: datasourceVcdLbServiceMonitorRead,
Schema: map[string]*schema.Schema{
"org": {
Type: schema.TypeString,
Optional: true,
Description: "vCD organization in which the Service Monitor is located",
},
"vdc": {
Type: schema.TypeString,
Optional: true,
Description: "vCD virtual datacenter in which the Service Monitor is located",
},
"edge_gateway": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Edge gateway name in which the Service Monitor is located",
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Service Monitor name",
},
"interval": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"timeout": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"max_retries": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"expected": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"method": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"url": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"send": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"receive": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"extension": {
Type: schema.TypeMap,
Computed: true,
},
},
}
}

func datasourceVcdLbServiceMonitorRead(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*VCDClient)
edgeGateway, err := vcdClient.GetEdgeGatewayFromResource(d)
if err != nil {
return fmt.Errorf(errorUnableToFindEdgeGateway, err)
}

readLBMonitor, err := edgeGateway.ReadLBServiceMonitor(&types.LBMonitor{Name: d.Get("name").(string)})
if err != nil {
return fmt.Errorf("unable to find load balancer service monitor with Name %s: %s", d.Get("name").(string), err)
}

d.SetId(readLBMonitor.ID)
return setLBMonitorData(d, readLBMonitor)
}
43 changes: 24 additions & 19 deletions vcd/provider.go
Expand Up @@ -83,25 +83,30 @@ func Provider() terraform.ResourceProvider {
},

ResourcesMap: map[string]*schema.Resource{
"vcd_network": resourceVcdNetwork(), // DEPRECATED: replaced by vcd_network_routed
"vcd_network_routed": resourceVcdNetworkRouted(),
"vcd_network_direct": resourceVcdNetworkDirect(),
"vcd_network_isolated": resourceVcdNetworkIsolated(),
"vcd_vapp_network": resourceVcdVappNetwork(),
"vcd_vapp": resourceVcdVApp(),
"vcd_firewall_rules": resourceVcdFirewallRules(),
"vcd_dnat": resourceVcdDNAT(),
"vcd_snat": resourceVcdSNAT(),
"vcd_edgegateway_vpn": resourceVcdEdgeGatewayVpn(),
"vcd_vapp_vm": resourceVcdVAppVm(),
"vcd_org": resourceOrg(),
"vcd_org_vdc": resourceVcdOrgVdc(),
"vcd_catalog": resourceVcdCatalog(),
"vcd_catalog_item": resourceVcdCatalogItem(),
"vcd_catalog_media": resourceVcdCatalogMedia(),
"vcd_inserted_media": resourceVcdInsertedMedia(),
"vcd_independent_disk": resourceVcdIndependentDisk(),
"vcd_external_network": resourceVcdExternalNetwork(),
"vcd_network": resourceVcdNetwork(), // DEPRECATED: replaced by vcd_network_routed
"vcd_network_routed": resourceVcdNetworkRouted(),
"vcd_network_direct": resourceVcdNetworkDirect(),
"vcd_network_isolated": resourceVcdNetworkIsolated(),
"vcd_vapp_network": resourceVcdVappNetwork(),
"vcd_vapp": resourceVcdVApp(),
"vcd_firewall_rules": resourceVcdFirewallRules(),
"vcd_dnat": resourceVcdDNAT(),
"vcd_snat": resourceVcdSNAT(),
"vcd_edgegateway_vpn": resourceVcdEdgeGatewayVpn(),
"vcd_vapp_vm": resourceVcdVAppVm(),
"vcd_org": resourceOrg(),
"vcd_org_vdc": resourceVcdOrgVdc(),
"vcd_catalog": resourceVcdCatalog(),
"vcd_catalog_item": resourceVcdCatalogItem(),
"vcd_catalog_media": resourceVcdCatalogMedia(),
"vcd_inserted_media": resourceVcdInsertedMedia(),
"vcd_independent_disk": resourceVcdIndependentDisk(),
"vcd_external_network": resourceVcdExternalNetwork(),
"vcd_lb_service_monitor": resourceVcdLbServiceMonitor(),
},

DataSourcesMap: map[string]*schema.Resource{
"vcd_lb_service_monitor": datasourceVcdLbServiceMonitor(),
},

ConfigureFunc: providerConfigure,
Expand Down
20 changes: 20 additions & 0 deletions vcd/provider_test.go
Expand Up @@ -51,3 +51,23 @@ func testAccPreCheck(t *testing.T) {
func init() {
testingTags["api"] = "provider_test.go"
}

// createTemporaryVCDConnection is meant to create a VCDClient to check environment before executing specific acceptance
// tests and before VCDClient is accessible.
func createTemporaryVCDConnection() *VCDClient {
config := Config{
User: testConfig.Provider.User,
Password: testConfig.Provider.Password,
SysOrg: testConfig.Provider.SysOrg,
Org: testConfig.VCD.Org,
Vdc: testConfig.VCD.Vdc,
Href: testConfig.Provider.Url,
InsecureFlag: testConfig.Provider.AllowInsecure,
MaxRetryTimeout: testConfig.Provider.MaxRetryTimeout,
}
conn, err := config.Client()
if err != nil {
panic("unable to initialize VCD connection :" + err.Error())
}
return conn
}
16 changes: 1 addition & 15 deletions vcd/resource_vcd_firewall_rules_test.go
Expand Up @@ -83,21 +83,7 @@ func createFirewallRulesConfigs(existingRules *govcd.EdgeGateway) string {
defaultAction := "drop"
edgeGatewayName := testConfig.Networking.EdgeGateway
if !vcdShortTest {
config := Config{
User: testConfig.Provider.User,
Password: testConfig.Provider.Password,
SysOrg: testConfig.Provider.SysOrg,
Org: testConfig.VCD.Org,
Vdc: testConfig.VCD.Vdc,
Href: testConfig.Provider.Url,
InsecureFlag: testConfig.Provider.AllowInsecure,
MaxRetryTimeout: 140,
}

conn, err := config.Client()
if err != nil {
panic(err)
}
conn := createTemporaryVCDConnection()

if edgeGatewayName == "" {
panic(fmt.Errorf("could not get an Edge Gateway. Variable networking.edgeGateway is not set"))
Expand Down

0 comments on commit 52ebf04

Please sign in to comment.