Skip to content

Commit

Permalink
Merge pull request #193 from niuzhenguo/cce-node-password
Browse files Browse the repository at this point in the history
Add CCE node password support
  • Loading branch information
niuzhenguo authored Aug 22, 2019
2 parents 2394cbe + 48d7f55 commit 2d5ee71
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
30 changes: 26 additions & 4 deletions huaweicloud/resource_huaweicloud_cce_node_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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{
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/cce_nodes_v3.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 2d5ee71

Please sign in to comment.