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 ELB v3 monitors #1163

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
58 changes: 58 additions & 0 deletions docs/resources/elb_monitor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
subcategory: "Dedicated Load Balance (Dedicated ELB)"
---

# huaweicloud\_elb\_monitor

Manages an ELB monitor resource within HuaweiCloud.

## Example Usage

```hcl
resource "huaweicloud_elb_monitor" "monitor_1" {
protocol = "HTTP"
interval = 30
timeout = 15
max_retries = 10
url_path = "/api"
port = 8888
pool_id = huaweicloud_elb_pool.test.id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) The region in which to create the ELB monitor resource.
If omitted, the provider-level region will be used.
Changing this creates a new monitor.

* `pool_id` - (Required, String, ForceNew) The id of the pool that this monitor will be assigned to.

* `protocol` - (Required, String, ForceNew) The type of probe, which is TCP, HTTP, or HTTPS,
that is sent by the load balancer to verify the member state. Changing this
creates a new monitor.

* `domain_name` - (Optional, String) The Domain Name of the Monitor.

* `port` - (Optional, Int) Specifies the health check port. The value ranges from 1 to 65535.

* `interval` - (Required, Int) The time, in seconds, between sending probes to members.

* `timeout` - (Required, Int) Maximum number of seconds for a monitor to wait for a
ping reply before it times out. The value must be less than the delay
value.

* `max_retries` - (Required, Int) Number of permissible ping failures before
changing the member's status to INACTIVE. Must be a number between 1
and 10.

* `url_path` - (Optional, String) Required for HTTP(S) types. URI path that will be
accessed if monitor type is HTTP or HTTPS.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The unique ID for the monitor.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/terraform-plugin-sdk v1.16.0
github.com/huaweicloud/golangsdk v0.0.0-20210524113822-7a55f63ba01a
github.com/huaweicloud/golangsdk v0.0.0-20210525085405-858f9079f00d
github.com/jen20/awspolicyequivalence v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
github.com/stretchr/testify v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/huaweicloud/golangsdk v0.0.0-20210524113822-7a55f63ba01a h1:YOG5x5keo4dVV542nonlxCha9V0UvpNFo+lhmfEbhwg=
github.com/huaweicloud/golangsdk v0.0.0-20210524113822-7a55f63ba01a/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/huaweicloud/golangsdk v0.0.0-20210525085405-858f9079f00d h1:0kH5vNsd5m/T1WqMmYZAOpVk75a/MZ6MmUSNLUrqOWY=
github.com/huaweicloud/golangsdk v0.0.0-20210525085405-858f9079f00d/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func Provider() terraform.ResourceProvider {
"huaweicloud_elb_l7rule": ResourceL7RuleV3(),
"huaweicloud_elb_listener": ResourceListenerV3(),
"huaweicloud_elb_loadbalancer": ResourceLoadBalancerV3(),
"huaweicloud_elb_monitor": ResourceMonitorV3(),
"huaweicloud_elb_ipgroup": ResourceIpGroupV3(),
"huaweicloud_elb_pool": ResourcePoolV3(),
"huaweicloud_elb_member": ResourceMemberV3(),
Expand Down
181 changes: 181 additions & 0 deletions huaweicloud/resource_huaweicloud_elb_monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package huaweicloud

import (
"fmt"
"log"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

"github.com/huaweicloud/golangsdk/openstack/elb/v3/monitors"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
)

func ResourceMonitorV3() *schema.Resource {
return &schema.Resource{
Create: resourceMonitorV3Create,
Read: resourceMonitorV3Read,
Update: resourceMonitorV3Update,
Delete: resourceMonitorV3Delete,

Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},

"domain_name": {
Type: schema.TypeString,
Optional: true,
},

"pool_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"protocol": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"interval": {
Type: schema.TypeInt,
Required: true,
},

"timeout": {
Type: schema.TypeInt,
Required: true,
},

"max_retries": {
Type: schema.TypeInt,
Required: true,
},

"port": {
Type: schema.TypeInt,
Optional: true,
},

"url_path": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
}
}

func resourceMonitorV3Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
lbClient, err := config.ElbV3Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating HuaweiCloud elb client: %s", err)
}

createOpts := monitors.CreateOpts{
PoolID: d.Get("pool_id").(string),
Type: d.Get("protocol").(string),
Delay: d.Get("interval").(int),
Timeout: d.Get("timeout").(int),
MaxRetries: d.Get("max_retries").(int),
URLPath: d.Get("url_path").(string),
DomainName: d.Get("domain_name").(string),
MonitorPort: d.Get("port").(int),
}

log.Printf("[DEBUG] Create Options: %#v", createOpts)
monitor, err := monitors.Create(lbClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Unable to create monitor: %s", err)
}

d.SetId(monitor.ID)

return resourceMonitorV3Read(d, meta)
}

func resourceMonitorV3Read(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
lbClient, err := config.ElbV3Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating HuaweiCloud elb client: %s", err)
}

monitor, err := monitors.Get(lbClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "monitor")
}

log.Printf("[DEBUG] Retrieved monitor %s: %#v", d.Id(), monitor)

d.Set("protocol", monitor.Type)
d.Set("interval", monitor.Delay)
d.Set("timeout", monitor.Timeout)
d.Set("max_retries", monitor.MaxRetries)
d.Set("url_path", monitor.URLPath)
d.Set("domain_name", monitor.DomainName)
d.Set("region", GetRegion(d, config))
if monitor.MonitorPort != 0 {
d.Set("port", monitor.MonitorPort)
}

return nil
}

func resourceMonitorV3Update(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
lbClient, err := config.ElbV3Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating HuaweiCloud elb client: %s", err)
}

var updateOpts monitors.UpdateOpts
if d.HasChange("url_path") {
updateOpts.URLPath = d.Get("url_path").(string)
}
if d.HasChange("interval") {
updateOpts.Delay = d.Get("interval").(int)
}
if d.HasChange("timeout") {
updateOpts.Timeout = d.Get("timeout").(int)
}
if d.HasChange("max_retries") {
updateOpts.MaxRetries = d.Get("max_retries").(int)
}
if d.HasChange("domain_name") {
updateOpts.DomainName = d.Get("domain_name").(string)
}
if d.HasChange("port") {
updateOpts.MonitorPort = d.Get("port").(int)
}

log.Printf("[DEBUG] Updating monitor %s with options: %#v", d.Id(), updateOpts)
_, err = monitors.Update(lbClient, d.Id(), updateOpts).Extract()
if err != nil {
return fmt.Errorf("Unable to update monitor %s: %s", d.Id(), err)
}

return resourceMonitorV3Read(d, meta)
}

func resourceMonitorV3Delete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*config.Config)
lbClient, err := config.ElbV3Client(GetRegion(d, config))
if err != nil {
return fmt.Errorf("Error creating HuaweiCloud elb client: %s", err)
}

log.Printf("[DEBUG] Deleting monitor %s", d.Id())
err = monitors.Delete(lbClient, d.Id()).ExtractErr()
if err != nil {
return fmt.Errorf("Unable to delete monitor %s: %s", d.Id(), err)
}

return nil
}
Loading