Skip to content

Commit 9d8bd92

Browse files
tongyimingmikatong
andauthored
fix(cvm): [127281125]support ipv6_address_type and release_address (#3518)
* support ipv6_address_type and release_address * update * add changelog --------- Co-authored-by: mikatong <mikatong@tencent.com>
1 parent a5153d1 commit 9d8bd92

File tree

5 files changed

+154
-4
lines changed

5 files changed

+154
-4
lines changed

.changelog/3518.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_instance: support ipv6_address_type, ipv6_address_count and release_address
3+
```

tencentcloud/services/cvm/resource_tc_instance.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ func ResourceTencentCloudInstance() *schema.Resource {
205205
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"WanIP", "HighQualityEIP", "AntiDDoSEIP"}),
206206
Description: "AddressType. Default value: WanIP. For beta users of dedicated IP. the value can be: HighQualityEIP: Dedicated IP. Note that dedicated IPs are only available in partial regions. For beta users of Anti-DDoS IP, the value can be: AntiDDoSEIP: Anti-DDoS EIP. Note that Anti-DDoS IPs are only available in partial regions.",
207207
},
208+
"ipv6_address_type": {
209+
Type: schema.TypeString,
210+
Optional: true,
211+
ForceNew: true,
212+
Computed: true,
213+
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"EIPv6", "HighQualityEIPv6"}),
214+
Description: "IPv6 AddressType. Default value: WanIP. EIPv6: Elastic IPv6; HighQualityEIPv6: Premium IPv6, only China Hong Kong supports premium IPv6. To allocate IPv6 addresses to resources, please specify the Elastic IPv6 type.",
215+
},
216+
"ipv6_address_count": {
217+
Type: schema.TypeInt,
218+
Optional: true,
219+
ForceNew: true,
220+
Computed: true,
221+
Description: "Specify the number of randomly generated IPv6 addresses for the Elastic Network Interface.",
222+
},
208223
"anti_ddos_package_id": {
209224
Type: schema.TypeString,
210225
Optional: true,
@@ -478,6 +493,11 @@ func ResourceTencentCloudInstance() *schema.Resource {
478493
ForceNew: true,
479494
Description: "The instance launch template version number. If given, a new instance launch template will be created based on the given version number.",
480495
},
496+
"release_address": {
497+
Type: schema.TypeBool,
498+
Optional: true,
499+
Description: "Release elastic IP. Under EIP 2.0, only the first EIP under the primary network card is provided, and the EIP types are limited to HighQualityEIP, AntiDDoSEIP, EIPv6, and HighQualityEIPv6. Default behavior is not released.",
500+
},
481501
// Computed values.
482502
"instance_status": {
483503
Type: schema.TypeString,
@@ -674,6 +694,11 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
674694
netWorkFlag = true
675695
}
676696

697+
if v, ok := d.GetOk("ipv6_address_type"); ok {
698+
internetAccessible.IPv6AddressType = helper.String(v.(string))
699+
netWorkFlag = true
700+
}
701+
677702
if v, ok := d.GetOk("anti_ddos_package_id"); ok {
678703
internetAccessible.AntiDDoSPackageId = helper.String(v.(string))
679704
netWorkFlag = true
@@ -695,6 +720,9 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
695720
if v, ok = d.GetOk("private_ip"); ok {
696721
request.VirtualPrivateCloud.PrivateIpAddresses = []*string{helper.String(v.(string))}
697722
}
723+
if v, ok = d.GetOkExists("ipv6_address_count"); ok {
724+
request.VirtualPrivateCloud.Ipv6AddressCount = helper.IntUint64(v.(int))
725+
}
698726
}
699727

700728
if v, ok := d.GetOk("security_groups"); ok {
@@ -1192,6 +1220,10 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
11921220
_ = d.Set("ipv4_address_type", instance.InternetAccessible.IPv4AddressType)
11931221
}
11941222

1223+
if instance.InternetAccessible.IPv6AddressType != nil {
1224+
_ = d.Set("ipv6_address_type", instance.InternetAccessible.IPv6AddressType)
1225+
}
1226+
11951227
if instance.InternetAccessible.AntiDDoSPackageId != nil {
11961228
_ = d.Set("anti_ddos_package_id", instance.InternetAccessible.AntiDDoSPackageId)
11971229
}
@@ -1710,6 +1742,10 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
17101742
_ = d.Set("user_data_raw", string(userDataRaw))
17111743
}
17121744

1745+
if instance.VirtualPrivateCloud != nil && instance.VirtualPrivateCloud.Ipv6AddressCount != nil {
1746+
_ = d.Set("ipv6_address_count", instance.VirtualPrivateCloud.Ipv6AddressCount)
1747+
}
1748+
17131749
return nil
17141750
}
17151751

@@ -2359,8 +2395,12 @@ func resourceTencentCloudInstanceDelete(d *schema.ResourceData, meta interface{}
23592395
return err
23602396
}
23612397

2398+
var releaseAddress bool
2399+
if v, ok := d.GetOkExists("release_address"); ok {
2400+
releaseAddress = v.(bool)
2401+
}
23622402
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
2363-
errRet := cvmService.DeleteInstance(ctx, instanceId)
2403+
errRet := cvmService.DeleteInstance(ctx, instanceId, releaseAddress)
23642404
if errRet != nil {
23652405
return tccommon.RetryError(errRet)
23662406
}
@@ -2510,7 +2550,7 @@ func resourceTencentCloudInstanceDelete(d *schema.ResourceData, meta interface{}
25102550

25112551
// exist in recycle, delete again
25122552
err = resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
2513-
errRet := cvmService.DeleteInstance(ctx, instanceId)
2553+
errRet := cvmService.DeleteInstance(ctx, instanceId, releaseAddress)
25142554
//when state is terminating, do not delete but check exist
25152555
if errRet != nil {
25162556
//check InvalidInstanceState.Terminating

tencentcloud/services/cvm/resource_tc_instance_test.go

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func testSweepCvmInstance(region string) error {
7575
continue
7676
}
7777

78-
if err = cvmService.DeleteInstance(ctx, instanceId); err != nil {
78+
if err = cvmService.DeleteInstance(ctx, instanceId, false); err != nil {
7979
log.Printf("[ERROR] sweep instance %s error: %s", instanceId, err.Error())
8080
}
8181
}
@@ -2995,3 +2995,104 @@ resource "tencentcloud_instance" "hpc" {
29952995
hpc_cluster_id = tencentcloud_cvm_hpc_cluster.hpc_cluster.id
29962996
}
29972997
`
2998+
2999+
func TestAccTencentCloudNeedFixCvmInstanceResource_IPv6AddressType(t *testing.T) {
3000+
resource.Test(t, resource.TestCase{
3001+
PreCheck: func() {
3002+
acctest.AccPreCheck(t)
3003+
},
3004+
Providers: acctest.AccProviders,
3005+
CheckDestroy: testAccCheckCvmInstanceDestroy,
3006+
Steps: []resource.TestStep{
3007+
{
3008+
Config: testAccCvmInstanceResource_IPv6AddressType,
3009+
Check: resource.ComposeTestCheckFunc(
3010+
testAccCheckCvmInstanceExists("tencentcloud_instance.foo"),
3011+
resource.TestCheckResourceAttr("tencentcloud_instance.foo", "ipv6_address_type", "EIPv6"),
3012+
),
3013+
},
3014+
},
3015+
})
3016+
}
3017+
3018+
const testAccCvmInstanceResource_IPv6AddressType = `
3019+
data "tencentcloud_instance_types" "default" {
3020+
filter {
3021+
name = "instance-family"
3022+
values = ["S3"]
3023+
}
3024+
cpu_core_count = 2
3025+
memory_size = 2
3026+
}
3027+
resource "tencentcloud_instance" "foo" {
3028+
instance_name = "tf-ci-test"
3029+
availability_zone = "ap-guangzhou-3"
3030+
vpc_id = "vpc-mvhjjprd"
3031+
subnet_id = "subnet-2qfyfvv8"
3032+
lifecycle {
3033+
ignore_changes = [instance_type]
3034+
}
3035+
image_id = "img-2lr9q49h"
3036+
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
3037+
system_disk_type = "CLOUD_PREMIUM"
3038+
force_delete = true
3039+
orderly_security_groups = ["sg-05f7wnhn"]
3040+
ipv6_address_type = "EIPv6"
3041+
}
3042+
`
3043+
3044+
func TestAccTencentCloudNeedFixCvmInstanceResource_ReleaseAddress(t *testing.T) {
3045+
resource.Test(t, resource.TestCase{
3046+
PreCheck: func() {
3047+
acctest.AccPreCheck(t)
3048+
tcacctest.AccStepSetRegion(t, "ap-hongkong")
3049+
},
3050+
Providers: acctest.AccProviders,
3051+
CheckDestroy: testAccCheckCvmInstanceDestroy,
3052+
Steps: []resource.TestStep{
3053+
{
3054+
Config: testAccCvmInstanceResource_ReleaseAddress,
3055+
Check: resource.ComposeTestCheckFunc(
3056+
testAccCheckCvmInstanceExists("tencentcloud_instance.foo"),
3057+
resource.TestCheckResourceAttr("tencentcloud_instance.foo", "ipv4_address_type", "HighQualityEIP"),
3058+
resource.TestCheckResourceAttr("tencentcloud_instance.foo", "ipv6_address_type", "HighQualityEIPv6"),
3059+
resource.TestCheckResourceAttr("tencentcloud_instance.foo", "ipv6_address_count", "1"),
3060+
resource.TestCheckResourceAttr("tencentcloud_instance.foo", "release_address", "true"),
3061+
),
3062+
},
3063+
},
3064+
})
3065+
}
3066+
3067+
const testAccCvmInstanceResource_ReleaseAddress = `
3068+
data "tencentcloud_instance_types" "default" {
3069+
filter {
3070+
name = "instance-family"
3071+
values = ["S5"]
3072+
}
3073+
cpu_core_count = 2
3074+
memory_size = 2
3075+
}
3076+
3077+
resource "tencentcloud_instance" "foo" {
3078+
instance_name = "tf-ci-test"
3079+
availability_zone = "ap-hongkong-3"
3080+
vpc_id = "vpc-0rlhss58"
3081+
subnet_id = "subnet-73ckwxez"
3082+
lifecycle {
3083+
ignore_changes = [instance_type]
3084+
}
3085+
image_id = "img-l8og963d"
3086+
instance_type = data.tencentcloud_instance_types.default.instance_types.0.instance_type
3087+
system_disk_type = "CLOUD_PREMIUM"
3088+
force_delete = true
3089+
internet_charge_type = "BANDWIDTH_PACKAGE"
3090+
bandwidth_package_id = "bwp-rcql8f4c"
3091+
ipv4_address_type = "HighQualityEIP"
3092+
ipv6_address_type = "HighQualityEIPv6"
3093+
ipv6_address_count = 1
3094+
allocate_public_ip = true
3095+
internet_max_bandwidth_out = 1
3096+
release_address = true
3097+
}
3098+
`

tencentcloud/services/cvm/service_tencentcloud_cvm.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,13 @@ func (me *CvmService) StartInstance(ctx context.Context, instanceId string) erro
475475
return nil
476476
}
477477

