Skip to content

fix(cvm): [125902956] support AntiDDos Eip #3451

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .changelog/3451.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/tencentcloud_instance: support AntiDDos Eip
```

```release-note:enhancement
resource/tencentcloud_as_scaling_config: support AntiDDos Eip
```
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.763
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.0.825
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1164
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1211
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.1071
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cat v1.0.825
Expand All @@ -46,8 +46,8 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1107
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1148
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1196
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1153
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1211
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1206
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1161
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1078 h1:61WsmpY
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1078/go.mod h1:PC3PuWjgDqScMDrVXe9+QEH/r95FHd4p560GjkDf2rk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1164 h1:XsqO8lrHWTphz8jmgkU09gcX+V6XnPN2QMOiZezrISk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1164/go.mod h1:hEhWTzJLNl5WkKi4cIWi9rtEAectaRY02RqYqC4Twi4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1211 h1:KLzI3CUZCNqflU0FRWI31dcWBIgBaBMoRgML9wNZ70U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.1211/go.mod h1:IBzy/+ZfDywz9Ln6tzRP9SiyPONBBTya/TiHaVvNonY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824 h1:DVKvZ6h+qd7tadUrCjVAkCCmE3TsbK2ZmwGd3AJcpWc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824/go.mod h1:DvBpDX/qdJG4KKLeULmRvhAjPYiw8za0HeTSu2y/lFw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.1071 h1:2CeivXYc7PtD2kgZEJXk9/SDQA9dzLejH5FmNzAW3QU=
Expand Down Expand Up @@ -991,6 +993,10 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1191 h1:Zj8
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1191/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1196 h1:2pRWolqipwF5RBtpSKp9YAg9cIvIPnhFCkj5FFhv8V8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1196/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1206 h1:RVM/x8Sx4XL7zda5IRE1HL3czh9wLAdl+UbrbVPcf2k=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1206/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1211 h1:Y97J0JA6dYIhsMeswB1G6RCiTH8qUIBEBrng9onSl60=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1211/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993 h1:WlPgXldQCxt7qi5Xrc6j6zTrsXWzN5BcOGs7Irq7fwQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/controlcenter v1.0.993/go.mod h1:Z9U8zNtyuyKhjS0698wqsrG/kLx1TQ5CEixXBwVe7xY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
Expand All @@ -999,6 +1005,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1128 h1:qoSzTK
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1128/go.mod h1:hVNSxeomc/AQsJphdbPnPINsO0cMLcVAA6kituTD2g0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1153 h1:ENSIHfoHuFw4IQrkPvUyBFEvE++QVdIxY3lSFo9jho0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1153/go.mod h1:lBiTrRc+WW71B71du+uodZRhpa+QlnsqwT4sVSEaPac=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1206 h1:tx8L5srClwK2T5dte7yw3N8PfxqtuHbT8fWfUZMOUwk=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1206/go.mod h1:zkdrFNYxTFX7E3QRgNVayQi7fq/A1TYRKLkGE8NS0lQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762 h1:2egy69SP/wPsmnfozcQVZ6tUY6F6N/TpEe/7xtXrc/8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762/go.mod h1:1XylIfNUbAzmNqi4XMhwcM3VhmUHdu1OYybOeaJ4sOw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.1111 h1:Y7LLIZEQh8OAbnBWppUopu2PjPaQOO9Jzhp8LZO7adI=
Expand Down
68 changes: 67 additions & 1 deletion tencentcloud/services/as/resource_tc_as_scaling_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,29 @@ func ResourceTencentCloudAsScalingConfig() *schema.Resource {
Optional: true,
Description: "Specify whether to assign an Internet IP address.",
},
"bandwidth_package_id": {
Type: schema.TypeString,
Optional: true,
Description: "Bandwidth package ID.",
},
"ipv4_address_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"WanIP", "HighQualityEIP", "AntiDDoSEIP"}),
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.",
},
"anti_ddos_package_id": {
Type: schema.TypeString,
Optional: true,
Description: "Anti-DDoS service package ID. This is required when you want to request an AntiDDoS IP.",
},
"is_keep_eip": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Whether to delete the bound EIP when the instance is destroyed. Range of values: True: retain the EIP; False: not retain the EIP. Note that when the IPv4AddressType field specifies the EIP type, the default behavior is not to retain the EIP. WanIP is unaffected by this field and will always be deleted with the instance. Changing this field configuration will take effect immediately for resources already bound to a scaling group.",
},
"password": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -370,6 +393,18 @@ func resourceTencentCloudAsScalingConfigCreate(d *schema.ResourceData, meta inte
publicIpAssigned := v.(bool)
request.InternetAccessible.PublicIpAssigned = &publicIpAssigned
}
if v, ok := d.GetOk("bandwidth_package_id"); ok {
request.InternetAccessible.BandwidthPackageId = helper.String(v.(string))
}
if v, ok := d.GetOk("ipv4_address_type"); ok {
request.InternetAccessible.IPv4AddressType = helper.String(v.(string))
}
if v, ok := d.GetOk("anti_ddos_package_id"); ok {
request.InternetAccessible.AntiDDoSPackageId = helper.String(v.(string))
}
if v, ok := d.GetOkExists("is_keep_eip"); ok {
request.InternetAccessible.IsKeepEIP = helper.Bool(v.(bool))
}

request.LoginSettings = &as.LoginSettings{}
if v, ok := d.GetOk("password"); ok {
Expand Down Expand Up @@ -610,6 +645,24 @@ func resourceTencentCloudAsScalingConfigRead(d *schema.ResourceData, meta interf

_ = d.Set("cam_role_name", *config.CamRoleName)

if config.InternetAccessible != nil {
if config.InternetAccessible.BandwidthPackageId != nil {
_ = d.Set("bandwidth_package_id", config.InternetAccessible.BandwidthPackageId)
}

if config.InternetAccessible.IPv4AddressType != nil {
_ = d.Set("ipv4_address_type", config.InternetAccessible.IPv4AddressType)
}

if config.InternetAccessible.AntiDDoSPackageId != nil {
_ = d.Set("anti_ddos_package_id", config.InternetAccessible.AntiDDoSPackageId)
}

if config.InternetAccessible.IsKeepEIP != nil {
_ = d.Set("is_keep_eip", config.InternetAccessible.IsKeepEIP)
}
}

if config.HostNameSettings != nil {
isEmptySettings := true
settings := map[string]interface{}{}
Expand Down Expand Up @@ -749,7 +802,8 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
}
}

if d.HasChange("internet_charge_type") || d.HasChange("internet_max_bandwidth_out") || d.HasChange("public_ip_assigned") {
if d.HasChange("internet_charge_type") || d.HasChange("internet_max_bandwidth_out") || d.HasChange("public_ip_assigned") ||
d.HasChange("bandwidth_package_id") || d.HasChange("ipv4_address_type") || d.HasChange("anti_ddos_package_id") || d.HasChange("is_keep_eip") {
request.InternetAccessible = &as.InternetAccessible{}
if v, ok := d.GetOk("internet_charge_type"); ok {
request.InternetAccessible.InternetChargeType = helper.String(v.(string))
Expand All @@ -761,6 +815,18 @@ func resourceTencentCloudAsScalingConfigUpdate(d *schema.ResourceData, meta inte
publicIpAssigned := v.(bool)
request.InternetAccessible.PublicIpAssigned = &publicIpAssigned
}
if v, ok := d.GetOk("bandwidth_package_id"); ok {
request.InternetAccessible.BandwidthPackageId = helper.String(v.(string))
}
if v, ok := d.GetOk("ipv4_address_type"); ok {
request.InternetAccessible.IPv4AddressType = helper.String(v.(string))
}
if v, ok := d.GetOk("anti_ddos_package_id"); ok {
request.InternetAccessible.AntiDDoSPackageId = helper.String(v.(string))
}
if v, ok := d.GetOkExists("is_keep_eip"); ok {
request.InternetAccessible.IsKeepEIP = helper.Bool(v.(bool))
}
}

if d.HasChange("security_group_ids") {
Expand Down
53 changes: 52 additions & 1 deletion tencentcloud/services/as/resource_tc_as_scaling_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ resource "tencentcloud_as_scaling_config" "example" {
}
```

