|
| 1 | +package dnspod |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "log" |
| 6 | + |
| 7 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 9 | + dnspod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod/v20210323" |
| 10 | + |
| 11 | + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" |
| 12 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 13 | +) |
| 14 | + |
| 15 | +func ResourceTencentCloudSubdomainValidateTxtValueOperation() *schema.Resource { |
| 16 | + return &schema.Resource{ |
| 17 | + Create: resourceTencentCloudSubdomainValidateTxtValueOperationCreate, |
| 18 | + Read: resourceTencentCloudSubdomainValidateTxtValueOperationRead, |
| 19 | + Delete: resourceTencentCloudSubdomainValidateTxtValueOperationDelete, |
| 20 | + Schema: map[string]*schema.Schema{ |
| 21 | + "domain_zone": { |
| 22 | + Type: schema.TypeString, |
| 23 | + Required: true, |
| 24 | + ForceNew: true, |
| 25 | + Description: "The subdomain to add Zone domain.", |
| 26 | + }, |
| 27 | + "domain": { |
| 28 | + Type: schema.TypeString, |
| 29 | + Computed: true, |
| 30 | + Description: "The domain name for which TXT records need to be added.", |
| 31 | + }, |
| 32 | + "subdomain": { |
| 33 | + Type: schema.TypeString, |
| 34 | + Computed: true, |
| 35 | + Description: "Host records that need to be added to TXT records.", |
| 36 | + }, |
| 37 | + "record_type": { |
| 38 | + Type: schema.TypeString, |
| 39 | + Computed: true, |
| 40 | + Description: "Record types need to be added.", |
| 41 | + }, |
| 42 | + "value": { |
| 43 | + Type: schema.TypeString, |
| 44 | + Computed: true, |
| 45 | + Description: "The record value of the TXT record needs to be added.", |
| 46 | + }, |
| 47 | + }, |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +func resourceTencentCloudSubdomainValidateTxtValueOperationCreate(d *schema.ResourceData, meta interface{}) error { |
| 52 | + defer tccommon.LogElapsed("resource.tencentcloud_subdomain_validate_txt_value_operation.create")() |
| 53 | + defer tccommon.InconsistentCheck(d, meta)() |
| 54 | + |
| 55 | + logId := tccommon.GetLogId(tccommon.ContextNil) |
| 56 | + |
| 57 | + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) |
| 58 | + |
| 59 | + var ( |
| 60 | + domainZone string |
| 61 | + ) |
| 62 | + var ( |
| 63 | + request = dnspod.NewCreateSubdomainValidateTXTValueRequest() |
| 64 | + response = dnspod.NewCreateSubdomainValidateTXTValueResponse() |
| 65 | + ) |
| 66 | + |
| 67 | + if v, ok := d.GetOk("domain_zone"); ok { |
| 68 | + domainZone = v.(string) |
| 69 | + } |
| 70 | + |
| 71 | + request.DomainZone = helper.String(domainZone) |
| 72 | + |
| 73 | + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { |
| 74 | + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseDnsPodClient().CreateSubdomainValidateTXTValueWithContext(ctx, request) |
| 75 | + if e != nil { |
| 76 | + return tccommon.RetryError(e) |
| 77 | + } else { |
| 78 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
| 79 | + } |
| 80 | + response = result |
| 81 | + return nil |
| 82 | + }) |
| 83 | + if err != nil { |
| 84 | + log.Printf("[CRITAL]%s create subdomain validate txt value operation failed, reason:%+v", logId, err) |
| 85 | + return err |
| 86 | + } |
| 87 | + |
| 88 | + if response.Response != nil { |
| 89 | + if response.Response.Domain != nil { |
| 90 | + _ = d.Set("domain", response.Response.Domain) |
| 91 | + } |
| 92 | + if response.Response.Domain != nil { |
| 93 | + _ = d.Set("subdomain", response.Response.Subdomain) |
| 94 | + } |
| 95 | + if response.Response.Domain != nil { |
| 96 | + _ = d.Set("record_type", response.Response.RecordType) |
| 97 | + } |
| 98 | + if response.Response.Domain != nil { |
| 99 | + _ = d.Set("value", response.Response.Value) |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + _ = response |
| 104 | + |
| 105 | + d.SetId(domainZone) |
| 106 | + |
| 107 | + return resourceTencentCloudSubdomainValidateTxtValueOperationRead(d, meta) |
| 108 | +} |
| 109 | + |
| 110 | +func resourceTencentCloudSubdomainValidateTxtValueOperationRead(d *schema.ResourceData, meta interface{}) error { |
| 111 | + defer tccommon.LogElapsed("resource.tencentcloud_subdomain_validate_txt_value_operation.read")() |
| 112 | + defer tccommon.InconsistentCheck(d, meta)() |
| 113 | + |
| 114 | + return nil |
| 115 | +} |
| 116 | + |
| 117 | +func resourceTencentCloudSubdomainValidateTxtValueOperationDelete(d *schema.ResourceData, meta interface{}) error { |
| 118 | + defer tccommon.LogElapsed("resource.tencentcloud_subdomain_validate_txt_value_operation.delete")() |
| 119 | + defer tccommon.InconsistentCheck(d, meta)() |
| 120 | + |
| 121 | + return nil |
| 122 | +} |
0 commit comments