478-
func (me *CvmService) DeleteInstance(ctx context.Context, instanceId string) error {
478+
func (me *CvmService) DeleteInstance(ctx context.Context, instanceId string, releaseAddress bool) error {
479479
logId := tccommon.GetLogId(ctx)
480480
request := cvm.NewTerminateInstancesRequest()
481481
request.InstanceIds = []*string{&instanceId}
482+
if releaseAddress {
483+
request.ReleaseAddress = helper.Bool(releaseAddress)
484+
}
482485

483486
ratelimit.Check(request.GetAction())
484487
response, err := me.client.UseCvmClient().TerminateInstances(request)

website/docs/r/instance.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ The following arguments are supported:
320320
* `internet_charge_type` - (Optional, String) Internet charge type of the instance, Valid values are `BANDWIDTH_PREPAID`, `TRAFFIC_POSTPAID_BY_HOUR`, `BANDWIDTH_POSTPAID_BY_HOUR` and `BANDWIDTH_PACKAGE`. If not set, internet charge type are consistent with the cvm charge type by default. This value takes NO Effect when changing and does not need to be set when `allocate_public_ip` is false.
321321
* `internet_max_bandwidth_out` - (Optional, Int) Maximum outgoing bandwidth to the public network, measured in Mbps (Mega bits per second). This value does not need to be set when `allocate_public_ip` is false.
322322
* `ipv4_address_type` - (Optional, String, ForceNew) AddressType. Default value: WanIP. For beta users of dedicated IP. the value can be: HighQualityEIP: Dedicated IP. Note that dedicated IPs are only available in partial regions. For beta users of Anti-DDoS IP, the value can be: AntiDDoSEIP: Anti-DDoS EIP. Note that Anti-DDoS IPs are only available in partial regions.
323+
* `ipv6_address_count` - (Optional, Int, ForceNew) Specify the number of randomly generated IPv6 addresses for the Elastic Network Interface.
324+
* `ipv6_address_type` - (Optional, String, ForceNew) IPv6 AddressType. Default value: WanIP. EIPv6: Elastic IPv6; HighQualityEIPv6: Premium IPv6, only China Hong Kong supports premium IPv6. To allocate IPv6 addresses to resources, please specify the Elastic IPv6 type.
323325
* `keep_image_login` - (Optional, Bool) Whether to keep image login or not, default is `false`. When the image type is private or shared or imported, this parameter can be set `true`. Modifications may lead to the reinstallation of the instance's operating system..
324326
* `key_ids` - (Optional, Set: [`String`]) The key pair to use for the instance, it looks like `skey-16jig7tx`. Modifications may lead to the reinstallation of the instance's operating system.
325327
* `key_name` - (Optional, String, **Deprecated**) Please use `key_ids` instead. The key pair to use for the instance, it looks like `skey-16jig7tx`. Modifications may lead to the reinstallation of the instance's operating system.
@@ -330,6 +332,7 @@ The following arguments are supported:
330332
* `placement_group_id` - (Optional, String) The ID of a placement group.
331333
* `private_ip` - (Optional, String) The private IP to be assigned to this instance, must be in the provided subnet and available.
332334
* `project_id` - (Optional, Int) The project the instance belongs to, default to 0.
335+
* `release_address` - (Optional, Bool) Release elastic IP. Under EIP 2.0, only the first EIP under the primary network card is provided, and the EIP types are limited to HighQualityEIP, AntiDDoSEIP, EIPv6, and HighQualityEIPv6. Default behavior is not released.
333336
* `running_flag` - (Optional, Bool) Set instance to running or stop. Default value is true, the instance will shutdown when this flag is false.
334337
* `security_groups` - (Optional, Set: [`String`], **Deprecated**) It will be deprecated. Use `orderly_security_groups` instead. A list of security group IDs to associate with.
335338
* `spot_instance_type` - (Optional, String) Type of spot instance, only support `ONE-TIME` now. Note: it only works when instance_charge_type is set to `SPOTPAID`.

0 commit comments

Comments
 (0)