Skip to content
Merged
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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mozillazg/go-httpheader v0.3.0 // indirect
github.com/pkg/errors v0.9.1
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.334
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.199
Expand All @@ -32,7 +33,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.332
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.294
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/emr v1.0.287
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2 h1:Xr9gkxfOP0KQWXKNqmwe8vEeSUiUj4Rlee9CMVX2ZUQ=
github.com/tdakkota/asciicheck v0.0.0-20200416190851-d7f85be797a2/go.mod h1:yHp0ai0Z9gUljN3o0xMhYJnH/IcvkdTBOX2fmJ93JEM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.334 h1:wQMm0QGdVvdkYALiav8MHWnigkpquU4XiUsMOzEtw38=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos v1.0.334/go.mod h1:6ficOD4j2/gwkkXUrSlInWqKIAuWrIid1u4UvMiC41A=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285 h1:gFmukRGLtYiXVBVvg/5DP/0fM1+dKpwDjT+khtDVLmc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api v1.0.285/go.mod h1:aGlXSWjtSnE6kuqcaRy/NKj1CLiB8NlMSHGsDn+k7Ag=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.199 h1:e9M5HSIq2xw61Oz9whoaq+QT95rZtowkY/2zhdzx9v4=
Expand Down Expand Up @@ -487,6 +489,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199 h1:L0t
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.199/go.mod h1:AvfGfE5JXkyMV6uGd6B++SIDp+VV/SSphg1q2RiANFw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199 h1:CzZEt6l0qDjZUW8D8rUNQ/sKw6z6oYYdWuby3hlsn8g=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.199/go.mod h1:pz4s3nOhoB9cY0+uWzifuwr7lfh/Gvi1rv0ADxpPzD4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335 h1:D8qrelkK5udv8RzJJIABMzItGIyaZoYnxEVeIsYqiNw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335/go.mod h1:pz4s3nOhoB9cY0+uWzifuwr7lfh/Gvi1rv0ADxpPzD4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199 h1:7ShREKvI8ik2YNtLF42JR9x2YEeZS/gZvhIRfpsI8T0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.199/go.mod h1:5WGSrlIZJOhwIqPjjafb6vzrPEZieSHPhPMjjGPXOSU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.294 h1:VKP8TRlMSDUIJ32GuFKr4a0Fv/oi4LksRVOfJoK9CVc=
Expand Down
4 changes: 3 additions & 1 deletion tencentcloud/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const (
defaultSecurityGroup = "sg-ijato2x1"
defaultSecurityGroup2 = "sg-51rgzop1"

defaultProjectId = "1250480"
defaultProjectId = "1250480"
defaultDayuBgpIdV2 = "bgpip-000004x0"
defaultDayuBgpIpV2 = "119.28.217.253"
)

/*
Expand Down
15 changes: 15 additions & 0 deletions tencentcloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
antiddos "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/antiddos/v20200309"
api "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/api/v20201106"
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
Expand Down Expand Up @@ -104,6 +105,7 @@ type TencentCloudClient struct {
clsConn *cls.Client
dnsPodConn *dnspod.Client
privateDnsConn *privatedns.Client
antiddosConn *antiddos.Client
}

// NewClientProfile returns a new ClientProfile
Expand Down Expand Up @@ -678,3 +680,16 @@ func (me *TencentCloudClient) UsePrivateDnsClient() *privatedns.Client {

return me.privateDnsConn
}

// UseAntiddosClient returns antiddos client for service
func (me *TencentCloudClient) UseAntiddosClient() *antiddos.Client {
if me.antiddosConn != nil {
return me.antiddosConn
}

cpf := me.NewClientProfile(300)
me.antiddosConn, _ = antiddos.NewClient(me.Credential, me.Region, cpf)
me.antiddosConn.WithHttpTransport(&LogRoundTripper{})

return me.antiddosConn
}
184 changes: 184 additions & 0 deletions tencentcloud/data_source_tc_dayu_eip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
Use this data source to query dayu eip rules

Example Usage

```hcl
data "tencentcloud_dayu_eip" "test" {
resource_id="bgpip-000004xg"
}
```
*/
package tencentcloud

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func dataSourceTencentCloudDayuEip() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudDayuEipRead,
Schema: map[string]*schema.Schema{
"resource_id": {
Type: schema.TypeString,
Required: true,
Description: "Id of the resource.",
},
"bind_status": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validateAllowedStringValue(DDOS_EIP_BIND_STATUS),
},
Optional: true,
Description: "The binding state of the instance, value range [BINDING, BIND, UNBINDING, UNBIND], default is [BINDING, BIND, UNBINDING, UNBIND].",
},
"offset": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
Description: "The page start offset, default is `0`.",
},
"limit": {
Type: schema.TypeInt,
Optional: true,
Default: 10,
Description: "The number of pages, default is `10`.",
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
"list": {
Type: schema.TypeList,
Computed: true,
Description: "A list of layer 4 rules. Each element contains the following attributes:",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"eip_list": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Description: "",
},
},
"instance_id": {
Type: schema.TypeString,
Optional: true,
Description: "ID of the resource instance.",
},
"eip_bound_rsc_ins": {
Type: schema.TypeString,
Optional: true,
Description: "The ID of the resource instance for the binding.",
},
"eip_bound_rsc_eni": {
Type: schema.TypeString,
Required: true,
Description: "The ID of the bound ENI.",
},
"eip_bound_rsc_vip": {
Type: schema.TypeString,
Required: true,
Description: "Bind the resource intranet IP.",
},
"created_time": {
Type: schema.TypeString,
Required: true,
Description: "The created time of resource.",
},
"expired_time": {
Type: schema.TypeString,
Required: true,
Description: "The expired time of resource.",
},
"modify_time": {
Type: schema.TypeString,
Required: true,
Description: "The modify time of resource.",
},
"protection_status": {
Type: schema.TypeString,
Required: true,
Description: "The protection status of the asset instance.",
},
"eip_address_status": {
Type: schema.TypeString,
Required: true,
Description: "Eip PUBLIC IP status.",
},
"region": {
Type: schema.TypeString,
Required: true,
Description: "The region where the asset instance is located.",
},
},
},
},
},
}
}

