Skip to content

Commit d1beb13

Browse files
committed
fix: modify cvm
1 parent e5191bf commit d1beb13

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

.changelog/3157.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ resource/tencentcloud_instance: update doc
1111
```
1212

1313
```release-note:enhancement
14-
resource/tencentcloud_instance_set: Added field `private_ip_addresses`
14+
resource/tencentcloud_instance_set: Added a new field `private_ip_addresses` to support specifying multiple IPs to create instances
1515
```

tencentcloud/services/cvm/resource_tc_instance_set.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/base64"
66
"fmt"
77
"log"
8+
"sort"
89
"strconv"
910
"time"
1011

@@ -147,7 +148,7 @@ func ResourceTencentCloudInstanceSet() *schema.Resource {
147148
Description: "The private IP to be assigned to this instance, must be in the provided subnet and available. Cannot be set at the same time as `private_ip_addresses`.",
148149
},
149150
"private_ip_addresses": {
150-
Type: schema.TypeList,
151+
Type: schema.TypeSet,
151152
Elem: &schema.Schema{Type: schema.TypeString},
152153
Optional: true,
153154
Computed: true,
@@ -436,9 +437,20 @@ func doResourceTencentCloudInstanceSetCreate(d *schema.ResourceData, meta interf
436437
address := ip.(string)
437438
addressList = append(addressList, &address)
438439
}
440+
sort.SliceStable(addressList, func(i, j int) bool {
441+
return *addressList[i] < *addressList[j]
442+
})
439443
request.VirtualPrivateCloud.PrivateIpAddresses = addressList
440444
}
441445

446+
if v, ok := d.GetOk("private_ip_addresses"); ok {
447+
addressListSet := v.(*schema.Set).List()
448+
for i := range addressListSet {
449+
addressList := addressListSet[i].(string)
450+
request.VirtualPrivateCloud.PrivateIpAddresses = append(request.VirtualPrivateCloud.PrivateIpAddresses, &addressList)
451+
}
452+
}
453+
442454
}
443455

444456
if v, ok := d.GetOk("security_groups"); ok {
@@ -591,9 +603,6 @@ func doResourceTencentCloudInstanceSetRead(d *schema.ResourceData, meta interfac
591603
if len(instance.PrivateIpAddresses) > 0 {
592604
_ = d.Set("private_ip", instance.PrivateIpAddresses[0])
593605
}
594-
if len(instance.PrivateIpAddresses) > 0 {
595-
_ = d.Set("private_ip_addresses", instance.PrivateIpAddresses)
596-
}
597606
if len(instance.PublicIpAddresses) > 0 {
598607
_ = d.Set("public_ip", instance.PublicIpAddresses[0])
599608
}
@@ -606,6 +615,14 @@ func doResourceTencentCloudInstanceSetRead(d *schema.ResourceData, meta interfac
606615
_ = d.Set("keep_image_login", *instance.LoginSettings.KeepImageLogin == CVM_IMAGE_LOGIN)
607616
}
608617

618+
privateIpAddresses := []*string{}
619+
for _, v := range instanceSet {
620+
if len(v.PrivateIpAddresses) > 0 {
621+
privateIpAddresses = append(privateIpAddresses, v.PrivateIpAddresses...)
622+
}
623+
}
624+
_ = d.Set("private_ip_addresses", privateIpAddresses)
625+
609626
return nil
610627
}
611628

website/docs/r/instance_set.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The following arguments are supported:
9696
* `key_name` - (Optional, String) The key pair to use for the instance, it looks like `skey-16jig7tx`. Modifying will cause the instance reset.
9797
* `password` - (Optional, String) Password for the instance. In order for the new password to take effect, the instance will be restarted after the password change. Modifying will cause the instance reset.
9898
* `placement_group_id` - (Optional, String, ForceNew) The ID of a placement group.
99-
* `private_ip_addresses` - (Optional, List: [`String`]) Private network subnet IP array, which can be used when creating an instance or modifying instance vpc attributes. Currently, only batch creation of multiple instances supports passing in multiple IPs of the same subnet. Cannot be set at the same time as `private_ip`.
99+
* `private_ip_addresses` - (Optional, Set: [`String`]) Private network subnet IP array, which can be used when creating an instance or modifying instance vpc attributes. Currently, only batch creation of multiple instances supports passing in multiple IPs of the same subnet. Cannot be set at the same time as `private_ip`.
100100
* `private_ip` - (Optional, String) The private IP to be assigned to this instance, must be in the provided subnet and available. Cannot be set at the same time as `private_ip_addresses`.
101101
* `project_id` - (Optional, Int) The project the instance belongs to, default to 0.
102102
* `security_groups` - (Optional, Set: [`String`]) A list of security group IDs to associate with.

0 commit comments

Comments
 (0)