|
| 1 | +/* |
| 2 | +Use this data source to query detailed information of cvm disaster_recover_group_quota |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +data "tencentcloud_cvm_disaster_recover_group_quota" "disaster_recover_group_quota" { |
| 8 | +} |
| 9 | +``` |
| 10 | +*/ |
| 11 | +package tencentcloud |
| 12 | + |
| 13 | +import ( |
| 14 | + "fmt" |
| 15 | + |
| 16 | + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" |
| 17 | + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" |
| 18 | + cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" |
| 19 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 20 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/ratelimit" |
| 21 | +) |
| 22 | + |
| 23 | +func dataSourceTencentCloudCvmDisasterRecoverGroupQuota() *schema.Resource { |
| 24 | + return &schema.Resource{ |
| 25 | + Read: dataSourceTencentCloudCvmDisasterRecoverGroupQuotaRead, |
| 26 | + Schema: map[string]*schema.Schema{ |
| 27 | + "group_quota": { |
| 28 | + Computed: true, |
| 29 | + Type: schema.TypeInt, |
| 30 | + Description: "The maximum number of placement groups that can be created.", |
| 31 | + }, |
| 32 | + |
| 33 | + "current_num": { |
| 34 | + Computed: true, |
| 35 | + Type: schema.TypeInt, |
| 36 | + Description: "The number of placement groups that have been created by the current user.", |
| 37 | + }, |
| 38 | + |
| 39 | + "cvm_in_host_group_quota": { |
| 40 | + Computed: true, |
| 41 | + Type: schema.TypeInt, |
| 42 | + Description: "Quota on instances in a physical-machine-type disaster recovery group.", |
| 43 | + }, |
| 44 | + |
| 45 | + "cvm_in_sw_group_quota": { |
| 46 | + Computed: true, |
| 47 | + Type: schema.TypeInt, |
| 48 | + Description: "Quota on instances in a switch-type disaster recovery group.", |
| 49 | + }, |
| 50 | + |
| 51 | + "cvm_in_rack_group_quota": { |
| 52 | + Computed: true, |
| 53 | + Type: schema.TypeInt, |
| 54 | + Description: "Quota on instances in a rack-type disaster recovery group.", |
| 55 | + }, |
| 56 | + |
| 57 | + "result_output_file": { |
| 58 | + Type: schema.TypeString, |
| 59 | + Optional: true, |
| 60 | + Description: "Used to save results.", |
| 61 | + }, |
| 62 | + }, |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func dataSourceTencentCloudCvmDisasterRecoverGroupQuotaRead(d *schema.ResourceData, meta interface{}) error { |
| 67 | + defer logElapsed("data_source.tencentcloud_cvm_disaster_recover_group_quota.read")() |
| 68 | + defer inconsistentCheck(d, meta)() |
| 69 | + |
| 70 | + var response *cvm.DescribeDisasterRecoverGroupQuotaResponse |
| 71 | + |
| 72 | + request := cvm.NewDescribeDisasterRecoverGroupQuotaRequest() |
| 73 | + err := resource.Retry(readRetryTimeout, func() *resource.RetryError { |
| 74 | + ratelimit.Check(request.GetAction()) |
| 75 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseCvmClient().DescribeDisasterRecoverGroupQuota(request) |
| 76 | + if e != nil { |
| 77 | + return retryError(e) |
| 78 | + } |
| 79 | + response = result |
| 80 | + return nil |
| 81 | + }) |
| 82 | + if err != nil { |
| 83 | + return err |
| 84 | + } |
| 85 | + if response == nil || response.Response == nil { |
| 86 | + d.SetId("") |
| 87 | + return fmt.Errorf("Response is nil") |
| 88 | + } |
| 89 | + _ = d.Set("group_quota", response.Response.GroupQuota) |
| 90 | + _ = d.Set("current_num", response.Response.CurrentNum) |
| 91 | + _ = d.Set("cvm_in_host_group_quota", response.Response.CvmInHostGroupQuota) |
| 92 | + _ = d.Set("cvm_in_sw_group_quota", response.Response.CvmInSwGroupQuota) |
| 93 | + _ = d.Set("cvm_in_rack_group_quota", response.Response.CvmInRackGroupQuota) |
| 94 | + |
| 95 | + d.SetId(helper.BuildToken()) |
| 96 | + output, ok := d.GetOk("result_output_file") |
| 97 | + if ok && output.(string) != "" { |
| 98 | + if e := writeToFile(output.(string), map[string]interface{}{ |
| 99 | + "group_quota": response.Response.GroupQuota, |
| 100 | + "current_num": response.Response.CurrentNum, |
| 101 | + "cvm_in_host_group_quota": response.Response.CvmInHostGroupQuota, |
| 102 | + "cvm_in_sw_group_quota": response.Response.CvmInSwGroupQuota, |
| 103 | + "cvm_in_rack_group_quota": response.Response.CvmInRackGroupQuota, |
| 104 | + }); e != nil { |
| 105 | + return e |
| 106 | + } |
| 107 | + } |
| 108 | + return nil |
| 109 | +} |
0 commit comments