Skip to content

Commit

Permalink
[MRS] set node login mode default to key-pair
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiChangkuo committed Oct 29, 2020
1 parent 3159714 commit 35a49a0
Showing 1 changed file with 39 additions and 45 deletions.
84 changes: 39 additions & 45 deletions huaweicloud/resource_huaweicloud_mrs_cluster_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -54,24 +76,15 @@ func resourceMRSClusterV1() *schema.Resource {
"core_node_num": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: resourceClusterValidateCoreNodeNum,
ValidateFunc: validation.IntBetween(1, 500),
ForceNew: true,
},
"core_node_size": {
Type: schema.TypeString,
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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 35a49a0

Please sign in to comment.