Skip to content

Commit

Permalink
support dns-validate-txt
Browse files Browse the repository at this point in the history
  • Loading branch information
mikatong committed Dec 10, 2024
1 parent f83afbf commit a1aaa18
Show file tree
Hide file tree
Showing 19 changed files with 4,055 additions and 1,248 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1034
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.1033
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.1046
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1056
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1014
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
Expand All @@ -55,7 +55,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.633
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.673
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc v1.0.797
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.831
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.1056
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/domain v1.0.414
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.628
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/eb v1.0.760
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1051 h1:3mg
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1051/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052 h1:RCs8aH5Gy1sn4qc22KweqQE7usx1S2reyZcedo0ZXBI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1052/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1056 h1:bOSZ7cOXvBe8MCBqDBTtpyKIqx9q6woxqIPK5M9FhNY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1056/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 @@ -958,6 +960,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc v1.0.797 h1:6hfb2rn
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dlc v1.0.797/go.mod h1:7nIkeQ6XbNx8aLuX5MxZExH0WVmQDIsHbb7Mk/JunPg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.831 h1:i9HuRYmEzqPwExDt/hRsjP6Rw5S6aoinKzqe0OLkFQg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.831/go.mod h1:OtG3j11r/hDfZufRkTux+XHnfHw5UGqlMgrZxtUbsSs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.1056 h1:kvJuKukDqbt1nKzaVRdcbvs3w9CoMz3V1oQp6jo3rSw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.1056/go.mod h1:TLTlcL7Dr1p0vPg0NvOi1CJEx2xG1zTlP+4k+ggxnZE=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/domain v1.0.414 h1:egwjvOEUKBaxsoRVn/YSEhp2E8qdh77Ous9A/wftDo0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/domain v1.0.414/go.mod h1:LRWnBUNRxs/Ee8MzJJd3eHzydlqyB5qmia975Ca/Ox0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.628 h1:cnhe9uh8tSyBfiPUckfqNI6t51YNZG9POupTrqWG9lM=
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ func Provider() *schema.Provider {
"tencentcloud_dnspod_record_line_list": dnspod.DataSourceTencentCloudDnspodRecordLineList(),
"tencentcloud_dnspod_record_list": dnspod.DataSourceTencentCloudDnspodRecordList(),
"tencentcloud_dnspod_record_type": dnspod.DataSourceTencentCloudDnspodRecordType(),
"tencentcloud_subdomain_validate_status": dnspod.DataSourceTencentCloudSubdomainValidateStatus(),
"tencentcloud_tat_command": tat.DataSourceTencentCloudTatCommand(),
"tencentcloud_tat_invoker": tat.DataSourceTencentCloudTatInvoker(),
"tencentcloud_tat_invoker_records": tat.DataSourceTencentCloudTatInvokerRecords(),
Expand Down Expand Up @@ -1685,6 +1686,7 @@ func Provider() *schema.Provider {
"tencentcloud_dnspod_custom_line": dnspod.ResourceTencentCloudDnspodCustomLine(),
"tencentcloud_dnspod_snapshot_config": dnspod.ResourceTencentCloudDnspodSnapshotConfig(),
"tencentcloud_dnspod_domain_lock": dnspod.ResourceTencentCloudDnspodDomainLock(),
"tencentcloud_subdomain_validate_txt_value_operation": dnspod.ResourceTencentCloudSubdomainValidateTxtValueOperation(),
"tencentcloud_private_dns_zone": privatedns.ResourceTencentCloudPrivateDnsZone(),
"tencentcloud_private_dns_record": privatedns.ResourceTencentCloudPrivateDnsRecord(),
"tencentcloud_private_dns_zone_vpc_attachment": privatedns.ResourceTencentCloudPrivateDnsZoneVpcAttachment(),
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ DNSPOD
tencentcloud_dnspod_custom_line
tencentcloud_dnspod_snapshot_config
tencentcloud_dnspod_domain_lock
tencentcloud_subdomain_validate_txt_value_operation

Data Source
tencentcloud_dnspod_records
Expand All @@ -1348,6 +1349,7 @@ DNSPOD
tencentcloud_dnspod_record_line_list
tencentcloud_dnspod_record_list
tencentcloud_dnspod_record_type
tencentcloud_subdomain_validate_status

PrivateDNS
Resource
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package dnspod

import (
"context"

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

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func DataSourceTencentCloudSubdomainValidateStatus() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudSubdomainValidateStatusRead,
Schema: map[string]*schema.Schema{
"domain_zone": {
Type: schema.TypeString,
Required: true,
Description: "Zone domain for which to view the verification status of TXT records.",
},

"status": {
Type: schema.TypeInt,
Computed: true,
Description: "Status. 0: not ready; 1: ready.",
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudSubdomainValidateStatusRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_subdomain_validate_status.read")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)
ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)

service := DnspodService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

var (
domainZone string
)
if v, ok := d.GetOk("domain_zone"); ok {
domainZone = v.(string)
}
paramMap := make(map[string]interface{})
if v, ok := d.GetOk("domain_zone"); ok {
paramMap["DomainZone"] = helper.String(v.(string))
}

var status int
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeSubdomainValidateStatusByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
status = result
return nil
})
if err != nil {
return err
}

d.SetId(domainZone)
_ = d.Set("status", status)

output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), d); e != nil {
return e
}
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Use this data source to query detailed information of dnspod subdomain_validate_status

Example Usage

