From 35a49a0585dfdc92f65437264c0d88a5935dac35 Mon Sep 17 00:00:00 2001 From: ShiChangkuo Date: Thu, 29 Oct 2020 14:49:31 +0800 Subject: [PATCH] [MRS] set node login mode default to key-pair --- .../resource_huaweicloud_mrs_cluster_v1.go | 84 +++++++++---------- 1 file changed, 39 insertions(+), 45 deletions(-) diff --git a/huaweicloud/resource_huaweicloud_mrs_cluster_v1.go b/huaweicloud/resource_huaweicloud_mrs_cluster_v1.go index 1efc2a969e2..1238ff4896a 100644 --- a/huaweicloud/resource_huaweicloud_mrs_cluster_v1.go +++ b/huaweicloud/resource_huaweicloud_mrs_cluster_v1.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/huaweicloud/golangsdk" "github.com/huaweicloud/golangsdk/openstack/mrs/v1/cluster" "github.com/huaweicloud/golangsdk/openstack/networking/v1/subnets" @@ -35,12 +36,33 @@ func resourceMRSClusterV1() *schema.Resource { ForceNew: true, Computed: true, }, - + "available_zone_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, "billing_type": { Type: schema.TypeInt, Required: true, ForceNew: true, }, + "cluster_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "cluster_version": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + "cluster_type": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ForceNew: true, + }, "master_node_num": { Type: schema.TypeInt, Required: true, @@ -54,7 +76,7 @@ func resourceMRSClusterV1() *schema.Resource { "core_node_num": { Type: schema.TypeInt, Required: true, - ValidateFunc: resourceClusterValidateCoreNodeNum, + ValidateFunc: validation.IntBetween(1, 500), ForceNew: true, }, "core_node_size": { @@ -62,16 +84,7 @@ func resourceMRSClusterV1() *schema.Resource { Required: true, ForceNew: true, }, - "available_zone_id": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "cluster_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, + "vpc_id": { Type: schema.TypeString, Required: true, @@ -82,36 +95,20 @@ func resourceMRSClusterV1() *schema.Resource { Required: true, ForceNew: true, }, - "cluster_version": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - "cluster_type": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, + "volume_type": { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { - return ValidateStringList(v, k, []string{"SATA", "SSD"}) - }, + ValidateFunc: validation.StringInSlice([]string{ + "SATA", "SAS", "SSD", + }, false), }, "volume_size": { Type: schema.TypeInt, Required: true, ForceNew: true, }, - "node_public_cert_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, "safe_mode": { Type: schema.TypeInt, Required: true, @@ -123,6 +120,11 @@ func resourceMRSClusterV1() *schema.Resource { Computed: true, ForceNew: true, }, + "node_public_cert_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, "log_collection": { Type: schema.TypeInt, Optional: true, @@ -344,15 +346,6 @@ func resourceMRSClusterV1() *schema.Resource { } } -func resourceClusterValidateCoreNodeNum(v interface{}, k string) (ws []string, errors []error) { - value := v.(int) - if 3 <= value && value <= 100 { - return - } - errors = append(errors, fmt.Errorf("%q must be [3, 100]", k)) - return -} - func getAllClusterComponents(d *schema.ResourceData) []cluster.ComponentOpts { var componentOpts []cluster.ComponentOpts @@ -444,16 +437,17 @@ func resourceClusterV1Create(d *schema.ResourceData, meta interface{}) error { CoreNodeSize: d.Get("core_node_size").(string), AvailableZoneID: d.Get("available_zone_id").(string), ClusterName: d.Get("cluster_name").(string), - Vpc: vpc.Name, + ClusterVersion: d.Get("cluster_version").(string), + ClusterType: d.Get("cluster_type").(int), VpcID: d.Get("vpc_id").(string), SubnetID: d.Get("subnet_id").(string), + Vpc: vpc.Name, SubnetName: subnet.Name, - ClusterVersion: d.Get("cluster_version").(string), - ClusterType: d.Get("cluster_type").(int), VolumeType: d.Get("volume_type").(string), VolumeSize: d.Get("volume_size").(int), - NodePublicCertName: d.Get("node_public_cert_name").(string), SafeMode: d.Get("safe_mode").(int), + LoginMode: 1, + NodePublicCertName: d.Get("node_public_cert_name").(string), ClusterAdminSecret: d.Get("cluster_admin_secret").(string), LogCollection: d.Get("log_collection").(int), ComponentList: getAllClusterComponents(d),