Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add load balancer application rule resource and data source #278

Merged
merged 18 commits into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ FEATURES:
* **New Data Source:** `vcd_lb_server_pool` Load Balancer Server Pool - [GH-268]
* **New Resource:** `vcd_lb_app_profile` Load Balancer Application profile - [GH-274]
* **New Data Source:** `vcd_lb_app_profile` Load Balancer Application profile - [GH-274]
* **New Resource:** `vcd_lb_app_rule` Load Balancer Application rule - [GH-278]
* **New Data Source:** `vcd_lb_app_rule` Load Balancer Application rule - [GH-278]
* resource/vcd_org_vdc added Org VDC update and full state read - [GH-275]

IMPROVEMENTS:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ require (
github.com/hashicorp/terraform v0.12.0
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.8
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.3.0-alpha.3.0.20190710123027-2756ed0823d2
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/Azure/go-autorest v10.15.4+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxS
github.com/Azure/go-ntlmssp v0.0.0-20180810175552-4a21cbd618b4/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4=
github.com/Didainius/go-vcloud-director/v2 v2.3.0-alpha.3.0.20190710123027-2756ed0823d2 h1:QDtxbnWBseaU7bjUsQOWbRPApBB46RJbdpRPE/DmbF0=
github.com/Didainius/go-vcloud-director/v2 v2.3.0-alpha.3.0.20190710123027-2756ed0823d2/go.mod h1:HonlGxbjJ1NAibWh99eE4/S2l6ZOZ5KJzKK1rh2a9vc=
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=
Expand Down Expand Up @@ -301,8 +303,6 @@ 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.8 h1:oTWf8R1eoJWHZxEPvuCWMnHJn3AbqdlSFThmrhaSqmA=
github.com/vmware/go-vcloud-director/v2 v2.3.0-alpha.8/go.mod h1:HonlGxbjJ1NAibWh99eE4/S2l6ZOZ5KJzKK1rh2a9vc=
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
7 changes: 7 additions & 0 deletions scripts/test-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ for CF in $test_names
do
file_count=$((file_count+1))
unset will_skip

skip_request=$(grep '^\s*#\s*skip-test' $CF)
if [ -n "$skip_request" ]
then
will_skip=1
fi

for skip_file in ${skipping_items[*]}
do
if [ "$CF" == "$skip_file" ]
Expand Down
10 changes: 5 additions & 5 deletions vcd/datasource_vcd_lb_app_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ func datasourceVcdLBAppProfile() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD organization in which the App Profile is located",
Description: "vCD organization in which the LB Application Profile is located",
},
"vdc": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD virtual datacenter in which the App Profile is located",
Description: "vCD virtual datacenter in which the LB Application Profile is located",
},
"edge_gateway": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Edge gateway name in which the App Profile is located",
Description: "Edge gateway name in which the LB Application Profile is located",
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "App Profile name for lookup",
Description: "LB Application Profile name for lookup",
},
"type": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -104,7 +104,7 @@ func datasourceVcdLBAppProfileRead(d *schema.ResourceData, meta interface{}) err

readLBAppProfile, err := edgeGateway.ReadLBAppProfileByName(d.Get("name").(string))
if err != nil {
return fmt.Errorf("unable to find load balancer app profile with Name %s: %s",
return fmt.Errorf("unable to find load balancer application profile with Name %s: %s",
d.Get("name").(string), err)
}

Expand Down
61 changes: 61 additions & 0 deletions vcd/datasource_vcd_lb_app_rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package vcd

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
)

func datasourceVcdLBAppRule() *schema.Resource {
return &schema.Resource{
Read: datasourceVcdLBAppRuleRead,
Schema: map[string]*schema.Schema{
"org": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD organization in which the LB Application Rule is located",
},
"vdc": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD virtual datacenter in which the LB Application Rule is located",
},
"edge_gateway": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Edge gateway name in which the LB Application Rule is located",
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "LB Application Rule name for lookup",
},
"script": {
Computed: true,
Type: schema.TypeString,
Description: "The script for the LB Application Rule. Each line will be separated " +
dataclouder marked this conversation as resolved.
Show resolved Hide resolved
"by \n characters",
},
},
}
}

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

readLBAppRule, err := edgeGateway.ReadLBAppRuleByName(d.Get("name").(string))
if err != nil {
return fmt.Errorf("unable to find load balancer application rule with Name %s: %s",
d.Get("name").(string), err)
}