Using `SPOTPAID` charge type
Using SPOTPAID charge type

```hcl
data "tencentcloud_images" "example" {
Expand Down Expand Up @@ -177,6 +177,57 @@ resource "tencentcloud_as_scaling_config" "example" {
}
```

Create configuration with AntiDDos Eip

```hcl
data "tencentcloud_images" "example" {
image_type = ["PUBLIC_IMAGE"]
os_name = "TencentOS Server 4 for x86_64"
}

resource "tencentcloud_as_scaling_config" "example" {
configuration_name = "tf-example"
image_id = data.tencentcloud_images.example.images.0.image_id
instance_types = ["SA5.MEDIUM4"]
project_id = 0
system_disk_type = "CLOUD_PREMIUM"
system_disk_size = "50"

data_disk {
disk_type = "CLOUD_PREMIUM"
disk_size = 50
}


internet_charge_type = "BANDWIDTH_PACKAGE"
internet_max_bandwidth_out = 10
public_ip_assigned = true
bandwidth_package_id = "bwp-4ocyia9s"
ipv4_address_type = "AntiDDoSEIP"
anti_ddos_package_id = "bgp-xxxxxxx"
is_keep_eip = true
password = "Test@123#"
enhanced_security_service = false
enhanced_monitor_service = false
enhanced_automation_tools_service = false
user_data = "dGVzdA=="

host_name_settings {
host_name = "host-name"
host_name_style = "UNIQUE"
}

instance_tags = {
tag = "example"
}

tags = {
"createdBy" = "Terraform"
"owner" = "tf"
}
}
```

