From ff50b9117e69c88078849e64c82c18a2adb0aaae Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Fri, 20 Jun 2025 11:07:03 +0800 Subject: [PATCH 1/2] add --- tencentcloud/provider.go | 2 + tencentcloud/provider.md | 1 + .../services/teo/data_source_tc_teo_plans.go | 357 ++++++++++++++++++ .../services/teo/data_source_tc_teo_plans.md | 55 +++ .../teo/data_source_tc_teo_plans_test.go | 31 ++ .../services/teo/resource_tc_teo_plan.go | 321 ++++++++++++++++ .../services/teo/service_tencentcloud_teo.go | 114 ++++++ website/docs/d/teo_plans.html.markdown | 110 ++++++ website/tencentcloud.erb | 3 + 9 files changed, 994 insertions(+) create mode 100644 tencentcloud/services/teo/data_source_tc_teo_plans.go create mode 100644 tencentcloud/services/teo/data_source_tc_teo_plans.md create mode 100644 tencentcloud/services/teo/data_source_tc_teo_plans_test.go create mode 100644 tencentcloud/services/teo/resource_tc_teo_plan.go create mode 100644 website/docs/d/teo_plans.html.markdown diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index b5fe7f64c9..88efecc57a 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -903,6 +903,7 @@ func Provider() *schema.Provider { "tencentcloud_teo_zone_available_plans": teo.DataSourceTencentCloudTeoZoneAvailablePlans(), "tencentcloud_teo_rule_engine_settings": teo.DataSourceTencentCloudTeoRuleEngineSettings(), "tencentcloud_teo_zones": teo.DataSourceTencentCloudTeoZones(), + "tencentcloud_teo_plans": teo.DataSourceTencentCloudTeoPlans(), "tencentcloud_sts_caller_identity": sts.DataSourceTencentCloudStsCallerIdentity(), "tencentcloud_dcdb_instances": dcdb.DataSourceTencentCloudDcdbInstances(), "tencentcloud_dcdb_accounts": dcdb.DataSourceTencentCloudDcdbAccounts(), @@ -1874,6 +1875,7 @@ func Provider() *schema.Provider { "tencentcloud_teo_security_policy_config": teo.ResourceTencentCloudTeoSecurityPolicyConfig(), "tencentcloud_teo_dns_record": teo.ResourceTencentCloudTeoDnsRecord(), "tencentcloud_teo_bind_security_template": teo.ResourceTencentCloudTeoBindSecurityTemplate(), + "tencentcloud_teo_plan": teo.ResourceTencentCloudTeoPlan(), "tencentcloud_tcm_mesh": tcm.ResourceTencentCloudTcmMesh(), "tencentcloud_tcm_cluster_attachment": tcm.ResourceTencentCloudTcmClusterAttachment(), "tencentcloud_tcm_prometheus_attachment": tcm.ResourceTencentCloudTcmPrometheusAttachment(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 8d82b27795..2d9e5797c1 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -1488,6 +1488,7 @@ Data Source tencentcloud_teo_zone_available_plans tencentcloud_teo_rule_engine_settings tencentcloud_teo_zones +tencentcloud_teo_plans Resource tencentcloud_teo_zone diff --git a/tencentcloud/services/teo/data_source_tc_teo_plans.go b/tencentcloud/services/teo/data_source_tc_teo_plans.go new file mode 100644 index 0000000000..ff490e9acf --- /dev/null +++ b/tencentcloud/services/teo/data_source_tc_teo_plans.go @@ -0,0 +1,357 @@ +package teo + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + teo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901" + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudTeoPlans() *schema.Resource { + return &schema.Resource{ + Read: DataSourceTencentCloudTeoPlansRead, + Schema: map[string]*schema.Schema{ + "filters": { + Optional: true, + Type: schema.TypeList, + Description: "Filter conditions, the upper limit of Filters. Values is 20. The detailed filtering conditions are as follows:
  • plan-type
    Filter according to [Package Type].
    Optional types are:
    plan-trial: Trial Package;
    plan-personal: Personal Package;
    plan-basic: Basic Package;
    plan-standard: Standard Package;
    plan-enterprise: Enterprise Package.
  • plan-id
    Filter according to [Package ID]. The package ID is in the form of: edgeone-268z103ob0sx.
  • area
    Filter according to [Package Acceleration Region].
  • Service area, optional types are:
    mainland: Mainland China;
    overseas: Global (excluding Mainland China);
    global: Global (including Mainland China).
  • status
    Filter by [Package Status].
    The available statuses are:
    normal: normal status;
    expiring-soon: about to expire;
    expired: expired;
    isolated: isolated.
  • .", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + Description: "Filter name.", + }, + "values": { + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + Required: true, + Description: "Filter value.", + }, + }, + }, + }, + + "order": { + Optional: true, + Type: schema.TypeString, + Description: "Sorting field, the values are:
  • enable-time: effective time;
  • expire-time: expiration time.
  • If not filled in, the default value enable-time will be used.", + }, + + "direction": { + Optional: true, + Type: schema.TypeString, + Description: "Sorting direction, the possible values are:
  • asc: sort from small to large;
  • desc: sort from large to small.
  • If not filled in, the default value desc will be used.", + }, + + // computed + "plans": { + Computed: true, + Type: schema.TypeList, + Description: "Plan list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "plan_type": { + Type: schema.TypeString, + Computed: true, + Description: "Plan type. Possible values are:
  • plan-trial: Trial plan;
  • plan-personal: Personal plan;
  • plan-basic: Basic plan;
  • plan-standard: Standard plan;
  • plan-enterprise-v2: Enterprise plan;
  • plan-enterprise-model-a: Enterprise Model A plan.
  • plan-enterprise: Old Enterprise plan.
  • .", + }, + "plan_id": { + Type: schema.TypeString, + Computed: true, + Description: "Plan ID.", + }, + "area": { + Type: schema.TypeString, + Computed: true, + Description: "Service area, the values are:
  • mainland: Mainland China;
  • overseas: Worldwide (excluding Mainland China);
  • global: Worldwide (including Mainland China).
  • .", + }, + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Package status, the values are:
  • normal: normal status;
  • expiring-soon: about to expire;
  • expired: expired;
  • isolated: isolated;
  • overdue-isolated: overdue isolated.
  • .", + }, + "pay_mode": { + Type: schema.TypeInt, + Computed: true, + Description: "Payment type, possible values:
  • 0: post-payment;
  • 1: pre-payment.
  • .", + }, + "zones_info": { + Type: schema.TypeList, + Computed: true, + Description: "Site information bound to the package, including site ID, site name, and site status.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "zone_id": { + Type: schema.TypeString, + Computed: true, + Description: "Zone ID.", + }, + "zone_name": { + Type: schema.TypeString, + Computed: true, + Description: "Zone name.", + }, + "paused": { + Type: schema.TypeBool, + Computed: true, + Description: "Whether the site is disabled. The possible values are:
  • false: not disabled;
  • true: disabled.
  • .", + }, + }, + }, + }, + "smart_request_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of intelligent acceleration requests in the package, unit: times.", + }, + "vau_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "VAU specifications in the package, unit: piece.", + }, + "acc_traffic_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "The content acceleration traffic specifications in the package, unit: byte.", + }, + "smart_traffic_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "Smart acceleration traffic specifications within the package, unit: byte.", + }, + "ddos_traffic_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "DDoS protection traffic specifications within the package, unit: bytes.", + }, + "sec_traffic_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "The security flow specification within the package, unit: byte.", + }, + "sec_request_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "The number of secure requests in the package, unit: times.", + }, + "l4_traffic_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "Layer 4 acceleration traffic specifications within the package, unit: byte.", + }, + "cross_mlc_traffic_capacity": { + Type: schema.TypeInt, + Computed: true, + Description: "The optimized traffic specifications of the Chinese mainland network in the package, unit: bytes.", + }, + "bindable": { + Type: schema.TypeString, + Computed: true, + Description: "Whether the package allows binding of new sites, the values are:
  • true: allows binding of new sites;
  • false: does not allow binding of new sites.
  • .", + }, + "enabled_time": { + Type: schema.TypeString, + Computed: true, + Description: "The package effective time.", + }, + "expired_time": { + Type: schema.TypeString, + Computed: true, + Description: "The expiration date of the package.", + }, + "features": { + Type: schema.TypeSet, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Computed: true, + Description: "The functions supported by the package have the following values:
  • ContentAcceleration: content acceleration function;
  • SmartAcceleration: smart acceleration function;
  • L4: four-layer acceleration function;
  • Waf: advanced web protection;
  • QUIC: QUIC function;
  • CrossMLC: Chinese mainland network optimization function;
  • ProcessMedia: media processing function;
  • L4DDoS: four-layer DDoS protection function;
  • L7DDoS function will only have one of the following specifications
  • L7DDoS.CM30G; seven-layer DDoS protection function - Chinese mainland 30G minimum bandwidth specification;
  • L7DDoS.CM60G; seven-layer DDoS protection function - Chinese mainland 60G minimum bandwidth specification;
  • L7DDoS.CM100G; Layer 7 DDoS protection function - 100G guaranteed bandwidth for mainland China;
  • L7DDoS.Anycast300G; Layer 7 DDoS protection function - 300G guaranteed bandwidth for Anycast outside mainland China;
  • L7DDoS.AnycastUnlimited; Layer 7 DDoS protection function - unlimited full protection for Anycast outside mainland China;
  • L7DDoS.CM30G_Anycast300G; Layer 7 DDoS protection function - 30G guaranteed bandwidth for mainland China
  • L7DDoS.CM60G_Anycast300G; Layer 7 DDoS protection function - 60G guaranteed bandwidth in mainland China, 300G guaranteed bandwidth in anycast outside mainland China;
  • L7DDoS.CM100G_Anycast300G; Layer 7 DDoS protection function - 100G guaranteed bandwidth in mainland China, 300G guaranteed bandwidth in anycast outside mainland China;
  • L7DDoS.CM30G_AnycastUnlimited d; Layer 7 DDoS protection function - 30G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China;
  • L7DDoS.CM60G_AnycastUnlimited; Layer 7 DDoS protection function - 60G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China;
  • L7DDoS.CM100G_AnycastUnlimited; Layer 7 DDoS protection function - 100G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China;
  • .", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func DataSourceTencentCloudTeoPlansRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_teo_plans.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(nil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = TeoService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + ) + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("filters"); ok { + filtersSet := v.([]interface{}) + tmpSet := make([]*teo.Filter, 0, len(filtersSet)) + for _, item := range filtersSet { + filter := teo.Filter{} + filterMap := item.(map[string]interface{}) + if v, ok := filterMap["name"].(string); ok && v != "" { + filter.Name = helper.String(v) + } + + if v, ok := filterMap["values"]; ok { + valuesSet := v.(*schema.Set).List() + filter.Values = helper.InterfacesStringsPoint(valuesSet) + } + + tmpSet = append(tmpSet, &filter) + } + + paramMap["filters"] = tmpSet + } + + if v, ok := d.GetOk("order"); ok { + paramMap["Order"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("direction"); ok { + paramMap["Direction"] = helper.String(v.(string)) + } + + var plans []*teo.Plan + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeTeoPlansByFilters(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + + plans = result + return nil + }) + + if err != nil { + return err + } + + ids := make([]string, 0, len(plans)) + tmpList := make([]map[string]interface{}, 0, len(plans)) + if plans != nil { + for _, plan := range plans { + planMap := map[string]interface{}{} + if plan.PlanType != nil { + planMap["plan_type"] = plan.PlanType + } + + if plan.PlanId != nil { + planMap["plan_id"] = plan.PlanId + ids = append(ids, *plan.PlanId) + } + + if plan.Area != nil { + planMap["area"] = plan.Area + } + + if plan.Status != nil { + planMap["status"] = plan.Status + } + + if plan.PayMode != nil { + planMap["pay_mode"] = plan.PayMode + } + + if plan.ZonesInfo != nil { + zonesInfoList := []interface{}{} + for _, zonesInfo := range plan.ZonesInfo { + zonesInfoMap := map[string]interface{}{} + if zonesInfo.ZoneId != nil { + zonesInfoMap["zone_id"] = zonesInfo.ZoneId + } + + if zonesInfo.ZoneName != nil { + zonesInfoMap["zone_name"] = zonesInfo.ZoneName + } + + if zonesInfo.Paused != nil { + zonesInfoMap["paused"] = zonesInfo.Paused + } + + zonesInfoList = append(zonesInfoList, zonesInfoMap) + } + + planMap["zones_info"] = zonesInfoList + } + + if plan.SmartRequestCapacity != nil { + planMap["smart_request_capacity"] = plan.SmartRequestCapacity + } + + if plan.VAUCapacity != nil { + planMap["vau_capacity"] = plan.VAUCapacity + } + + if plan.AccTrafficCapacity != nil { + planMap["acc_traffic_capacity"] = plan.AccTrafficCapacity + } + + if plan.SmartTrafficCapacity != nil { + planMap["smart_traffic_capacity"] = plan.SmartTrafficCapacity + } + + if plan.DDoSTrafficCapacity != nil { + planMap["ddos_traffic_capacity"] = plan.DDoSTrafficCapacity + } + + if plan.SecTrafficCapacity != nil { + planMap["sec_traffic_capacity"] = plan.SecTrafficCapacity + } + + if plan.SecRequestCapacity != nil { + planMap["sec_request_capacity"] = plan.SecRequestCapacity + } + + if plan.L4TrafficCapacity != nil { + planMap["l4_traffic_capacity"] = plan.L4TrafficCapacity + } + + if plan.CrossMLCTrafficCapacity != nil { + planMap["cross_mlc_traffic_capacity"] = plan.CrossMLCTrafficCapacity + } + + if plan.Bindable != nil { + planMap["bindable"] = plan.Bindable + } + + if plan.EnabledTime != nil { + planMap["enabled_time"] = plan.EnabledTime + } + + if plan.ExpiredTime != nil { + planMap["expired_time"] = plan.ExpiredTime + } + + if plan.Features != nil { + planMap["features"] = plan.Features + } + + tmpList = append(tmpList, planMap) + } + + _ = d.Set("plans", tmpList) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), tmpList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/teo/data_source_tc_teo_plans.md b/tencentcloud/services/teo/data_source_tc_teo_plans.md new file mode 100644 index 0000000000..c0119c1c18 --- /dev/null +++ b/tencentcloud/services/teo/data_source_tc_teo_plans.md @@ -0,0 +1,55 @@ +Use this data source to query detailed information of TEO plans + +Example Usage + +Query all plans + +```hcl +data "tencentcloud_teo_plans" "example" {} +``` + +Query plans by filters + +```hcl +data "tencentcloud_teo_plans" "example" { + order = "expire-time" + direction = "desc" + filters { + name = "plan-id" + values = [ + "edgeone-2o1xvpmq7nn", + "edgeone-2mezmk9s2xdx" + ] + } + + filters { + name = "plan-type" + values = [ + "plan-trial", + "plan-personal", + "plan-basic", + "plan-standard", + "plan-enterprise" + ] + } + + filters { + name = "area" + values = [ + "overseas", + "mainland", + "global" + ] + } + + filters { + name = "status" + values = [ + "normal", + "expiring-soon", + "expired", + "isolated" + ] + } +} +``` diff --git a/tencentcloud/services/teo/data_source_tc_teo_plans_test.go b/tencentcloud/services/teo/data_source_tc_teo_plans_test.go new file mode 100644 index 0000000000..27cd2597e2 --- /dev/null +++ b/tencentcloud/services/teo/data_source_tc_teo_plans_test.go @@ -0,0 +1,31 @@ +package teo_test + +import ( + "testing" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +// go test -i; go test -test.run TestAccTencentCloudTeoPlansDataSource -v +func TestAccTencentCloudTeoPlansDataSource(t *testing.T) { + t.Parallel() + + resource.Test(t, resource.TestCase{ + PreCheck: func() { tcacctest.AccPreCheck(t) }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceTeoPlans, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_teo_plans.example"), + ), + }, + }, + }) +} + +const testAccDataSourceTeoPlans = ` +data "tencentcloud_teo_plans" "example" {} +` diff --git a/tencentcloud/services/teo/resource_tc_teo_plan.go b/tencentcloud/services/teo/resource_tc_teo_plan.go new file mode 100644 index 0000000000..ce7d594928 --- /dev/null +++ b/tencentcloud/services/teo/resource_tc_teo_plan.go @@ -0,0 +1,321 @@ +package teo + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + teov20220901 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudTeoPlan() *schema.Resource { + return &schema.Resource{ + Create: ResourceTencentCloudTeoPlanCreate, + Read: ResourceTencentCloudTeoPlanRead, + Update: ResourceTencentCloudTeoPlanUpdate, + Delete: ResourceTencentCloudTeoPlanDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "plan_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"personal", "basic", "standard", "enterprise"}), + Description: "The subscription package type, the possible values are: `personal`: personal package, prepaid package; `basic`: basic package, prepaid package; `standard`: standard package, prepaid package; `enterprise`: enterprise package, postpaid package.", + }, + + "prepaid_plan_param": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Description: "Subscription prepaid package parameters. When PlanType is personal, basic, or standard, this parameter is optional and is used to enter the subscription duration of the package and whether to enable automatic renewal. If this parameter is not filled in, the default subscription duration is 1 month and automatic renewal is not enabled.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "period": { + Type: schema.TypeInt, + Optional: true, + ValidateFunc: tccommon.ValidateAllowedIntValue([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36}), + Description: "The subscription period of the prepaid package, in months, with possible values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. If not filled in, the default value 1 is used.", + }, + "renew_flag": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: tccommon.ValidateAllowedStringValue([]string{"on", "off"}), + Description: "The automatic renewal flag of the prepaid package, the values are: `on`: turn on automatic renewal; `off`: do not turn on automatic renewal. If not filled in, the default value off is used. When automatic renewal occurs, the default renewal period is 1 month.", + }, + }, + }, + }, + + // computed + "plan_id": { + Type: schema.TypeString, + Computed: true, + Description: "Plan ID.", + }, + + "area": { + Type: schema.TypeString, + Computed: true, + Description: "Service area, possible values are:
  • mainland: Mainland China;
  • overseas: Worldwide (excluding Mainland China);
  • global: Worldwide (including Mainland China).
  • .", + }, + + "status": { + Type: schema.TypeString, + Computed: true, + Description: "Package status, the values are:
  • normal: normal status;
  • expiring-soon: about to expire;
  • expired: expired;
  • isolated: isolated;
  • overdue-isolated: overdue isolated.
  • .", + }, + + "pay_mode": { + Type: schema.TypeString, + Computed: true, + Description: "Payment type, possible values:
  • 0: post-payment;
  • 1: pre-payment.
  • .", + }, + + "enabled_time": { + Type: schema.TypeString, + Computed: true, + Description: "The time when the package takes effect.", + }, + + "expired_time": { + Type: schema.TypeString, + Computed: true, + Description: "The expiration date of the package.", + }, + }, + } +} + +func ResourceTencentCloudTeoPlanCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_teo_plan.create")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = teov20220901.NewCreatePlanRequest() + response = teov20220901.NewCreatePlanResponse() + planId string + ) + + if v, ok := d.GetOk("plan_type"); ok { + request.PlanType = helper.String(v.(string)) + } + + if dMap, ok := helper.InterfacesHeadMap(d, "prepaid_plan_param"); ok { + prepaidPlanParam := teov20220901.PrepaidPlanParam{} + if v, ok := dMap["period"].(int); ok && v != 0 { + prepaidPlanParam.Period = helper.IntInt64(v) + } + + if v, ok := dMap["renew_flag"].(string); ok && v != "" { + prepaidPlanParam.RenewFlag = helper.String(v) + } + + request.PrepaidPlanParam = &prepaidPlanParam + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoV20220901Client().CreatePlanWithContext(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()) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Create teo plan failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s create teo function failed, reason:%+v", logId, err) + return err + } + + if response.Response.PlanId == nil { + return fmt.Errorf("PlanId is nil.") + } + + planId = *response.Response.PlanId + d.SetId(planId) + return ResourceTencentCloudTeoPlanRead(d, meta) +} + +func ResourceTencentCloudTeoPlanRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_teo_plan.read")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + service = TeoService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + planId = d.Id() + ) + + respData, err := service.DescribeTeoPlansById(ctx, planId) + if err != nil { + return err + } + + if respData == nil { + log.Printf("[WARN]%s resource `tencentcloud_teo_plan` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + d.SetId("") + return nil + } + + if respData.PlanType != nil { + _ = d.Set("plan_type", respData.PlanType) + } + + if respData.PlanId != nil { + _ = d.Set("plan_id", respData.PlanId) + } + + if respData.Area != nil { + _ = d.Set("area", respData.Area) + } + + if respData.Status != nil { + _ = d.Set("status", respData.Status) + } + + if respData.PayMode != nil { + _ = d.Set("pay_mode", respData.PayMode) + } + + if respData.EnabledTime != nil { + _ = d.Set("enabled_time", respData.EnabledTime) + } + + if respData.ExpiredTime != nil { + _ = d.Set("expired_time", respData.ExpiredTime) + } + + return nil +} + +func ResourceTencentCloudTeoPlanUpdate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_teo_plan.update")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + planId = d.Id() + ) + + if d.HasChange("plan_type") { + request := teov20220901.NewUpgradePlanRequest() + if v, ok := d.GetOk("plan_type"); ok { + request.PlanType = helper.String(v.(string)) + } + + request.PlanId = &planId + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoV20220901Client().UpgradePlanWithContext(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()) + } + + return nil + }) + + if err != nil { + return err + } + } + + if d.HasChange("prepaid_plan_param.0.period") { + request := teov20220901.NewRenewPlanRequest() + if v, ok := d.GetOk("period"); ok { + request.Period = helper.IntInt64(v.(int)) + } + + request.PlanId = &planId + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoV20220901Client().RenewPlanWithContext(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()) + } + + return nil + }) + + if err != nil { + return err + } + } + + if d.HasChange("prepaid_plan_param.0.renew_flag") { + request := teov20220901.NewModifyPlanRequest() + if v, ok := d.GetOk("renew_flag"); ok { + request.RenewFlag = &teov20220901.RenewFlag{ + Switch: helper.String(v.(string)), + } + } + + request.PlanId = &planId + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoV20220901Client().ModifyPlanWithContext(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()) + } + + return nil + }) + + if err != nil { + return err + } + } + + return ResourceTencentCloudTeoPlanRead(d, meta) +} + +func ResourceTencentCloudTeoPlanDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_teo_plan.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + var ( + logId = tccommon.GetLogId(tccommon.ContextNil) + ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + request = teov20220901.NewDestroyPlanRequest() + planId = d.Id() + ) + + request.PlanId = &planId + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseTeoV20220901Client().DestroyPlanWithContext(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()) + } + + return nil + }) + + if err != nil { + log.Printf("[CRITAL]%s delete teo plan failed, reason:%+v", logId, err) + return err + } + + return nil +} diff --git a/tencentcloud/services/teo/service_tencentcloud_teo.go b/tencentcloud/services/teo/service_tencentcloud_teo.go index 97cb16d968..988746c884 100644 --- a/tencentcloud/services/teo/service_tencentcloud_teo.go +++ b/tencentcloud/services/teo/service_tencentcloud_teo.go @@ -1836,10 +1836,12 @@ func (me *TeoService) DescribeTeoBindSecurityTemplateById(ctx context.Context, z ratelimit.Check(request.GetAction()) response, err := me.client.UseTeoV20220901Client().DescribeSecurityTemplateBindings(request) + if err != nil { errRet = err return } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) if response != nil && response.Response != nil { if response.Response.SecurityTemplate != nil && len(response.Response.SecurityTemplate) > 0 { @@ -1857,3 +1859,115 @@ func (me *TeoService) DescribeTeoBindSecurityTemplateById(ctx context.Context, z } return } + +func (me *TeoService) DescribeTeoPlansById(ctx context.Context, planId string) (ret *teo.Plan, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := teo.NewDescribePlansRequest() + response := teo.NewDescribePlansResponse() + request.Filters = []*teo.Filter{ + { + Name: helper.String("plan-id"), + Values: helper.Strings([]string{planId}), + }, + } + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseTeoV20220901Client().DescribePlans(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()) + } + + if result == nil || result.Response == nil || result.Response.Plans == nil { + return resource.NonRetryableError(fmt.Errorf("Describe plans failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + if len(response.Response.Plans) > 0 { + ret = response.Response.Plans[0] + } + + return +} + +func (me *TeoService) DescribeTeoPlansByFilters(ctx context.Context, paramMap map[string]interface{}) (ret []*teo.Plan, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := teo.NewDescribePlansRequest() + response := teo.NewDescribePlansResponse() + + for k, v := range paramMap { + if k == "Filters" { + request.Filters = v.([]*teov20220901.Filter) + } + + if k == "Order" { + request.Order = v.(*string) + } + + if k == "Direction" { + request.Direction = v.(*string) + } + } + + var ( + offset int64 = 0 + limit int64 = 200 + ) + + for { + request.Offset = &offset + request.Limit = &limit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + ratelimit.Check(request.GetAction()) + result, e := me.client.UseTeoClient().DescribePlans(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()) + } + + if result == nil || result.Response == nil { + return resource.NonRetryableError(fmt.Errorf("Describe plans failed, Response is nil.")) + } + + response = result + return nil + }) + + if err != nil { + errRet = err + return + } + + if len(response.Response.Plans) < 1 { + break + } + + ret = append(ret, response.Response.Plans...) + if len(response.Response.Plans) < int(limit) { + break + } + + offset += limit + } + + return +} diff --git a/website/docs/d/teo_plans.html.markdown b/website/docs/d/teo_plans.html.markdown new file mode 100644 index 0000000000..d25aaf1d8e --- /dev/null +++ b/website/docs/d/teo_plans.html.markdown @@ -0,0 +1,110 @@ +--- +subcategory: "TencentCloud EdgeOne(TEO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_teo_plans" +sidebar_current: "docs-tencentcloud-datasource-teo_plans" +description: |- + Use this data source to query detailed information of TEO plans +--- + +# tencentcloud_teo_plans + +Use this data source to query detailed information of TEO plans + +## Example Usage + +### Query all plans + +```hcl +data "tencentcloud_teo_plans" "example" {} +``` + +### Query plans by filters + +```hcl +data "tencentcloud_teo_plans" "example" { + order = "expire-time" + direction = "desc" + filters { + name = "plan-id" + values = [ + "edgeone-2o1xvpmq7nn", + "edgeone-2mezmk9s2xdx" + ] + } + + filters { + name = "plan-type" + values = [ + "plan-trial", + "plan-personal", + "plan-basic", + "plan-standard", + "plan-enterprise" + ] + } + + filters { + name = "area" + values = [ + "overseas", + "mainland", + "global" + ] + } + + filters { + name = "status" + values = [ + "normal", + "expiring-soon", + "expired", + "isolated" + ] + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `direction` - (Optional, String) Sorting direction, the possible values are:
  • asc: sort from small to large;
  • desc: sort from large to small.
  • If not filled in, the default value desc will be used. +* `filters` - (Optional, List) Filter conditions, the upper limit of Filters. Values is 20. The detailed filtering conditions are as follows:
  • plan-type
    Filter according to [Package Type].
    Optional types are:
    plan-trial: Trial Package;
    plan-personal: Personal Package;
    plan-basic: Basic Package;
    plan-standard: Standard Package;
    plan-enterprise: Enterprise Package.
  • plan-id
    Filter according to [Package ID]. The package ID is in the form of: edgeone-268z103ob0sx.
  • area
    Filter according to [Package Acceleration Region].
  • Service area, optional types are:
    mainland: Mainland China;
    overseas: Global (excluding Mainland China);
    global: Global (including Mainland China).
  • status
    Filter by [Package Status].
    The available statuses are:
    normal: normal status;
    expiring-soon: about to expire;
    expired: expired;
    isolated: isolated.
  • . +* `order` - (Optional, String) Sorting field, the values are:
  • enable-time: effective time;
  • expire-time: expiration time.
  • If not filled in, the default value enable-time will be used. +* `result_output_file` - (Optional, String) Used to save results. + +The `filters` object supports the following: + +* `name` - (Required, String) Filter name. +* `values` - (Required, Set) Filter value. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `plans` - Plan list. + * `acc_traffic_capacity` - The content acceleration traffic specifications in the package, unit: byte. + * `area` - Service area, the values are:
  • mainland: Mainland China;
  • overseas: Worldwide (excluding Mainland China);
  • global: Worldwide (including Mainland China).
  • . + * `bindable` - Whether the package allows binding of new sites, the values are:
  • true: allows binding of new sites;
  • false: does not allow binding of new sites.
  • . + * `cross_mlc_traffic_capacity` - The optimized traffic specifications of the Chinese mainland network in the package, unit: bytes. + * `ddos_traffic_capacity` - DDoS protection traffic specifications within the package, unit: bytes. + * `enabled_time` - The package effective time. + * `expired_time` - The expiration date of the package. + * `features` - The functions supported by the package have the following values:
  • ContentAcceleration: content acceleration function;
  • SmartAcceleration: smart acceleration function;
  • L4: four-layer acceleration function;
  • Waf: advanced web protection;
  • QUIC: QUIC function;
  • CrossMLC: Chinese mainland network optimization function;
  • ProcessMedia: media processing function;
  • L4DDoS: four-layer DDoS protection function;
  • L7DDoS function will only have one of the following specifications
  • L7DDoS.CM30G; seven-layer DDoS protection function - Chinese mainland 30G minimum bandwidth specification;
  • L7DDoS.CM60G; seven-layer DDoS protection function - Chinese mainland 60G minimum bandwidth specification;
  • L7DDoS.CM100G; Layer 7 DDoS protection function - 100G guaranteed bandwidth for mainland China;
  • L7DDoS.Anycast300G; Layer 7 DDoS protection function - 300G guaranteed bandwidth for Anycast outside mainland China;
  • L7DDoS.AnycastUnlimited; Layer 7 DDoS protection function - unlimited full protection for Anycast outside mainland China;
  • L7DDoS.CM30G_Anycast300G; Layer 7 DDoS protection function - 30G guaranteed bandwidth for mainland China
  • L7DDoS.CM60G_Anycast300G; Layer 7 DDoS protection function - 60G guaranteed bandwidth in mainland China, 300G guaranteed bandwidth in anycast outside mainland China;
  • L7DDoS.CM100G_Anycast300G; Layer 7 DDoS protection function - 100G guaranteed bandwidth in mainland China, 300G guaranteed bandwidth in anycast outside mainland China;
  • L7DDoS.CM30G_AnycastUnlimited d; Layer 7 DDoS protection function - 30G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China;
  • L7DDoS.CM60G_AnycastUnlimited; Layer 7 DDoS protection function - 60G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China;
  • L7DDoS.CM100G_AnycastUnlimited; Layer 7 DDoS protection function - 100G guaranteed bandwidth in mainland China, unlimited Anycast protection outside mainland China;
  • . + * `l4_traffic_capacity` - Layer 4 acceleration traffic specifications within the package, unit: byte. + * `pay_mode` - Payment type, possible values:
  • 0: post-payment;
  • 1: pre-payment.
  • . + * `plan_id` - Plan ID. + * `plan_type` - Plan type. Possible values are:
  • plan-trial: Trial plan;
  • plan-personal: Personal plan;
  • plan-basic: Basic plan;
  • plan-standard: Standard plan;
  • plan-enterprise-v2: Enterprise plan;
  • plan-enterprise-model-a: Enterprise Model A plan.
  • plan-enterprise: Old Enterprise plan.
  • . + * `sec_request_capacity` - The number of secure requests in the package, unit: times. + * `sec_traffic_capacity` - The security flow specification within the package, unit: byte. + * `smart_request_capacity` - The number of intelligent acceleration requests in the package, unit: times. + * `smart_traffic_capacity` - Smart acceleration traffic specifications within the package, unit: byte. + * `status` - Package status, the values are:
  • normal: normal status;
  • expiring-soon: about to expire;
  • expired: expired;
  • isolated: isolated;
  • overdue-isolated: overdue isolated.
  • . + * `vau_capacity` - VAU specifications in the package, unit: piece. + * `zones_info` - Site information bound to the package, including site ID, site name, and site status. + * `paused` - Whether the site is disabled. The possible values are:
  • false: not disabled;
  • true: disabled.
  • . + * `zone_id` - Zone ID. + * `zone_name` - Zone name. + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index f1936a45ac..2782c210b4 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -5310,6 +5310,9 @@
  • Data Sources