Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/3537.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-data-source
tencentcloud_billing_budget_operation_log
```

```release-note:new-resource
tencentcloud_billing_budget
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ require (

require (
github.com/hashicorp/go-uuid v1.0.3
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.0
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.31
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdc v1.0.1149
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwdoris v1.0.993
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwpg v1.0.1126
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824 h1:DVKvZ6h+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824/go.mod h1:DvBpDX/qdJG4KKLeULmRvhAjPYiw8za0HeTSu2y/lFw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.0 h1:tfTh+fIqYPgWV2wi4oDvG963pi8tljtZ+5OdnhEqRnU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.0/go.mod h1:OKowLuHQjXN5pk3KnYnbmZLQucfBUUEpqWsa/3Cl+jY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.31 h1:teA14cAcXuGxas6+5YANQ5KCoPaQBKIb2Q8+sk08Mu0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.31/go.mod h1:1P9mCHgZ9pk/xftRsGC05XanvIk/sC5kLIy5jfD6DqU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.1071 h1:2CeivXYc7PtD2kgZEJXk9/SDQA9dzLejH5FmNzAW3QU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.1071/go.mod h1:UAjX3Vq52SQLKTe6o2HyGA/841Rnc+f4ZRATEsFHJDM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.1.27 h1:Jo/5JV8oiPbXKXQg2xv3ZeKxLst/xXl3nWUgXalq9eg=
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ func Provider() *schema.Provider {
"tencentcloud_mqtt_instances": mqtt.DataSourceTencentCloudMqttInstances(),
"tencentcloud_mqtt_instance_detail": mqtt.DataSourceTencentCloudMqttInstanceDetail(),
"tencentcloud_mqtt_topics": mqtt.DataSourceTencentCloudMqttTopics(),
"tencentcloud_billing_budget_operation_log": billing.DataSourceTencentCloudBillingBudgetOperationLog(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -2376,6 +2377,7 @@ func Provider() *schema.Provider {
"tencentcloud_mqtt_jwks_authenticator": mqtt.ResourceTencentCloudMqttJwksAuthenticator(),
"tencentcloud_mqtt_http_authenticator": mqtt.ResourceTencentCloudMqttHttpAuthenticator(),
"tencentcloud_billing_allocation_tag": billing.ResourceTencentCloudBillingAllocationTag(),
"tencentcloud_billing_budget": billing.ResourceTencentCloudBillingBudget(),
},

ConfigureFunc: providerConfigure,
Expand Down
5 changes: 4 additions & 1 deletion tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2349,5 +2349,8 @@ tencentcloud_mqtt_jwks_authenticator
tencentcloud_mqtt_http_authenticator

Billing
Data Source
tencentcloud_billing_budget_operation_log
Resource
tencentcloud_billing_allocation_tag
tencentcloud_billing_allocation_tag
tencentcloud_billing_budget
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package billing

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
billingv20180709 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func DataSourceTencentCloudBillingBudgetOperationLog() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudBillingBudgetOperationLogRead,
Schema: map[string]*schema.Schema{
"budget_id": {
Type: schema.TypeString,
Required: true,
Description: "Budget id.",
},

"records": {
Type: schema.TypeList,
Computed: true,
Description: "Query data list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"payer_uin": {
Type: schema.TypeInt,
Computed: true,
Description: "Payer uin.",
},
"owner_uin": {
Type: schema.TypeInt,
Computed: true,
Description: "Owner uin.",
},
"operate_uin": {
Type: schema.TypeInt,
Computed: true,
Description: "Operate uin.",
},
"bill_day": {
Type: schema.TypeInt,
Computed: true,
Description: "Bill day.",
},
"bill_month": {
Type: schema.TypeString,
Computed: true,
Description: "Bill month.",
},
"action": {
Type: schema.TypeString,
Computed: true,
Description: "Modification type: ADD, UPDATE.",
},
"diff_value": {
Type: schema.TypeList,
Computed: true,
Description: "change information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"property": {
Type: schema.TypeString,
Computed: true,
Description: "Change attributes.",
},
"before": {
Type: schema.TypeString,
Computed: true,
Description: "Content before change.",
},
"after": {
Type: schema.TypeString,
Computed: true,
Description: "Content after change.",
},
},
},
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: "Create time.",
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: "Update time.",
},
"operation_channel": {
Type: schema.TypeString,
Computed: true,
Description: "Operation channel.",
},
"budget_id": {
Type: schema.TypeString,
Computed: true,
Description: "Budget item id.",
},
},
},
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudBillingBudgetOperationLogRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_billing_budget_operation_log.read")()
defer tccommon.InconsistentCheck(d, meta)()

logId := tccommon.GetLogId(nil)
ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)

service := BillingService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}

var budgetId string

paramMap := make(map[string]interface{})

if v, ok := d.GetOk("budget_id"); ok {
budgetId = v.(string)
paramMap["BudgetId"] = helper.String(budgetId)
}

var respData []*billingv20180709.BudgetOperationLogEntity
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeBillingBudgetOperationLogByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
respData = result
return nil
})
if err != nil {
return err
}

if len(respData) > 0 {
recordsList := make([]map[string]interface{}, 0, len(respData))

for _, records := range respData {
recordsMap := map[string]interface{}{}

if records.PayerUin != nil {
recordsMap["payer_uin"] = records.PayerUin
}

if records.OwnerUin != nil {
recordsMap["owner_uin"] = records.OwnerUin
}

if records.OperateUin != nil {
recordsMap["operate_uin"] = records.OperateUin
}

if records.BillDay != nil {
recordsMap["bill_day"] = records.BillDay
}

if records.BillMonth != nil {
recordsMap["bill_month"] = records.BillMonth
}

if records.Action != nil {
recordsMap["action"] = records.Action
}

diffValueList := make([]map[string]interface{}, 0, len(records.DiffValue))
if records.DiffValue != nil {
for _, diffValue := range records.DiffValue {
diffValueMap := map[string]interface{}{}

if diffValue.Property != nil {
diffValueMap["property"] = diffValue.Property
}

if diffValue.Before != nil {
diffValueMap["before"] = diffValue.Before
}

if diffValue.After != nil {
diffValueMap["after"] = diffValue.After
}

diffValueList = append(diffValueList, diffValueMap)
}

recordsMap["diff_value"] = diffValueList
}
if records.CreateTime != nil {
recordsMap["create_time"] = records.CreateTime
}

if records.UpdateTime != nil {
recordsMap["update_time"] = records.UpdateTime
}

if records.OperationChannel != nil {
recordsMap["operation_channel"] = records.OperationChannel
}

if records.BudgetId != nil {
recordsMap["budget_id"] = records.BudgetId
}

recordsList = append(recordsList, recordsMap)
}

_ = d.Set("records", recordsList)
}

d.SetId(budgetId)

output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), d); e != nil {
return e
}
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Use this data source to query detailed information of billing billing_budget_operation_log

Example Usage

```hcl
data "tencentcloud_billing_budget_operation_log" "billing_budget_operation_log" {
budget_id = "1971489821259956225"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package billing_test

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
)

func TestAccTencentCloudBillingBudgetOperationLogDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{{
Config: testAccBillingBudgetOperationLogDataSource,
Check: resource.ComposeTestCheckFunc(tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_billing_budget_operation_log.billing_budget_operation_log")),
}},
})
}

const testAccBillingBudgetOperationLogDataSource = `
data "tencentcloud_billing_budget_operation_log" "billing_budget_operation_log" {
budget_id = "1971489821259956225"
}
`
Loading
Loading