diff --git a/flexibleengine/resource_flexibleengine_cce_cluster_v3.go b/flexibleengine/resource_flexibleengine_cce_cluster_v3.go index 0608137a2..68edeb0fe 100644 --- a/flexibleengine/resource_flexibleengine_cce_cluster_v3.go +++ b/flexibleengine/resource_flexibleengine_cce_cluster_v3.go @@ -3,6 +3,7 @@ package flexibleengine import ( "fmt" "log" + "strings" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -119,6 +120,23 @@ func resourceCCEClusterV3() *schema.Resource { ForceNew: true, ValidateFunc: validateIP, }, + "masters": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Computed: true, + MaxItems: 3, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "availability_zone": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, + }, + }, + }, "status": { Type: schema.TypeString, Computed: true, @@ -208,6 +226,31 @@ func resourceClusterExtendParamV3(d *schema.ResourceData) map[string]string { return m } +func resourceClusterMastersV3(d *schema.ResourceData) ([]clusters.MasterSpec, error) { + if v, ok := d.GetOk("masters"); ok { + flavorId := d.Get("flavor_id").(string) + mastersRaw := v.([]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 + } + + return nil, nil +} + func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) cceClient, err := config.cceV3Client(GetRegion(d, config)) @@ -236,6 +279,12 @@ func resourceCCEClusterV3Create(d *schema.ResourceData, meta interface{}) error } } + masters, err := resourceClusterMastersV3(d) + if err != nil { + return err + } + spec.Masters = masters + createOpts := clusters.CreateOpts{ Kind: "Cluster", ApiVersion: "v3", @@ -333,6 +382,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/flexibleengine/resource_flexibleengine_cce_cluster_v3_test.go b/flexibleengine/resource_flexibleengine_cce_cluster_v3_test.go index d7c8d52f5..01a1eac57 100644 --- a/flexibleengine/resource_flexibleengine_cce_cluster_v3_test.go +++ b/flexibleengine/resource_flexibleengine_cce_cluster_v3_test.go @@ -33,11 +33,11 @@ func TestAccCCEClusterV3_basic(t *testing.T) { resource.TestCheckResourceAttr( "flexibleengine_cce_cluster_v3.cluster_1", "flavor_id", "cce.s1.small"), resource.TestCheckResourceAttr( - "flexibleengine_cce_cluster_v3.cluster_1", "cluster_version", "v1.11.7"), + "flexibleengine_cce_cluster_v3.cluster_1", "cluster_version", "v1.11.7-r2"), resource.TestCheckResourceAttr( "flexibleengine_cce_cluster_v3.cluster_1", "container_network_type", "overlay_l2"), resource.TestCheckResourceAttr( - "flexibleengine_cce_cluster_v3.cluster_1", "authentication_mode", "x509"), + "flexibleengine_cce_cluster_v3.cluster_1", "authentication_mode", "rbac"), ), }, { @@ -131,7 +131,7 @@ resource "flexibleengine_cce_cluster_v3" "cluster_1" { name = "%s" cluster_type="VirtualMachine" flavor_id="cce.s1.small" - cluster_version = "v1.11.7" + cluster_version = "v1.11.7-r2" vpc_id="%s" subnet_id="%s" container_network_type="overlay_l2" @@ -144,7 +144,7 @@ resource "flexibleengine_cce_cluster_v3" "cluster_1" { name = "%s" cluster_type="VirtualMachine" flavor_id="cce.s1.small" - cluster_version = "v1.11.7" + cluster_version = "v1.11.7-r2" vpc_id="%s" subnet_id="%s" container_network_type="overlay_l2" 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 3a9c2a06e..110fa3e06 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 @@ -60,6 +60,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 @@ -90,6 +92,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/website/docs/r/cce_cluster_v3.html.md b/website/docs/r/cce_cluster_v3.html.md index e34390ca3..31d614efd 100644 --- a/website/docs/r/cce_cluster_v3.html.md +++ b/website/docs/r/cce_cluster_v3.html.md @@ -84,6 +84,13 @@ The following arguments are supported: * `eip` - (Optional) EIP address of the cluster. Changing this parameter will create a new cluster resource. +* `masters` - (Optional, List, ForceNew) Advanced configuration of master nodes. 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 All above argument parameters can be exported as attribute parameters along with attribute reference.