From b6ee54effe4c2c859c4e8a4fa27eb49a308372fa Mon Sep 17 00:00:00 2001 From: Jason Zhang Date: Sat, 30 Jan 2021 16:08:36 +0800 Subject: [PATCH] support param masters in cce cluster --- docs/resources/cce_cluster.md | 9 ++- go.mod | 2 +- go.sum | 8 +-- .../resource_huaweicloud_cce_cluster_v3.go | 62 ++++++++++++++++++- .../openstack/cce/v3/clusters/results.go | 7 +++ vendor/modules.txt | 2 +- 6 files changed, 78 insertions(+), 12 deletions(-) diff --git a/docs/resources/cce_cluster.md b/docs/resources/cce_cluster.md index 5f00de00df..53f4eb9db4 100644 --- a/docs/resources/cce_cluster.md +++ b/docs/resources/cce_cluster.md @@ -134,7 +134,11 @@ versions are available, choose Dashboard > Buy Cluster on the CCE console. Chang * `authenticating_proxy_ca` - (Optional, String, ForceNew) CA root certificate provided in the authenticating_proxy mode. The CA root certificate is encoded to the Base64 format. Changing this parameter will create a new cluster resource. -* `multi_az` - (Optional, Bool, ForceNew) Enable multiple AZs for the cluster, only when using HA flavors. Changing this parameter will create a new cluster resource. +* `multi_az` - (Optional, Bool, ForceNew) Enable multiple AZs for the cluster, only when using HA flavors. + Changing this parameter will create a new cluster resource. This parameter and `masters` are alternative + +* `masters` - (Optional, List, ForceNew) Advanced configuration of master nodes. Changing this creates a new cluster. + This parameter and `multi_az` are alternative. * `eip` - (Optional, String, ForceNew) EIP address of the cluster. Changing this parameter will create a new cluster resource. @@ -145,6 +149,9 @@ versions are available, choose Dashboard > Buy Cluster on the CCE console. Chang * `enterprise_project_id` - (Optional, String, ForceNew) The enterprise project id of the cce cluster. Changing this creates a new cluster. +The `masters` block supports: + +* `availability_zone` - (Optional, String, ForceNew) Specifies the availability zone of the master node. Changing this creates a new cluster. ## Attributes Reference In addition to all arguments above, the following attributes are exported: diff --git a/go.mod b/go.mod index b081556a05..e6c9bd1594 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( 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-20210128073103-0683919fcabd + github.com/huaweicloud/golangsdk v0.0.0-20210130015616-a15f013de8ca 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 diff --git a/go.sum b/go.sum index ff78186b92..6003bd34c5 100644 --- a/go.sum +++ b/go.sum @@ -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-20210121015204-d66fe0197517 h1:l/Aa5CisHTWEg5ZEvNPRlrfxkCDEgYQieJRqFlthkXw= -github.com/huaweicloud/golangsdk v0.0.0-20210121015204-d66fe0197517/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= -github.com/huaweicloud/golangsdk v0.0.0-20210126090908-31d3a6a5cee7 h1:7CkjSplJmYll80TgMsjhYy7PMLNPjBMtnuEPhDf/NvU= -github.com/huaweicloud/golangsdk v0.0.0-20210126090908-31d3a6a5cee7/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= -github.com/huaweicloud/golangsdk v0.0.0-20210128073103-0683919fcabd h1:jHD4wEEoUCkbsf4Vlm5TeFKHdyxnjoYoTGe0E6tJgHo= -github.com/huaweicloud/golangsdk v0.0.0-20210128073103-0683919fcabd/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= +github.com/huaweicloud/golangsdk v0.0.0-20210130015616-a15f013de8ca h1:ucLVgXpwEIbvBZn6OeEz9/gtIxBWDYRHgef44HkYp5o= +github.com/huaweicloud/golangsdk v0.0.0-20210130015616-a15f013de8ca/go.mod h1:fcOI5u+0f62JtJd7zkCch/Z57BNC6bhqb32TKuiF4r0= 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= diff --git a/huaweicloud/resource_huaweicloud_cce_cluster_v3.go b/huaweicloud/resource_huaweicloud_cce_cluster_v3.go index 42c8bf1cd8..84cbf4897a 100644 --- a/huaweicloud/resource_huaweicloud_cce_cluster_v3.go +++ b/huaweicloud/resource_huaweicloud_cce_cluster_v3.go @@ -3,6 +3,7 @@ package huaweicloud import ( "fmt" "log" + "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -124,9 +125,28 @@ func ResourceCCEClusterV3() *schema.Resource { ForceNew: true, }, "multi_az": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + ConflictsWith: []string{"masters"}, + }, + "masters": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Computed: true, + MaxItems: 3, + ConflictsWith: []string{"multi_az"}, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "availability_zone": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, + }, + }, }, "eip": { Type: schema.TypeString, @@ -238,6 +258,27 @@ func resourceClusterExtendParamV3(d *schema.ResourceData, config *Config) map[st return m } +func resourceClusterMastersV3(d *schema.ResourceData) ([]clusters.MasterSpec, error) { + flavorId := d.Get("flavor_id").(string) + mastersRaw := d.Get("masters").([]interface{}) + if strings.Contains(flavorId, "s1") && len(mastersRaw) != 1 { + return nil, fmt.Errorf("Error creating HuaweiCloud Cluster: "+ + "single-master cluster need 1 az for master node, but got %d", len(mastersRaw)) + } + if strings.Contains(flavorId, "s2") && len(mastersRaw) != 3 { + return nil, fmt.Errorf("Error creating HuaweiCloud Cluster: "+ + "high-availability cluster need 3 az for master nodes, but got %d", len(mastersRaw)) + } + masters := make([]clusters.MasterSpec, len(mastersRaw)) + for i, raw := range mastersRaw { + rawMap := raw.(map[string]interface{}) + masters[i] = clusters.MasterSpec{ + MasterAZ: rawMap["availability_zone"].(string), + } + } + return masters, nil +} + func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) cceClient, err := config.CceV3Client(GetRegion(d, config)) @@ -279,6 +320,12 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error }, } + masters, err := resourceClusterMastersV3(d) + if err != nil { + return err + } + createOpts.Spec.Masters = masters + create, err := clusters.Create(cceClient, createOpts).Extract() if err != nil { @@ -378,6 +425,15 @@ func resourceCCEClusterV3Read(d *schema.ResourceData, meta interface{}) error { } d.Set("certificate_users", userList) + // Set masters + var masterList []map[string]interface{} + for _, masterObj := range n.Spec.Masters { + master := make(map[string]interface{}) + master["availability_zone"] = masterObj.MasterAZ + masterList = append(masterList, master) + } + d.Set("masters", masterList) + return nil } diff --git a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters/results.go b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters/results.go index 71d9ccb724..b48f4db7c7 100644 --- a/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters/results.go +++ b/vendor/github.com/huaweicloud/golangsdk/openstack/cce/v3/clusters/results.go @@ -62,6 +62,8 @@ type Spec struct { BillingMode int `json:"billingMode,omitempty"` //Extended parameter for a cluster ExtendParam map[string]string `json:"extendParam,omitempty"` + //Advanced configuration of master node + Masters []MasterSpec `json:"masters,omitempty"` } // Node network parameters @@ -92,6 +94,11 @@ type AuthenticationSpec struct { AuthenticatingProxy map[string]string `json:"authenticatingProxy" required:"true"` } +type MasterSpec struct { + // AZ of master node + MasterAZ string `json:"availabilityZone,omitempty"` +} + type Status struct { //The state of the cluster Phase string `json:"phase"` diff --git a/vendor/modules.txt b/vendor/modules.txt index ab5e3e2d4f..a2822272a3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -186,7 +186,7 @@ github.com/hashicorp/terraform-svchost/auth github.com/hashicorp/terraform-svchost/disco # github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d github.com/hashicorp/yamux -# github.com/huaweicloud/golangsdk v0.0.0-20210128073103-0683919fcabd +# github.com/huaweicloud/golangsdk v0.0.0-20210130015616-a15f013de8ca ## explicit github.com/huaweicloud/golangsdk github.com/huaweicloud/golangsdk/internal