d.SetId(readLBAppRule.ID)
return setLBAppRuleData(d, readLBAppRule)
}
6 changes: 3 additions & 3 deletions vcd/datasource_vcd_lb_server_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ func datasourceVcdLbServerPool() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD organization in which the Service Monitor is located",
Description: "vCD organization in which the LB Server Pool is located",
},
"vdc": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD virtual datacenter in which the Service Monitor is located",
Description: "vCD virtual datacenter in which the LB Server Pool is located",
},
"edge_gateway": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Edge gateway name in which the Server Pool is located",
Description: "Edge gateway name in which the LB Server Pool is located",
},
"name": &schema.Schema{
Type: schema.TypeString,
Expand Down
8 changes: 4 additions & 4 deletions vcd/datasource_vcd_lb_service_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ func datasourceVcdLbServiceMonitor() *schema.Resource {
"org": {
Type: schema.TypeString,
Optional: true,
Description: "vCD organization in which the Service Monitor is located",
Description: "vCD organization in which the LB Service Monitor is located",
},
"vdc": {
Type: schema.TypeString,
Optional: true,
Description: "vCD virtual datacenter in which the Service Monitor is located",
Description: "vCD virtual datacenter in which the LB Service Monitor is located",
},
"edge_gateway": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Edge gateway name in which the Service Monitor is located",
Description: "Edge gateway name in which the LB Service Monitor is located",
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
Description: "Service Monitor name",
Description: "LB Service Monitor name",
},
"interval": &schema.Schema{
Type: schema.TypeInt,
Expand Down
2 changes: 2 additions & 0 deletions vcd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ func Provider() terraform.ResourceProvider {
"vcd_lb_service_monitor": resourceVcdLbServiceMonitor(), // 2.4
"vcd_lb_server_pool": resourceVcdLBServerPool(), // 2.4
"vcd_lb_app_profile": resourceVcdLBAppProfile(), // 2.4
"vcd_lb_app_rule": resourceVcdLBAppRule(), // 2.4
},

DataSourcesMap: map[string]*schema.Resource{
"vcd_lb_service_monitor": datasourceVcdLbServiceMonitor(), // 2.4
"vcd_lb_server_pool": datasourceVcdLbServerPool(), // 2.4
"vcd_lb_app_profile": datasourceVcdLBAppProfile(), // 2.4
"vcd_lb_app_rule": datasourceVcdLBAppRule(), // 2.4
},

ConfigureFunc: providerConfigure,
Expand Down
2 changes: 1 addition & 1 deletion vcd/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build api functional catalog vapp network extnetwork org query vm vdc gateway disk binary lb lbAppProfile lbServiceMonitor lbServerPool ALL
// +build api functional catalog vapp network extnetwork org query vm vdc gateway disk binary lb lbAppProfile lbAppRule lbServiceMonitor lbServerPool ALL

package vcd

Expand Down
22 changes: 11 additions & 11 deletions vcd/resource_vcd_lb_app_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ func resourceVcdLBAppProfile() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD organization in which the Application Profile is located",
Description: "vCD organization in which the LB Application Profile is located",
},
"vdc": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "vCD virtual datacenter in which the Application Profile is located",
Description: "vCD virtual datacenter in which the LB Application Profile is located",
},
"edge_gateway": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Edge gateway name in which the Application Profile is located",
Description: "Edge gateway name in which the LB Application Profile is located",
},
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Unique Application Profile name",
Description: "Unique LB Application Profile name",
},
"type": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -123,12 +123,12 @@ func resourceVcdLBAppProfileCreate(d *schema.ResourceData, meta interface{}) err

LBProfile, err := getLBAppProfileType(d)
if err != nil {
return fmt.Errorf("unable to expand load balancer app profile: %s", err)
return fmt.Errorf("unable to create load balancer application profile type: %s", err)
}

createdPool, err := edgeGateway.CreateLBAppProfile(LBProfile)
if err != nil {
return fmt.Errorf("error creating new load balancer app profile: %s", err)
return fmt.Errorf("error creating new load balancer application profile: %s", err)
}

// We store the values once again because response include pool member IDs
Expand All @@ -151,7 +151,7 @@ func resourceVcdLBAppProfileRead(d *schema.ResourceData, meta interface{}) error
readLBProfile, err := edgeGateway.ReadLBAppProfileByID(d.Id())
if err != nil {
d.SetId("")
return fmt.Errorf("unable to find load balancer app profile with ID %s: %s", d.Id(), err)
return fmt.Errorf("unable to find load balancer application profile with ID %s: %s", d.Id(), err)
}

return setLBAppProfileData(d, readLBProfile)
Expand All @@ -169,12 +169,12 @@ func resourceVcdLBAppProfileUpdate(d *schema.ResourceData, meta interface{}) err

updateLBProfileConfig, err := getLBAppProfileType(d)
if err != nil {
return fmt.Errorf("could not expand load balancer app profile for update: %s", err)
return fmt.Errorf("unable to create load balancer application profile type for update: %s", err)
}

updatedLBProfile, err := edgeGateway.UpdateLBAppProfile(updateLBProfileConfig)
if err != nil {
return fmt.Errorf("unable to update load balancer app profile with ID %s: %s", d.Id(), err)
return fmt.Errorf("unable to update load balancer application profile with ID %s: %s", d.Id(), err)
}

if err := setLBAppProfileData(d, updatedLBProfile); err != nil {
Expand All @@ -196,7 +196,7 @@ func resourceVcdLBAppProfileDelete(d *schema.ResourceData, meta interface{}) err

err = edgeGateway.DeleteLBAppProfileByID(d.Id())
if err != nil {
return fmt.Errorf("error deleting load balancer app profile: %s", err)
return fmt.Errorf("error deleting load balancer application profile: %s", err)
}

d.SetId("")
Expand Down Expand Up @@ -224,7 +224,7 @@ func resourceVcdLBAppProfileImport(d *schema.ResourceData, meta interface{}) ([]

readLBProfile, err := edgeGateway.ReadLBAppProfileByName(appProfileName)
if err != nil {
return []*schema.ResourceData{}, fmt.Errorf("unable to find load balancer app profile with name %s: %s",
return []*schema.ResourceData{}, fmt.Errorf("unable to find load balancer application profile with name %s: %s",
d.Id(), err)
}

Expand Down
4 changes: 3 additions & 1 deletion vcd/resource_vcd_lb_app_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
"testing"

"github.com/vmware/go-vcloud-director/v2/govcd"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/vmware/go-vcloud-director/v2/types/v56"
Expand Down Expand Up @@ -174,7 +176,7 @@ func testAccCheckVcdLBAppProfileDestroy(appProfileName string) resource.TestChec
}

monitor, err := edgeGateway.ReadLBAppProfile(&types.LBAppProfile{Name: appProfileName})
if !strings.Contains(err.Error(), "could not find load balancer application profile") ||
if !strings.Contains(err.Error(), govcd.ErrorEntityNotFound.Error()) ||
monitor != nil {
return fmt.Errorf("load balancer application profile was not deleted: %s", err)
}
Expand Down
Loading