Skip to content

Commit

Permalink
Merge pull request #155 from yunify/add-endpoint-check
Browse files Browse the repository at this point in the history
add endpoint&zone check
  • Loading branch information
runzexia authored Jul 6, 2018
2 parents 068d582 + dfef79c commit 9c22d17
Show file tree
Hide file tree
Showing 2,400 changed files with 611,856 additions and 369,690 deletions.
3 changes: 2 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import:
- terraform

- package: github.com/yunify/qingcloud-sdk-go
version: v2.0.0-alpha.32
subpackages:
- config
- service
- service
6 changes: 5 additions & 1 deletion qingcloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {

type QingCloudClient struct {
zone string
qingcloud *qc.QingCloudService
job *qc.JobService
eip *qc.EIPService
keypair *qc.KeyPairService
Expand Down Expand Up @@ -92,8 +93,11 @@ func (c *Config) Client() (*QingCloudClient, error) {
return nil, err
}
userdata, err := clt.UserData(c.Zone)

if err != nil {
return nil, err
}
return &QingCloudClient{
qingcloud: clt,
zone: c.Zone,
job: job,
eip: eip,
Expand Down
2 changes: 2 additions & 0 deletions qingcloud/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
qingcloudResourceTypeRouter = "router"
qingcloudResourceTypeLoadBalancer = "loadbalancer"

StatusActive = "active"

DEFAULT_ZONE = "pek3a"
DEFAULT_ENDPOINT = "https://api.qingcloud.com:443/iaas"
waitJobTimeOutDefault = 240
Expand Down
27 changes: 27 additions & 0 deletions qingcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
package qingcloud

import (
"fmt"
"os"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
qc "github.com/yunify/qingcloud-sdk-go/service"
)

func Provider() terraform.ResourceProvider {
Expand Down Expand Up @@ -97,6 +99,31 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
Zone: zone.(string),
EndPoint: endpoint.(string),
}
client, err := config.Client()
if err != nil {
return nil, err
}
// check zone & endpoint
describeZonesOutput, err := client.qingcloud.DescribeZones(nil)
if err != nil {
return nil, err
}
if len(describeZonesOutput.ZoneSet) == 0 {
return nil, fmt.Errorf("can not get zone info")
}
i := 0
for _, az := range describeZonesOutput.ZoneSet {
if qc.StringValue(az.ZoneID) == zone {
if qc.StringValue(az.Status) != StatusActive {
return nil, fmt.Errorf(" zone: %s", qc.StringValue(az.Status))
}
break
}
i++
}
if i == len(describeZonesOutput.ZoneSet) {
return nil, fmt.Errorf("can not find zone: %s", zone)
}
return config.Client()
}

Expand Down
21 changes: 17 additions & 4 deletions qingcloud/resource_qingcloud_loadbalancer_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ func resourceQingcloudLoadBalancerListener() *schema.Resource {
ValidateFunc: withinArrayString("roundrobin", "leastconn", "source"),
},
resourceLoadBalancerListenerServerCertificateId: &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
resourceLoadBalancerListenerSessionSticky: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -115,7 +117,11 @@ func resourceQingcloudLoadBalancerListnerCreate(d *schema.ResourceData, meta int
listener.ListenerProtocol = getSetStringPointer(d, resourceLoadBalancerListenerProtocol)
listener.BackendProtocol = getSetStringPointer(d, resourceLoadBalancerListenerProtocol)
listener.BalanceMode = getSetStringPointer(d, resourceLoadBalancerListenerBalancerMode)
listener.ServerCertificateID = getSetStringPointer(d, resourceLoadBalancerListenerServerCertificateId)
if len(d.Get(resourceLoadBalancerListenerServerCertificateId).(*schema.Set).List()) > 0 {
for _, value := range d.Get(resourceLoadBalancerListenerServerCertificateId).(*schema.Set).List() {
listener.ServerCertificateID = append(listener.ServerCertificateID, qc.String(value.(string)))
}
}
listener.SessionSticky = getSetStringPointer(d, resourceLoadBalancerListenerSessionSticky)
listener.Forwardfor = qc.Int(d.Get(resourceLoadBalancerListenerForwardfor).(int))
listener.HealthyCheckMethod = getSetStringPointer(d, resourceLoadBalancerListenerHealthCheckMethod)
Expand Down Expand Up @@ -162,7 +168,7 @@ func resourceQingcloudLoadBalancerListenerRead(d *schema.ResourceData, meta inte
d.Set(resourceLoadBalancerListenerPort, qc.IntValue(output.LoadBalancerListenerSet[0].ListenerPort))
d.Set(resourceLoadBalancerListenerProtocol, qc.StringValue(output.LoadBalancerListenerSet[0].ListenerProtocol))
d.Set(resourceLoadBalancerListenerBalancerMode, qc.StringValue(output.LoadBalancerListenerSet[0].BalanceMode))
d.Set(resourceLoadBalancerListenerServerCertificateId, qc.StringValue(output.LoadBalancerListenerSet[0].ServerCertificateID))
d.Set(resourceLoadBalancerListenerServerCertificateId, qc.StringValueSlice(output.LoadBalancerListenerSet[0].ServerCertificateID))
d.Set(resourceLoadBalancerListenerSessionSticky, qc.StringValue(output.LoadBalancerListenerSet[0].SessionSticky))
d.Set(resourceLoadBalancerListenerForwardfor, qc.IntValue(output.LoadBalancerListenerSet[0].Forwardfor))
d.Set(resourceLoadBalancerListenerHealthCheckMethod, qc.StringValue(output.LoadBalancerListenerSet[0].HealthyCheckMethod))
Expand All @@ -178,7 +184,14 @@ func resourceQingcloudLoadBalancerListenerUpdate(d *schema.ResourceData, meta in
input.LoadBalancerListener = qc.String(d.Id())
input.LoadBalancerListenerName = getSetStringPointer(d, resourceName)
input.BalanceMode = getSetStringPointer(d, resourceLoadBalancerListenerBalancerMode)
input.ServerCertificateID = getSetStringPointer(d, resourceLoadBalancerListenerServerCertificateId)
if d.HasChange(resourceLoadBalancerListenerServerCertificateId) {
if len(d.Get(resourceLoadBalancerListenerServerCertificateId).(*schema.Set).List()) == 0 {
input.ServerCertificateID = append(input.ServerCertificateID, qc.String(" "))
}
for _, value := range d.Get(resourceLoadBalancerListenerServerCertificateId).(*schema.Set).List() {
input.ServerCertificateID = append(input.ServerCertificateID, qc.String(value.(string)))
}
}
input.SessionSticky = getSetStringPointer(d, resourceLoadBalancerListenerSessionSticky)
input.Forwardfor = qc.Int(d.Get(resourceLoadBalancerListenerForwardfor).(int))
input.HealthyCheckMethod = getSetStringPointer(d, resourceLoadBalancerListenerHealthCheckMethod)
Expand Down
4 changes: 2 additions & 2 deletions qingcloud/resource_qingcloud_loadbalancer_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ resource "qingcloud_loadbalancer_listener" "foo"{
load_balancer_id = "${qingcloud_loadbalancer.foo.id}"
listener_port = "443"
listener_protocol = "https"
server_certificate_id = "${qingcloud_server_certificate.foo.id}"
server_certificate_id = ["${qingcloud_server_certificate.foo.id}"]
listener_option = 256
}
Expand Down Expand Up @@ -274,7 +274,7 @@ resource "qingcloud_loadbalancer_listener" "foo"{
load_balancer_id = "${qingcloud_loadbalancer.foo.id}"
listener_port = "443"
listener_protocol = "https"
server_certificate_id = "${qingcloud_server_certificate.foo.id}"
server_certificate_id = ["${qingcloud_server_certificate.foo.id}"]
listener_option = 207
healthy_check_method = "http|/index.html|vhost.example.com"
healthy_check_option = "10|5|5|5"
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/.github/ISSUE_TEMPLATE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/aws/aws-sdk-go/.godoc_config

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 40 additions & 21 deletions vendor/github.com/aws/aws-sdk-go/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9c22d17

Please sign in to comment.