Skip to content

Commit 37314e6

Browse files
author
ivan
committed
添加调用 CreateClusterInstances时,传入imageId参数来指定镜像,以及对镜像的验证,满足 img-xxx 的格式
1 parent 0ec89d4 commit 37314e6

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

tencentcloud/resource_tc_container_cluster_instance.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ func resourceTencentCloudContainerClusterInstance() *schema.Resource {
199199
Computed: true,
200200
Description: "Describe the lan ip of the node.",
201201
},
202+
"os": {
203+
Type: schema.TypeString,
204+
Optional: true,
205+
ValidateFunc: validateImageID,
206+
Description: "The valid image id, format of img-xxx.",
207+
},
202208
},
203209
}
204210
}
@@ -461,6 +467,10 @@ func resourceTencentCloudContainerClusterInstancesCreate(d *schema.ResourceData,
461467
iAdvanced.Unschedulable = helper.IntInt64(v.(int))
462468
}
463469

470+
if v, ok := d.GetOk("os"); ok {
471+
runInstancesPara.ImageId = helper.String(v.(string))
472+
}
473+
464474
runInstancesParas := runInstancesPara.ToJsonString()
465475
cvms.Work = []string{runInstancesParas}
466476

tencentcloud/resource_tc_kubernetes_cluster.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,12 @@ func TkeCvmCreateInfo() map[string]*schema.Schema {
549549
Elem: &schema.Schema{Type: schema.TypeString},
550550
Description: "Disaster recover groups to which a CVM instance belongs. Only support maximum 1.",
551551
},
552+
"os": {
553+
Type: schema.TypeString,
554+
Optional: true,
555+
ValidateFunc: validateImageID,
556+
Description: "The valid image id, format of img-xxx.",
557+
},
552558
}
553559
}
554560

@@ -1262,6 +1268,10 @@ func tkeGetCvmRunInstancesPara(dMap map[string]interface{}, meta interface{},
12621268
}
12631269
}
12641270

1271+
if v, ok := dMap["os"]; ok {
1272+
request.ImageId = helper.String(v.(string))
1273+
}
1274+
12651275
cvmJson = request.ToJsonString()
12661276

12671277
cvmJson = strings.Replace(cvmJson, `"Password":"",`, "", -1)

tencentcloud/validators.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ func validateIp(v interface{}, k string) (ws []string, errors []error) {
6565
return
6666
}
6767

68+
func validateImageID(v interface{}, k string) (ws []string, errors []error) {
69+
value := v.(string)
70+
if !strings.HasPrefix(value, "img-") {
71+
errors = append(errors, fmt.Errorf("the format of %q is invalid: %s, it should begin with `img-`", k, value))
72+
}
73+
return
74+
}
75+
6876
// NOTE not exactly strict, but ok for now
6977
func validateIntegerInRange(min, max int64) schema.SchemaValidateFunc {
7078
return func(v interface{}, k string) (ws []string, errors []error) {

0 commit comments

Comments
 (0)