```hcl
data "tencentcloud_subdomain_validate_status" "subdomain_validate_status" {
domain_zone = "www.iac-tf.cloud"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dnspod_test

import (
"testing"

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

tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
)

func TestAccTencentCloudSubdomainValidateStatusDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{{
Config: testAccSubdomainValidateStatusDataSource,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_subdomain_validate_status.subdomain_validate_status"),
resource.TestCheckResourceAttr("data.tencentcloud_subdomain_validate_status.subdomain_validate_status", "status", "1"),
),
}},
})
}

func TestAccTencentCloudSubdomainValidateStatusDataSource_notReady(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{{
Config: testAccSubdomainValidateStatusDataSourceNotReady,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_subdomain_validate_status.subdomain_validate_status"),
resource.TestCheckResourceAttr("data.tencentcloud_subdomain_validate_status.subdomain_validate_status", "status", "0"),
),
}},
})
}

const testAccSubdomainValidateStatusDataSource = `
data "tencentcloud_subdomain_validate_status" "subdomain_validate_status" {
domain_zone = "www.iac-tf.cloud"
}
`

const testAccSubdomainValidateStatusDataSourceNotReady = `
data "tencentcloud_subdomain_validate_status" "subdomain_validate_status" {
domain_zone = "www.iac-tf.com"
}
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package dnspod

import (
"context"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
dnspod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func ResourceTencentCloudSubdomainValidateTxtValueOperation() *schema.Resource {
return &schema.Resource{
Create: resourceTencentCloudSubdomainValidateTxtValueOperationCreate,
Read: resourceTencentCloudSubdomainValidateTxtValueOperationRead,
Delete: resourceTencentCloudSubdomainValidateTxtValueOperationDelete,
Schema: map[string]*schema.Schema{
"domain_zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The subdomain to add Zone domain.",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "The domain name for which TXT records need to be added.",
},
"subdomain": {
Type: schema.TypeString,
Computed: true,
Description: "Host records that need to be added to TXT records.",
},
"record_type": {
Type: schema.TypeString,
Computed: true,
Description: "Record types need to be added.",
},
"value": {
Type: schema.TypeString,
Computed: true,
Description: "The record value of the TXT record needs to be added.",
},
},
}
}

func resourceTencentCloudSubdomainValidateTxtValueOperationCreate(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_subdomain_validate_txt_value_operation.create")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(tccommon.ContextNil)

ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)

var (
domainZone string
)
var (
request = dnspod.NewCreateSubdomainValidateTXTValueRequest()
response = dnspod.NewCreateSubdomainValidateTXTValueResponse()
)

if v, ok := d.GetOk("domain_zone"); ok {
domainZone = v.(string)
}

request.DomainZone = helper.String(domainZone)

err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDnsPodClient().CreateSubdomainValidateTXTValueWithContext(ctx, request)
if e != nil {
return tccommon.RetryError(e)
} else {
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
}
response = result
return nil
})
if err != nil {
log.Printf("[CRITAL]%s create subdomain validate txt value operation failed, reason:%+v", logId, err)
return err
}

if response.Response != nil {
if response.Response.Domain != nil {
_ = d.Set("domain", response.Response.Domain)
}
if response.Response.Domain != nil {
_ = d.Set("subdomain", response.Response.Subdomain)
}
if response.Response.Domain != nil {
_ = d.Set("record_type", response.Response.RecordType)
}
if response.Response.Domain != nil {
_ = d.Set("value", response.Response.Value)
}
}

_ = response

d.SetId(domainZone)

return resourceTencentCloudSubdomainValidateTxtValueOperationRead(d, meta)
}

func resourceTencentCloudSubdomainValidateTxtValueOperationRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_subdomain_validate_txt_value_operation.read")()
defer tccommon.InconsistentCheck(d, meta)()

return nil
}

func resourceTencentCloudSubdomainValidateTxtValueOperationDelete(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("resource.tencentcloud_subdomain_validate_txt_value_operation.delete")()
defer tccommon.InconsistentCheck(d, meta)()

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Provides a resource to create a dnspod subdomain_validate_txt_value_operation

Example Usage

```hcl
resource "tencentcloud_subdomain_validate_txt_value_operation" "subdomain_validate_txt_value_operation" {
domain_zone = "www.iac-tf.cloud"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dnspod_test

import (
"testing"

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

tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
)

func TestAccTencentCloudSubdomainValidateTxtValueOperationResource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccSubdomainValidateTxtValueOperation,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("tencentcloud_subdomain_validate_txt_value_operation.subdomain_validate_txt_value_operation", "id"),
resource.TestCheckResourceAttr("tencentcloud_subdomain_validate_txt_value_operation.subdomain_validate_txt_value_operation", "domain", "iac-tf.cloud"),
resource.TestCheckResourceAttr("tencentcloud_subdomain_validate_txt_value_operation.subdomain_validate_txt_value_operation", "domain_zone", "www.iac-tf.cloud"),
resource.TestCheckResourceAttr("tencentcloud_subdomain_validate_txt_value_operation.subdomain_validate_txt_value_operation", "record_type", "TXT"),
resource.TestCheckResourceAttrSet("tencentcloud_subdomain_validate_txt_value_operation.subdomain_validate_txt_value_operation", "subdomain"),
resource.TestCheckResourceAttrSet("tencentcloud_subdomain_validate_txt_value_operation.subdomain_validate_txt_value_operation", "value"),
),
},
},
})
}

const testAccSubdomainValidateTxtValueOperation = `
resource "tencentcloud_subdomain_validate_txt_value_operation" "subdomain_validate_txt_value_operation" {
domain_zone = "www.iac-tf.cloud"
}
`
Loading

0 comments on commit a1aaa18

Please sign in to comment.