Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CCE node password support #193

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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