Skip to content

Commit

Permalink
[cce] Add possibility to set runtime (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiChangkuo authored Apr 2, 2021
1 parent 8cfe8ed commit 0bf01c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/resources/cce_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ The following arguments are supported:
* `auto_renew` - (Optional, String, ForceNew) Specifies whether auto renew is enabled.
Valid values are "true" and "false". Changing this creates a new resource.

* `runtime` - (Optional, String, ForceNew) Specifies the runtime of the CCE node. Valid values are *docker* and *containerd*.
Changing this creates a new resource.

* `extend_param` - (Optional, Map, ForceNew) Extended parameter. Changing this parameter will create a new resource. Availiable keys :

* `agency_name` - Specifies the agency name to provide temporary credentials for CCE node to access other cloud services.
Expand Down
17 changes: 17 additions & 0 deletions huaweicloud/resource_huaweicloud_cce_node_pool.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/cce/v3/nodepools"
"github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes"
Expand Down Expand Up @@ -201,6 +202,15 @@ func ResourceCCENodePool() *schema.Resource {
}
},
},
"runtime": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"docker", "containerd",
}, false),
},
"extend_param": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -298,6 +308,12 @@ func resourceCCENodePoolCreate(d *schema.ResourceData, meta interface{}) error {
},
}

if v, ok := d.GetOk("runtime"); ok {
createOpts.Spec.NodeTemplate.RunTime = &nodes.RunTimeSpec{
Name: v.(string),
}
}

clusterid := d.Get("cluster_id").(string)
stateCluster := &resource.StateChangeConf{
Target: []string{"Available"},
Expand Down Expand Up @@ -369,6 +385,7 @@ func resourceCCENodePoolRead(d *schema.ResourceData, meta interface{}) error {
d.Set("os", s.Spec.NodeTemplate.Os)
d.Set("billing_mode", s.Spec.NodeTemplate.BillingMode)
d.Set("key_pair", s.Spec.NodeTemplate.Login.SshKey)
d.Set("runtime", s.Spec.NodeTemplate.RunTime.Name)
d.Set("initial_node_count", s.Spec.InitialNodeCount)
d.Set("scall_enable", s.Spec.Autoscaling.Enable)
d.Set("min_node_count", s.Spec.Autoscaling.MinNodeCount)
Expand Down
16 changes: 16 additions & 0 deletions huaweicloud/resource_huaweicloud_cce_node_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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/cce/v3/clusters"
"github.com/huaweicloud/golangsdk/openstack/cce/v3/nodes"
Expand Down Expand Up @@ -196,6 +197,15 @@ func ResourceCCENodeV3() *schema.Resource {
"iptype", "bandwidth_size", "sharetype",
},
},
"runtime": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"docker", "containerd",
}, false),
},
"ecs_group_id": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -559,6 +569,11 @@ func resourceCCENodeV3Create(d *schema.ResourceData, meta interface{}) error {
if v, ok := d.GetOk("fixed_ip"); ok {
createOpts.Spec.NodeNicSpec.PrimaryNic.FixedIps = []string{v.(string)}
}
if v, ok := d.GetOk("runtime"); ok {
createOpts.Spec.RunTime = &nodes.RunTimeSpec{
Name: v.(string),
}
}

clusterid := d.Get("cluster_id").(string)
stateCluster := &resource.StateChangeConf{
Expand Down Expand Up @@ -632,6 +647,7 @@ func resourceCCENodeV3Read(d *schema.ResourceData, meta interface{}) error {
d.Set("os", s.Spec.Os)
d.Set("key_pair", s.Spec.Login.SshKey)
d.Set("subnet_id", s.Spec.NodeNicSpec.PrimaryNic.SubnetId)
d.Set("runtime", s.Spec.RunTime.Name)
d.Set("ecs_group_id", s.Spec.EcsGroupID)
d.Set("billing_mode", s.Spec.BillingMode)
if s.Spec.BillingMode != 0 {
Expand Down

0 comments on commit 0bf01c4

Please sign in to comment.