|
9 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
|
10 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
11 | 11 | cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
|
| 12 | + svccbs "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/services/cbs" |
12 | 13 |
|
13 | 14 | "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
|
14 | 15 | )
|
@@ -61,6 +62,40 @@ func DataSourceTencentCloudInstanceTypes() *schema.Resource {
|
61 | 62 | },
|
62 | 63 | },
|
63 | 64 | },
|
| 65 | + "cbs_filter": { |
| 66 | + Type: schema.TypeList, |
| 67 | + Optional: true, |
| 68 | + Description: "Cbs filter.", |
| 69 | + MaxItems: 1, |
| 70 | + Elem: &schema.Resource{ |
| 71 | + Schema: map[string]*schema.Schema{ |
| 72 | + "disk_types": { |
| 73 | + Type: schema.TypeList, |
| 74 | + Optional: true, |
| 75 | + Elem: &schema.Schema{Type: schema.TypeString}, |
| 76 | + Description: "Hard disk media type. Value range:\n" + |
| 77 | + " - CLOUD_BASIC: Represents ordinary Cloud Block Storage;\n" + |
| 78 | + " - CLOUD_PREMIUM: Represents high-performance Cloud Block Storage;\n" + |
| 79 | + " - CLOUD_SSD: Represents SSD Cloud Block Storage;\n" + |
| 80 | + " - CLOUD_HSSD: Represents enhanced SSD Cloud Block Storage.", |
| 81 | + }, |
| 82 | + "disk_charge_type": { |
| 83 | + Type: schema.TypeString, |
| 84 | + Optional: true, |
| 85 | + Description: "Payment model. Value range:\n" + |
| 86 | + " - PREPAID: Prepaid;\n" + |
| 87 | + " - POSTPAID_BY_HOUR: Post-payment.", |
| 88 | + }, |
| 89 | + "disk_usage": { |
| 90 | + Type: schema.TypeString, |
| 91 | + Optional: true, |
| 92 | + Description: "System disk or data disk. Value range:\n" + |
| 93 | + " - SYSTEM_DISK: Represents the system disk;\n" + |
| 94 | + " - DATA_DISK: Represents the data disk.", |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + }, |
64 | 99 | "exclude_sold_out": {
|
65 | 100 | Type: schema.TypeBool,
|
66 | 101 | Optional: true,
|
@@ -120,6 +155,79 @@ func DataSourceTencentCloudInstanceTypes() *schema.Resource {
|
120 | 155 | Computed: true,
|
121 | 156 | Description: "Sell status of the instance.",
|
122 | 157 | },
|
| 158 | + "cbs_configs": { |
| 159 | + Type: schema.TypeList, |
| 160 | + Computed: true, |
| 161 | + Description: "CBS config. The cbs_configs is populated when the cbs_filter is added.", |
| 162 | + Elem: &schema.Resource{ |
| 163 | + Schema: map[string]*schema.Schema{ |
| 164 | + "available": { |
| 165 | + Type: schema.TypeBool, |
| 166 | + Computed: true, |
| 167 | + Description: "Whether the configuration is available.", |
| 168 | + }, |
| 169 | + "disk_charge_type": { |
| 170 | + Type: schema.TypeString, |
| 171 | + Computed: true, |
| 172 | + Description: "Payment model. Value range:\n" + |
| 173 | + " - PREPAID: Prepaid;\n" + |
| 174 | + " - POSTPAID_BY_HOUR: Post-payment.", |
| 175 | + }, |
| 176 | + "zone": { |
| 177 | + Type: schema.TypeString, |
| 178 | + Computed: true, |
| 179 | + Description: "The availability zone to which the Cloud Block Storage belongs.", |
| 180 | + }, |
| 181 | + "instance_family": { |
| 182 | + Type: schema.TypeString, |
| 183 | + Computed: true, |
| 184 | + Description: "Instance family.", |
| 185 | + }, |
| 186 | + "disk_type": { |
| 187 | + Type: schema.TypeString, |
| 188 | + Computed: true, |
| 189 | + Description: "Hard disk media type. Value range:\n" + |
| 190 | + " - CLOUD_BASIC: Represents ordinary Cloud Block Storage;\n" + |
| 191 | + " - CLOUD_PREMIUM: Represents high-performance Cloud Block Storage;\n" + |
| 192 | + " - CLOUD_SSD: Represents SSD Cloud Block Storage;\n" + |
| 193 | + " - CLOUD_HSSD: Represents enhanced SSD Cloud Block Storage.", |
| 194 | + }, |
| 195 | + "step_size": { |
| 196 | + Type: schema.TypeInt, |
| 197 | + Computed: true, |
| 198 | + Description: "Minimum step size change in cloud disk size, in GB.", |
| 199 | + }, |
| 200 | + "extra_performance_range": { |
| 201 | + Computed: true, |
| 202 | + Type: schema.TypeList, |
| 203 | + Elem: &schema.Schema{Type: schema.TypeInt}, |
| 204 | + Description: "Extra performance range.", |
| 205 | + }, |
| 206 | + "device_class": { |
| 207 | + Type: schema.TypeString, |
| 208 | + Computed: true, |
| 209 | + Description: "Device class.", |
| 210 | + }, |
| 211 | + "disk_usage": { |
| 212 | + Type: schema.TypeString, |
| 213 | + Computed: true, |
| 214 | + Description: "Cloud disk type. Value range:\n" + |
| 215 | + " - SYSTEM_DISK: Represents the system disk;\n" + |
| 216 | + " - DATA_DISK: Represents the data disk.", |
| 217 | + }, |
| 218 | + "min_disk_size": { |
| 219 | + Type: schema.TypeInt, |
| 220 | + Computed: true, |
| 221 | + Description: "The minimum configurable cloud disk size, in GB.", |
| 222 | + }, |
| 223 | + "max_disk_size": { |
| 224 | + Type: schema.TypeInt, |
| 225 | + Computed: true, |
| 226 | + Description: "The maximum configurable cloud disk size, in GB.", |
| 227 | + }, |
| 228 | + }, |
| 229 | + }, |
| 230 | + }, |
123 | 231 | },
|
124 | 232 | },
|
125 | 233 | },
|
@@ -207,6 +315,65 @@ func dataSourceTencentCloudInstanceTypesRead(d *schema.ResourceData, meta interf
|
207 | 315 | }
|
208 | 316 | }
|
209 | 317 |
|
| 318 | + client := meta.(tccommon.ProviderMeta).GetAPIV3Conn() |
| 319 | + cbsService := svccbs.NewCbsService(client) |
| 320 | + cbsFilterParams := make(map[string]interface{}) |
| 321 | + var hasCbsFilter bool |
| 322 | + if dMap, ok := helper.InterfacesHeadMap(d, "cbs_filter"); ok { |
| 323 | + if v, ok := dMap["disk_types"].([]interface{}); ok && len(v) > 0 { |
| 324 | + cbsFilterParams["disk_types"] = helper.InterfacesStrings(v) |
| 325 | + } |
| 326 | + if v, ok := dMap["disk_charge_type"].(string); ok && v != "" { |
| 327 | + cbsFilterParams["disk_charge_type"] = v |
| 328 | + } |
| 329 | + if v, ok := dMap["disk_usage"].(string); ok && v != "" { |
| 330 | + cbsFilterParams["disk_usage"] = v |
| 331 | + } |
| 332 | + hasCbsFilter = true |
| 333 | + } |
| 334 | + if hasCbsFilter { |
| 335 | + for idx, t := range typeList { |
| 336 | + filterParams := make(map[string]interface{}) |
| 337 | + for k, v := range cbsFilterParams { |
| 338 | + filterParams[k] = v |
| 339 | + } |
| 340 | + |
| 341 | + if v, ok := t["availability_zone"].(*string); ok && v != nil { |
| 342 | + filterParams["availability_zone"] = *v |
| 343 | + } |
| 344 | + if v, ok := t["cpu_core_count"].(*int64); ok && v != nil { |
| 345 | + filterParams["cpu_core_count"] = *v |
| 346 | + } |
| 347 | + if v, ok := t["memory_size"].(*int64); ok && v != nil { |
| 348 | + filterParams["memory_size"] = *v |
| 349 | + } |
| 350 | + if v, ok := t["family"].(*string); ok && v != nil { |
| 351 | + filterParams["family"] = *v |
| 352 | + } |
| 353 | + diskConfigSet, err := cbsService.DescribeDiskConfigQuota(ctx, filterParams) |
| 354 | + if err != nil { |
| 355 | + return err |
| 356 | + } |
| 357 | + cbsConfigList := make([]interface{}, 0) |
| 358 | + for _, diskConfig := range diskConfigSet { |
| 359 | + cbsConfigList = append(cbsConfigList, map[string]interface{}{ |
| 360 | + "available": diskConfig.Available, |
| 361 | + "disk_charge_type": diskConfig.DiskChargeType, |
| 362 | + "zone": diskConfig.Zone, |
| 363 | + "instance_family": diskConfig.InstanceFamily, |
| 364 | + "disk_type": diskConfig.DiskType, |
| 365 | + "step_size": diskConfig.StepSize, |
| 366 | + "extra_performance_range": diskConfig.ExtraPerformanceRange, |
| 367 | + "device_class": diskConfig.DeviceClass, |
| 368 | + "disk_usage": diskConfig.DiskUsage, |
| 369 | + "min_disk_size": diskConfig.MinDiskSize, |
| 370 | + "max_disk_size": diskConfig.MaxDiskSize, |
| 371 | + }) |
| 372 | + } |
| 373 | + typeList[idx]["cbs_configs"] = cbsConfigList |
| 374 | + } |
| 375 | + } |
| 376 | + |
210 | 377 | d.SetId(helper.DataResourceIdsHash(ids))
|
211 | 378 | err = d.Set("instance_types", typeList)
|
212 | 379 | if err != nil {
|
|
0 commit comments