Import

AutoScaling Configuration can be imported using the id, e.g.
Expand Down
35 changes: 35 additions & 0 deletions tencentcloud/services/cvm/resource_tc_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ func ResourceTencentCloudInstance() *schema.Resource {
ForceNew: true,
Description: "Associate a public IP address with an instance in a VPC or Classic. Boolean value, Default is false.",
},
"ipv4_address_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"WanIP", "HighQualityEIP", "AntiDDoSEIP"}),
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.",
},
"anti_ddos_package_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: "Anti-DDoS service package ID. This is required when you want to request an AntiDDoS IP.",
},
// vpc
"vpc_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -654,6 +669,16 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
netWorkFlag = true
}

if v, ok := d.GetOk("ipv4_address_type"); ok {
internetAccessible.IPv4AddressType = helper.String(v.(string))
netWorkFlag = true
}

if v, ok := d.GetOk("anti_ddos_package_id"); ok {
internetAccessible.AntiDDoSPackageId = helper.String(v.(string))
netWorkFlag = true
}

if netWorkFlag {
request.InternetAccessible = &internetAccessible
}
Expand Down Expand Up @@ -1162,6 +1187,16 @@ func resourceTencentCloudInstanceRead(d *schema.ResourceData, meta interface{})
_ = d.Set("allocate_public_ip", len(instance.PublicIpAddresses) > 0)
}

if instance.InternetAccessible != nil {
if instance.InternetAccessible.IPv4AddressType != nil {
_ = d.Set("ipv4_address_type", instance.InternetAccessible.IPv4AddressType)
}

if instance.InternetAccessible.AntiDDoSPackageId != nil {
_ = d.Set("anti_ddos_package_id", instance.InternetAccessible.AntiDDoSPackageId)
}
}

tagService := svctag.NewTagService(client)

tags, err := tagService.DescribeResourceTags(ctx, "cvm", "instance", client.Region, d.Id())
Expand Down
33 changes: 33 additions & 0 deletions tencentcloud/services/cvm/resource_tc_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Provides a CVM instance resource.

~> **NOTE:** When creating a CVM instance using a `launch_template_id`, if you set other parameter values ​​at the same time, the template definition values ​​will be overwritten.

~> **NOTE:** It is recommended to use resource `tencentcloud_eip` to create a AntiDDos Eip, and then call resource `tencentcloud_eip_association` to bind it to resource `tencentcloud_instance`.

Example Usage

Create a general POSTPAID_BY_HOUR CVM instance
Expand Down Expand Up @@ -243,6 +245,37 @@ resource "tencentcloud_instance" "example" {
}
```

Create CVM instance with AntiDDos Eip

```hcl
resource "tencentcloud_instance" "example" {
instance_name = "tf-example"
availability_zone = "ap-guangzhou-6"
image_id = "img-eb30mz89"
instance_type = "S5.MEDIUM4"
system_disk_type = "CLOUD_HSSD"
system_disk_size = 50
hostname = "user"
project_id = 0
vpc_id = "vpc-i5yyodl9"
subnet_id = "subnet-hhi88a58"
internet_charge_type = "BANDWIDTH_PACKAGE"
bandwidth_package_id = "bwp-4ocyia9s"
ipv4_address_type = "AntiDDoSEIP"
anti_ddos_package_id = "bgp-xxxxxxx"

data_disks {
data_disk_type = "CLOUD_HSSD"
data_disk_size = 100
encrypt = false
}

tags = {
tagKey = "tagValue"
}
}
```

Import

CVM instance can be imported using the id, e.g.
Expand Down
Loading
Loading