|
| 1 | +/* |
| 2 | +Provides a resource to create a vpc ccn_instances_reset_attach, you can use this resource to reset cross-region attachment. |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +resource "tencentcloud_ccn_instances_reset_attach" "ccn_instances_reset_attach" { |
| 8 | + ccn_id = "ccn-39lqkygf" |
| 9 | + ccn_uin = "100022975249" |
| 10 | + instances { |
| 11 | + instance_id = "vpc-j9yhbzpn" |
| 12 | + instance_region = "ap-guangzhou" |
| 13 | + instance_type = "VPC" |
| 14 | + } |
| 15 | +} |
| 16 | +``` |
| 17 | +*/ |
| 18 | +package tencentcloud |
| 19 | + |
| 20 | +import ( |
| 21 | + "fmt" |
| 22 | + "log" |
| 23 | + |
| 24 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 25 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 26 | + vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312" |
| 27 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 28 | +) |
| 29 | + |
| 30 | +func resourceTencentCloudCcnInstancesResetAttach() *schema.Resource { |
| 31 | + return &schema.Resource{ |
| 32 | + Create: resourceTencentCloudCcnInstancesResetAttachCreate, |
| 33 | + Read: resourceTencentCloudCcnInstancesResetAttachRead, |
| 34 | + Delete: resourceTencentCloudCcnInstancesResetAttachDelete, |
| 35 | + Schema: map[string]*schema.Schema{ |
| 36 | + "ccn_id": { |
| 37 | + Required: true, |
| 38 | + ForceNew: true, |
| 39 | + Type: schema.TypeString, |
| 40 | + Description: "CCN Instance ID.", |
| 41 | + }, |
| 42 | + |
| 43 | + "ccn_uin": { |
| 44 | + Required: true, |
| 45 | + ForceNew: true, |
| 46 | + Type: schema.TypeString, |
| 47 | + Description: "CCN Uin (root account).", |
| 48 | + }, |
| 49 | + |
| 50 | + "instances": { |
| 51 | + Required: true, |
| 52 | + ForceNew: true, |
| 53 | + Type: schema.TypeList, |
| 54 | + Description: "List Of Attachment Instances.", |
| 55 | + Elem: &schema.Resource{ |
| 56 | + Schema: map[string]*schema.Schema{ |
| 57 | + "instance_id": { |
| 58 | + Type: schema.TypeString, |
| 59 | + Required: true, |
| 60 | + Description: "Attachment Instance ID.", |
| 61 | + }, |
| 62 | + "instance_region": { |
| 63 | + Type: schema.TypeString, |
| 64 | + Required: true, |
| 65 | + Description: "Instance Region.", |
| 66 | + }, |
| 67 | + "instance_type": { |
| 68 | + Type: schema.TypeString, |
| 69 | + Optional: true, |
| 70 | + Description: "InstanceType: `VPC`, `DIRECTCONNECT`, `BMVPC`, `VPNGW`.", |
| 71 | + }, |
| 72 | + "description": { |
| 73 | + Type: schema.TypeString, |
| 74 | + Optional: true, |
| 75 | + Description: "Description.", |
| 76 | + }, |
| 77 | + "route_table_id": { |
| 78 | + Type: schema.TypeString, |
| 79 | + Optional: true, |
| 80 | + Description: "ID of the routing table associated with the instance. Note: This field may return null, indicating that no valid value can be obtained.", |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +func resourceTencentCloudCcnInstancesResetAttachCreate(d *schema.ResourceData, meta interface{}) error { |
| 90 | + defer logElapsed("data_source.tencentcloud_vpc_ccn_instances_reset_attach.read")() |
| 91 | + defer inconsistentCheck(d, meta)() |
| 92 | + |
| 93 | + logId := getLogId(contextNil) |
| 94 | + |
| 95 | + var ( |
| 96 | + request = vpc.NewResetAttachCcnInstancesRequest() |
| 97 | + ccnId string |
| 98 | + ) |
| 99 | + if v, ok := d.GetOk("ccn_id"); ok { |
| 100 | + ccnId = v.(string) |
| 101 | + request.CcnId = helper.String(v.(string)) |
| 102 | + } |
| 103 | + |
| 104 | + if v, ok := d.GetOk("ccn_uin"); ok { |
| 105 | + request.CcnUin = helper.String(v.(string)) |
| 106 | + } |
| 107 | + |
| 108 | + if v, ok := d.GetOk("instances"); ok { |
| 109 | + for _, item := range v.([]interface{}) { |
| 110 | + dMap := item.(map[string]interface{}) |
| 111 | + ccnInstance := vpc.CcnInstance{} |
| 112 | + if v, ok := dMap["instance_id"]; ok { |
| 113 | + ccnInstance.InstanceId = helper.String(v.(string)) |
| 114 | + } |
| 115 | + if v, ok := dMap["instance_region"]; ok { |
| 116 | + ccnInstance.InstanceRegion = helper.String(v.(string)) |
| 117 | + } |
| 118 | + if v, ok := dMap["instance_type"]; ok { |
| 119 | + ccnInstance.InstanceType = helper.String(v.(string)) |
| 120 | + } |
| 121 | + if v, ok := dMap["description"]; ok { |
| 122 | + ccnInstance.Description = helper.String(v.(string)) |
| 123 | + } |
| 124 | + if v, ok := dMap["route_table_id"]; ok { |
| 125 | + routeTableId := v.(string) |
| 126 | + if routeTableId != "" { |
| 127 | + ccnInstance.RouteTableId = helper.String(v.(string)) |
| 128 | + } |
| 129 | + } |
| 130 | + request.Instances = append(request.Instances, &ccnInstance) |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { |
| 135 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseVpcClient().ResetAttachCcnInstances(request) |
| 136 | + if e != nil { |
| 137 | + return retryError(e) |
| 138 | + } else { |
| 139 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
| 140 | + } |
| 141 | + return nil |
| 142 | + }) |
| 143 | + if err != nil { |
| 144 | + return fmt.Errorf("[CRITAL]%s operate vpc ccnInstancesResetAttach failed, reason:%+v", logId, err) |
| 145 | + } |
| 146 | + |
| 147 | + d.SetId(ccnId) |
| 148 | + |
| 149 | + return resourceTencentCloudCcnInstancesResetAttachRead(d, meta) |
| 150 | +} |
| 151 | + |
| 152 | +func resourceTencentCloudCcnInstancesResetAttachRead(d *schema.ResourceData, meta interface{}) error { |
| 153 | + defer logElapsed("resource.tencentcloud_ccn_instances_reset_attach.read")() |
| 154 | + defer inconsistentCheck(d, meta)() |
| 155 | + |
| 156 | + return nil |
| 157 | +} |
| 158 | + |
| 159 | +func resourceTencentCloudCcnInstancesResetAttachDelete(d *schema.ResourceData, meta interface{}) error { |
| 160 | + defer logElapsed("resource.tencentcloudccn_instances_reset_attach.delete")() |
| 161 | + defer inconsistentCheck(d, meta)() |
| 162 | + |
| 163 | + return nil |
| 164 | +} |
0 commit comments