Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…form-provider-huaweicloud into cce-kubeporxymod
  • Loading branch information
yangshuai committed Jul 31, 2020
2 parents 3ee0538 + 0b6f035 commit 31cd5a6
Show file tree
Hide file tree
Showing 48 changed files with 805 additions and 7,359 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module github.com/terraform-providers/terraform-provider-huaweicloud

go 1.14

require (
github.com/aws/aws-sdk-go v1.25.3
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/terraform-plugin-sdk v1.13.0
github.com/huaweicloud/golangsdk v0.0.0-20200721081039-51b301b04100
github.com/huaweicloud/golangsdk v0.0.0-20200728004128-63646e8b1ea7
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a
github.com/mitchellh/go-homedir v1.1.0
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,8 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS
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-20200719033133-e6883dd4cac6 h1:7gIUBTKXTHUJQFlJMUejFG6WOtz1d2ZLOOwD/BCIHMs=
github.com/huaweicloud/golangsdk v0.0.0-20200719033133-e6883dd4cac6/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
github.com/huaweicloud/golangsdk v0.0.0-20200721030010-4ccadda0c1d0 h1:v0WvhM9CBkbxy8kGhLc0MsQc8zzOlrgWqc/FcgvhGGk=
github.com/huaweicloud/golangsdk v0.0.0-20200721030010-4ccadda0c1d0/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
github.com/huaweicloud/golangsdk v0.0.0-20200721081039-51b301b04100 h1:jbgMKCCuT/jb/x3peMLgcWYKRcKzWP5LUC+3uv2U8fI=
github.com/huaweicloud/golangsdk v0.0.0-20200721081039-51b301b04100/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
github.com/huaweicloud/golangsdk v0.0.0-20200728004128-63646e8b1ea7 h1:ZczeotQ12mnp9sAPdO8+1J60I7e7O4PfYmw8abeu+UM=
github.com/huaweicloud/golangsdk v0.0.0-20200728004128-63646e8b1ea7/go.mod h1:WQBcHRNX9shz3928lWEvstQJtAtYI7ks6XlgtRT9Tcw=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a h1:FyS/ubzBR5xJlnJGRTwe7GUHpJOR4ukYK3y+LFNffuA=
github.com/jen20/awspolicyequivalence v0.0.0-20170831201602-3d48364a137a/go.mod h1:uoIMjNxUfXi48Ci40IXkPRbghZ1vbti6v9LCbNqRgHY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down
30 changes: 29 additions & 1 deletion huaweicloud/custom_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package huaweicloud

import (
"fmt"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand All @@ -28,6 +29,20 @@ func expandCdmClusterV1CreateClusterIsScheduleBootOff(d interface{}, arrayIndex
}

func checkCssClusterV1ExtendClusterFinished(data interface{}) bool {
//actions --- the behaviors on a cluster
v, err := navigateValue(data, []string{"actions"}, nil)
e, err := isEmptyValue(reflect.ValueOf(v))
if err == nil && !e {
return false
}

//actionProgress --- indicates the progress in percentage
v, err = navigateValue(data, []string{"actionProgress"}, nil)
e, err = isEmptyValue(reflect.ValueOf(v))
if err == nil && !e {
return false
}

instances, err := navigateValue(data, []string{"instances"}, nil)
if err != nil {
return false
Expand Down Expand Up @@ -57,7 +72,20 @@ func expandCssClusterV1ExtendClusterNodeNum(d interface{}, arrayIndex map[string
oldv, newv := rd.GetChange("expect_node_num")
v := newv.(int) - oldv.(int)
if v < 0 {
return 0, fmt.Errorf("it only supports extending nodes")
return 0, fmt.Errorf("expect_node_num only supports to be extended")
}
return v, nil
}

func expandCssClusterV1ExtendClusterVolumeSize(d interface{}, arrayIndex map[string]int) (interface{}, error) {
t, _ := navigateValue(d, []string{"terraform_resource_data"}, nil)
rd := t.(*schema.ResourceData)

//volume size location: reference to the Schema of css_cluster_v1
oldv, newv := rd.GetChange("node_config.0.volume.0.size")
v := newv.(int) - oldv.(int)
if v < 0 {
return 0, fmt.Errorf("volume size only supports to be extended")
}
return v, nil
}
Expand Down
9 changes: 4 additions & 5 deletions huaweicloud/resource_huaweicloud_cce_cluster_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func resourceCCEClusterV3() *schema.Resource {
"kube_proxy_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"status": {
Type: schema.TypeString,
Expand Down Expand Up @@ -204,7 +205,7 @@ func resourceClusterExtendParamV3(d *schema.ResourceData) map[string]string {
if multi_az, ok := d.GetOk("multi_az"); ok && multi_az == true {
m["clusterAZ"] = "multi_az"
}
if kube_proxy_mode, ok := d.GetOk("kube_proxy_mode"); ok{
if kube_proxy_mode, ok := d.GetOk("kube_proxy_mode"); ok {
m["kubeProxyMode"] = kube_proxy_mode.(string)
}
if eip, ok := d.GetOk("eip"); ok {
Expand All @@ -221,7 +222,6 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error
return fmt.Errorf("Unable to create HuaweiCloud CCE client : %s", err)
}


authenticating_proxy := make(map[string]string)
if hasFilledOpt(d, "authenticating_proxy_ca") {
authenticating_proxy["ca"] = d.Get("authenticating_proxy_ca").(string)
Expand All @@ -244,9 +244,8 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error
Cidr: d.Get("container_network_cidr").(string)},
Authentication: clusters.AuthenticationSpec{Mode: d.Get("authentication_mode").(string),
AuthenticatingProxy: authenticating_proxy},
BillingMode: d.Get("billing_mode").(int),
ExtendParam: resourceClusterExtendParamV3(d),
//KubeProxyMode: d.Get("kube_proxy_mode").(string),
BillingMode: d.Get("billing_mode").(int),
ExtendParam: resourceClusterExtendParamV3(d),
},
}

Expand Down
12 changes: 0 additions & 12 deletions huaweicloud/resource_huaweicloud_cce_node_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,6 @@ func resourceCCENodeV3Read(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("[DEBUG] Error saving root Volume to state for HuaweiCloud Node (%s): %s", d.Id(), err)
}

var tains []map[string]interface{}
for _, pairObject := range s.Spec.Taints {
tain := make(map[string]interface{})
tain["key"] = pairObject.Key
tain["value"] = pairObject.Value
tain["effect"] = pairObject.Effect
tains = append(tains, tain)
}
if err := d.Set("tains", tains); err != nil {
return fmt.Errorf("[DEBUG] Error saving root Volume to state for HuaweiCloud Node (%s): %s", d.Id(), err)
}

// set computed attributes
d.Set("private_ip", s.Status.PrivateIP)
d.Set("public_ip", s.Status.PublicIP)
Expand Down
5 changes: 5 additions & 0 deletions huaweicloud/resource_huaweicloud_cce_node_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ resource "huaweicloud_cce_node_v3" "test" {
size = 100
volumetype = "SATA"
}
taints {
key = "status"
value = "unavailable"
effect = "NoSchedule"
}
}
`, testAccCCENodeV3_Base(rName), updateName)
}
Expand Down
88 changes: 74 additions & 14 deletions huaweicloud/resource_huaweicloud_css_cluster_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/openstack/css/v1/snapshots"
)

func resourceCssClusterV1() *schema.Resource {
Expand Down Expand Up @@ -108,7 +109,6 @@ func resourceCssClusterV1() *schema.Resource {
"size": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"volume_type": {
Type: schema.TypeString,
Expand All @@ -130,25 +130,21 @@ func resourceCssClusterV1() *schema.Resource {
"backup_strategy": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start_time": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"keep_days": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
Default: 7,
},
"prefix": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "snapshot",
},
},
Expand Down Expand Up @@ -244,6 +240,14 @@ func resourceCssClusterV1Create(d *schema.ResourceData, meta interface{}) error
}
d.SetId(id.(string))

// enable snapshot function when "backup_strategy" was not specified
if len(d.Get("backup_strategy").([]interface{})) == 0 {
err = snapshots.Enable(client, d.Id()).ExtractErr()
if err != nil {
return fmt.Errorf("Error enable snapshot function: %s", err)
}
}

return resourceCssClusterV1Read(d, meta)
}

Expand All @@ -262,7 +266,32 @@ func resourceCssClusterV1Read(d *schema.ResourceData, meta interface{}) error {
}
res["read"] = fillCssClusterV1ReadRespBody(v)

return setCssClusterV1Properties(d, res)
if err := setCssClusterV1Properties(d, res); err != nil {
return err
}

// set backup strategy property
policy, err := snapshots.PolicyGet(client, d.Id()).Extract()
if err != nil {
return fmt.Errorf("Error extracting Cluster:backup_strategy, err: %s", err)
}

if policy.Enable == "true" {
strategy := []map[string]interface{}{
{
"prefix": policy.Prefix,
"start_time": policy.Period,
"keep_days": policy.KeepDay,
},
}
if err := d.Set("backup_strategy", strategy); err != nil {
return fmt.Errorf("Error setting Cluster:backup_strategy, err: %s", err)
}
} else {
d.Set("backup_strategy", nil)
}

return nil
}

func resourceCssClusterV1Update(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -296,6 +325,31 @@ func resourceCssClusterV1Update(d *schema.ResourceData, meta interface{}) error
}
}

// update backup strategy
if d.HasChange("backup_strategy") {
var opts = snapshots.PolicyCreateOpts{
Prefix: "snapshot",
Period: "00:00 GMT+08:00",
KeepDay: 7,
Enable: "false",
}

rawList := d.Get("backup_strategy").([]interface{})
if len(rawList) == 1 {
raw := rawList[0].(map[string]interface{})
opts = snapshots.PolicyCreateOpts{
Prefix: raw["prefix"].(string),
Period: raw["start_time"].(string),
KeepDay: raw["keep_days"].(int),
Enable: "true",
}
}
err := snapshots.PolicyCreate(client, &opts, d.Id()).ExtractErr()
if err != nil {
return fmt.Errorf("Error updating backup strategy: %s", err)
}
}

return resourceCssClusterV1Read(d, meta)
}

Expand Down Expand Up @@ -650,24 +704,30 @@ func buildCssClusterV1ExtendClusterParameters(opts map[string]interface{}, array
if err != nil {
return nil, err
}
if e, err := isEmptyValue(reflect.ValueOf(v)); err != nil {
params["nodesize"] = v

v, err = expandCssClusterV1ExtendClusterVolumeSize(opts, arrayIndex)
if err != nil {
return nil, err
} else if !e {
params["modifySize"] = v
}
params["disksize"] = v

if len(params) == 0 {
return params, nil
// both of nodesize and disksize can not be set to 0 simultaneously
if params["nodesize"].(int) == 0 && params["disksize"].(int) == 0 {
return nil, nil
}

params = map[string]interface{}{"grow": params}
params["type"] = "ess"
updateOpts := map[string]interface{}{
"grow": []map[string]interface{}{params},
}

return params, nil
return updateOpts, nil
}

func sendCssClusterV1ExtendClusterRequest(d *schema.ResourceData, params interface{},
client *golangsdk.ServiceClient) (interface{}, error) {
url, err := replaceVars(d, "clusters/{id}/extend", nil)
url, err := replaceVars(d, "clusters/{id}/role_extend", nil)
if err != nil {
return nil, err
}
Expand Down
56 changes: 27 additions & 29 deletions huaweicloud/resource_huaweicloud_dcs_instance_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,32 @@ func testAccCheckDcsV1InstanceExists(n string, instance instances.Instance) reso

func testAccDcsV1Instance_basic(instanceName string) string {
return fmt.Sprintf(`
resource "huaweicloud_networking_secgroup_v2" "secgroup_1" {
name = "secgroup_1"
description = "secgroup_1"
}
data "huaweicloud_dcs_az_v1" "az_1" {
port = "8002"
code = "%s"
}
data "huaweicloud_dcs_product_v1" "product_1" {
spec_code = "dcs.master_standby"
}
resource "huaweicloud_dcs_instance_v1" "instance_1" {
name = "%s"
engine_version = "3.0.7"
password = "Huawei_test"
engine = "Redis"
capacity = 2
vpc_id = "%s"
security_group_id = "${huaweicloud_networking_secgroup_v2.secgroup_1.id}"
subnet_id = "%s"
available_zones = ["${data.huaweicloud_dcs_az_v1.az_1.id}"]
product_id = "${data.huaweicloud_dcs_product_v1.product_1.id}"
save_days = 1
backup_type = "manual"
begin_at = "00:00-01:00"
period_type = "weekly"
backup_at = [1]
depends_on = ["data.huaweicloud_dcs_product_v1.product_1", "huaweicloud_networking_secgroup_v2.secgroup_1"]
}
resource "huaweicloud_networking_secgroup_v2" "secgroup_1" {
name = "secgroup_1"
description = "secgroup_1"
}
data "huaweicloud_dcs_az_v1" "az_1" {
port = "8002"
code = "%s"
}
resource "huaweicloud_dcs_instance_v1" "instance_1" {
name = "%s"
engine_version = "3.0"
password = "Huawei_test"
engine = "Redis"
capacity = 2
vpc_id = "%s"
security_group_id = "${huaweicloud_networking_secgroup_v2.secgroup_1.id}"
subnet_id = "%s"
available_zones = ["${data.huaweicloud_dcs_az_v1.az_1.id}"]
product_id = "dcs.master_standby-h"
save_days = 1
backup_type = "manual"
begin_at = "00:00-01:00"
period_type = "weekly"
backup_at = [1]
depends_on = ["huaweicloud_networking_secgroup_v2.secgroup_1"]
}
`, OS_AVAILABILITY_ZONE, instanceName, OS_VPC_ID, OS_NETWORK_ID)
}
Loading

0 comments on commit 31cd5a6

Please sign in to comment.