Skip to content

Commit

Permalink
support param masters in cce cluster (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 authored Feb 1, 2021
1 parent bc1ae36 commit 01d3878
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 12 deletions.
9 changes: 8 additions & 1 deletion docs/resources/cce_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
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-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=
Expand Down
62 changes: 59 additions & 3 deletions huaweicloud/resource_huaweicloud_cce_cluster_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package huaweicloud
import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01d3878

Please sign in to comment.