diff --git a/huaweicloud/resource_huaweicloud_cce_node_v3.go b/huaweicloud/resource_huaweicloud_cce_node_v3.go index 1a6e19d8a2..1db4fe5f99 100644 --- a/huaweicloud/resource_huaweicloud_cce_node_v3.go +++ b/huaweicloud/resource_huaweicloud_cce_node_v3.go @@ -69,9 +69,17 @@ func resourceCCENodeV3() *schema.Resource { ForceNew: true, }, "key_pair": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + ConflictsWith: []string{"password"}, + Optional: true, + ForceNew: true, + }, + "password": { + Type: schema.TypeString, + ConflictsWith: []string{"key_pair"}, + Optional: true, + ForceNew: true, + Sensitive: true, }, "root_volume": { Type: schema.TypeList, @@ -261,6 +269,20 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error creating HuaweiCloud CCE Node client: %s", err) } + var loginSpec nodes.LoginSpec + if hasFilledOpt(d, "key_pair") { + loginSpec = nodes.LoginSpec{SshKey: d.Get("key_pair").(string)} + } else if hasFilledOpt(d, "password") { + loginSpec = nodes.LoginSpec{ + UserPassword: nodes.UserPassword{ + Username: "root", + Password: d.Get("password").(string), + }, + } + } else { + return fmt.Errorf("Error creating HuaweiCloud CCE Node: key_pair or password must be set") + } + createOpts := nodes.CreateOpts{ Kind: "Node", ApiVersion: "v3", @@ -273,7 +295,7 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error { Flavor: d.Get("flavor_id").(string), Az: d.Get("availability_zone").(string), Os: d.Get("os").(string), - Login: nodes.LoginSpec{SshKey: d.Get("key_pair").(string)}, + Login: loginSpec, RootVolume: resourceCCERootVolume(d), DataVolumes: resourceCCEDataVolume(d), PublicIP: nodes.PublicIPSpec{ diff --git a/website/docs/r/cce_nodes_v3.html.md b/website/docs/r/cce_nodes_v3.html.md index f711daa4c9..bb8fce4bef 100644 --- a/website/docs/r/cce_nodes_v3.html.md +++ b/website/docs/r/cce_nodes_v3.html.md @@ -58,7 +58,9 @@ The following arguments are supported: * `os` - (Optional) Operating System of the node, possible values are EulerOS 2.2 and CentOS 7.1. Defaults to EulerOS 2.2. Changing this parameter will create a new resource. -* `key_pair` - (Required) Key pair name when logging in to select the key pair mode. Changing this parameter will create a new resource. +* `key_pair` - (Optional) Key pair name when logging in to select the key pair mode. Changing this parameter will create a new resource. + +* `password` - (Optional) root password when logging in to select the password mode. Changing this parameter will create a new resource. * `eip_ids` - (Optional) List of existing elastic IP IDs. Changing this parameter will create a new resource.