func dataSourceTencentCloudDayuEipRead(d *schema.ResourceData, meta interface{}) error {
defer logElapsed("data_source.tencentcloud_dayu_l4_rules.read")()

logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)

resourceId := d.Get("resource_id").(string)
var bindStatus []string
if v, ok := d.GetOk("bind_status"); ok {
tmpBindStatusList := v.([]interface{})
for _, tmpBindStatus := range tmpBindStatusList {
bindStatus = append(bindStatus, tmpBindStatus.(string))
}
} else {
bindStatus = DDOS_EIP_BIND_STATUS
}
offset := d.Get("offset").(int)
limit := d.Get("limit").(int)

antiddosService := AntiddosService{client: meta.(*TencentCloudClient).apiV3Conn}
result, err := antiddosService.DescribeListBGPIPInstances(ctx, resourceId, bindStatus, offset, limit)
if err != nil {
return err
}
resultList := make([]map[string]interface{}, 0)
for _, eipItem := range result {
tmpEipInfo := make(map[string]interface{})
eipList := make([]string, 0)
for _, eip := range eipItem.InstanceDetail.EipList {
eipList = append(eipList, *eip)
}
tmpEipInfo["eip_list"] = eipList
tmpEipInfo["instance_id"] = *eipItem.InstanceDetail.InstanceId
tmpEipInfo["region"] = *eipItem.Region.Region
tmpEipInfo["eip_bound_rsc_ins"] = *eipItem.EipAddressInfo.EipBoundRscIns
tmpEipInfo["eip_bound_rsc_eni"] = *eipItem.EipAddressInfo.EipBoundRscEni
tmpEipInfo["eip_bound_rsc_vip"] = *eipItem.EipAddressInfo.EipBoundRscVip
tmpEipInfo["eip_address_status"] = *eipItem.EipAddressStatus
tmpEipInfo["protection_status"] = *eipItem.Status
tmpEipInfo["created_time"] = *eipItem.CreatedTime
tmpEipInfo["expired_time"] = *eipItem.ExpiredTime
tmpEipInfo["modify_time"] = *eipItem.EipAddressInfo.ModifyTime

resultList = append(resultList, tmpEipInfo)
}
ids := make([]string, 0, len(resultList))
for _, listItem := range resultList {
ids = append(ids, listItem["instance_id"].(string))
}
d.SetId(helper.DataResourceIdsHash(ids))
_ = d.Set("list", resultList)
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
return writeToFile(output.(string), resultList)
}
return nil

}
41 changes: 41 additions & 0 deletions tencentcloud/data_source_tc_dayu_eip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tencentcloud

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

var testDataDayuEip = "data.tencentcloud_dayu_eip.test"

func TestAccTencentCloudDataDayuEip(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheckCommon(t, ACCTUNT_TYPE_INTERNATION) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDayuEipDestroy,
Steps: []resource.TestStep{
{
Config: testAccTencentCloudDataDayuEip,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDayuEipExists("tencentcloud_dayu_eip.test_eip"),
resource.TestCheckResourceAttr(testDataDayuEip, "list.#", "1"),
),
},
},
})
}

const testAccTencentCloudDataDayuEip = `
resource "tencentcloud_dayu_eip" "test_eip" {
resource_id = "bgpip-000004xg"
eip = "162.62.163.50"
bind_resource_id = "ins-4m0jvxic"
bind_resource_region = "hk"
bind_resource_type = "cvm"
}

data "tencentcloud_dayu_eip" "test" {
resource_id = tencentcloud_dayu_eip.test_eip.resource_id
}
`
Loading