Skip to content

Commit 42aa04e

Browse files
authored
support resource: tencentcloud_tcr_webhook_trigger (#1695)
* support resource: tencentcloud_tcr_webhook_trigger * add changelog * adjust TCR e2e case name * adjust e2e case * support resource: tencentcloud_tcr_webhook_trigger_logs
1 parent d7729d3 commit 42aa04e

14 files changed

+1364
-1
lines changed

.changelog/1695.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:new-resource
2+
tencentcloud_tcr_webhook_trigger
3+
```
4+
5+
```release-note:new-data-source
6+
tencentcloud_tcr_describe_webhook_trigger_logs
7+
```

tencentcloud/data_source_tc_tcr_namespaces.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func dataSourceTencentCloudTCRNamespaces() *schema.Resource {
5858
Computed: true,
5959
Description: "Indicate that the namespace is public or not.",
6060
},
61+
"id": {
62+
Type: schema.TypeInt,
63+
Computed: true,
64+
Description: "ID of TCR namespace.",
65+
},
6166
},
6267
},
6368
},
@@ -99,6 +104,7 @@ func dataSourceTencentCloudTCRNamespacesRead(d *schema.ResourceData, meta interf
99104
mapping := map[string]interface{}{
100105
"name": namespace.Name,
101106
"is_public": namespace.Public,
107+
"id": namespace.NamespaceId,
102108
}
103109

104110
namespaceList = append(namespaceList, mapping)

tencentcloud/data_source_tc_tcr_namespaces_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func TestAccTencentCloudTCRNamespacesData(t *testing.T) {
2020
Check: resource.ComposeAggregateTestCheckFunc(
2121
resource.TestCheckResourceAttrSet(testDataTCRNamespacesNameAll, "namespace_list.0.name"),
2222
resource.TestCheckResourceAttrSet(testDataTCRNamespacesNameAll, "namespace_list.0.is_public"), // we only need to care whether the value is set or not, rather than the exact value itself, and this value of public cannot be confirmed when the e2e case parallel running
23+
resource.TestCheckResourceAttrSet(testDataTCRNamespacesNameAll, "namespace_list.0.id"),
2324
),
2425
},
2526
},
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
/*
2+
Use this data source to query detailed information of tencentcloud_tcr_webhook_trigger_logs
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_tcr_webhook_trigger_logs" "my_logs" {
8+
registry_id = local.tcr_id
9+
namespace = var.tcr_namespace
10+
trigger_id = var.trigger_id
11+
tags = {
12+
"createdBy" = "terraform"
13+
}
14+
}
15+
```
16+
*/
17+
package tencentcloud
18+
19+
import (
20+
"context"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
23+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
24+
tcr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr/v20190924"
25+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
26+
)
27+
28+
func dataSourceTencentCloudTcrWebhookTriggerLogs() *schema.Resource {
29+
return &schema.Resource{
30+
Read: dataSourceTencentCloudTcrWebhookTriggerLogsRead,
31+
Schema: map[string]*schema.Schema{
32+
"registry_id": {
33+
Required: true,
34+
Type: schema.TypeString,
35+
Description: "instance Id.",
36+
},
37+
38+
"namespace": {
39+
Required: true,
40+
Type: schema.TypeString,
41+
Description: "namespace.",
42+
},
43+
44+
"trigger_id": {
45+
Required: true,
46+
Type: schema.TypeInt,
47+
Description: "trigger id.",
48+
},
49+
50+
"logs": {
51+
Computed: true,
52+
Type: schema.TypeList,
53+
Description: "log list.",
54+
Elem: &schema.Resource{
55+
Schema: map[string]*schema.Schema{
56+
"id": {
57+
Type: schema.TypeInt,
58+
Computed: true,
59+
Description: "log id.",
60+
},
61+
"trigger_id": {
62+
Type: schema.TypeInt,
63+
Computed: true,
64+
Description: "trigger Id.",
65+
},
66+
"event_type": {
67+
Type: schema.TypeString,
68+
Computed: true,
69+
Description: "event type.",
70+
},
71+
"notify_type": {
72+
Type: schema.TypeString,
73+
Computed: true,
74+
Description: "notification type.",
75+
},
76+
"detail": {
77+
Type: schema.TypeString,
78+
Computed: true,
79+
Description: "webhook trigger detail.",
80+
},
81+
"creation_time": {
82+
Type: schema.TypeString,
83+
Computed: true,
84+
Description: "creation time.",
85+
},
86+
"update_time": {
87+
Type: schema.TypeString,
88+
Computed: true,
89+
Description: "update time.",
90+
},
91+
"status": {
92+
Type: schema.TypeString,
93+
Computed: true,
94+
Description: "status.",
95+
},
96+
},
97+
},
98+
},
99+
100+
"tags": {
101+
Type: schema.TypeMap,
102+
Optional: true,
103+
Description: "Tag description list.",
104+
},
105+
"result_output_file": {
106+
Type: schema.TypeString,
107+
Optional: true,
108+
Description: "Used to save results.",
109+
},
110+
},
111+
}
112+
}
113+
114+
func dataSourceTencentCloudTcrWebhookTriggerLogsRead(d *schema.ResourceData, meta interface{}) error {
115+
defer logElapsed("data_source.tencentcloud_tcr_webhook_trigger_logs.read")()
116+
defer inconsistentCheck(d, meta)()
117+
118+
logId := getLogId(contextNil)
119+
120+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
121+
122+
paramMap := make(map[string]interface{})
123+
if v, ok := d.GetOk("registry_id"); ok {
124+
paramMap["registry_id"] = helper.String(v.(string))
125+
}
126+
127+
if v, ok := d.GetOk("namespace"); ok {
128+
paramMap["namespace"] = helper.String(v.(string))
129+
}
130+
131+
if v, ok := d.GetOk("trigger_id"); ok {
132+
paramMap["trigger_id"] = helper.IntInt64(v.(int))
133+
}
134+
135+
service := TCRService{client: meta.(*TencentCloudClient).apiV3Conn}
136+
137+
var logs []*tcr.WebhookTriggerLog
138+
139+
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
140+
result, e := service.DescribeTcrWebhookTriggerLogByFilter(ctx, paramMap)
141+
if e != nil {
142+
return retryError(e)
143+
}
144+
logs = result
145+
return nil
146+
})
147+
if err != nil {
148+
return err
149+
}
150+
151+
ids := make([]string, 0, len(logs))
152+
tmpList := make([]map[string]interface{}, 0, len(logs))
153+
154+
if logs != nil {
155+
for _, webhookTriggerLog := range logs {
156+
webhookTriggerLogMap := map[string]interface{}{}
157+
158+
if webhookTriggerLog.Id != nil {
159+
webhookTriggerLogMap["id"] = webhookTriggerLog.Id
160+
}
161+
162+
if webhookTriggerLog.TriggerId != nil {
163+
webhookTriggerLogMap["trigger_id"] = webhookTriggerLog.TriggerId
164+
}
165+
166+
if webhookTriggerLog.EventType != nil {
167+
webhookTriggerLogMap["event_type"] = webhookTriggerLog.EventType
168+
}
169+
170+
if webhookTriggerLog.NotifyType != nil {
171+
webhookTriggerLogMap["notify_type"] = webhookTriggerLog.NotifyType
172+
}
173+
174+
if webhookTriggerLog.Detail != nil {
175+
webhookTriggerLogMap["detail"] = webhookTriggerLog.Detail
176+
}
177+
178+
if webhookTriggerLog.CreationTime != nil {
179+
webhookTriggerLogMap["creation_time"] = webhookTriggerLog.CreationTime
180+
}
181+
182+
if webhookTriggerLog.UpdateTime != nil {
183+
webhookTriggerLogMap["update_time"] = webhookTriggerLog.UpdateTime
184+
}
185+
186+
if webhookTriggerLog.Status != nil {
187+
webhookTriggerLogMap["status"] = webhookTriggerLog.Status
188+
}
189+
190+
ids = append(ids, helper.Int64ToStr(*webhookTriggerLog.Id))
191+
tmpList = append(tmpList, webhookTriggerLogMap)
192+
}
193+
194+
_ = d.Set("logs", tmpList)
195+
}
196+
197+
d.SetId(helper.DataResourceIdsHash(ids))
198+
output, ok := d.GetOk("result_output_file")
199+
if ok && output.(string) != "" {
200+
if e := writeToFile(output.(string), tmpList); e != nil {
201+
return e
202+
}
203+
}
204+
return nil
205+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudTcrDescribeWebhookTriggerLogsDataSource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccTcrDescribeWebhookTriggerLogsDataSource,
19+
Check: resource.ComposeTestCheckFunc(
20+
testAccCheckTencentCloudDataSourceID("data.tencentcloud_tcr_webhook_trigger_logs.my_logs"),
21+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.#"),
22+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "registry_id"),
23+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "namespace"),
24+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "trigger_id"),
25+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.#"),
26+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.id"),
27+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.trigger_id"),
28+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.event_type"),
29+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.notify_type"),
30+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.detail"),
31+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.creation_time"),
32+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.update_time"),
33+
resource.TestCheckResourceAttrSet("data.tencentcloud_tcr_webhook_trigger_logs.my_logs", "logs.0.status"),
34+
),
35+
},
36+
},
37+
})
38+
}
39+
40+
const testAccTcrDescribeWebhookTriggerLogsDataSource = defaultTCRInstanceData + `
41+
42+
data "tencentcloud_tcr_webhook_trigger_logs" "my_logs" {
43+
registry_id = local.tcr_id
44+
namespace = var.tcr_namespace
45+
trigger_id = 2
46+
tags = {
47+
"createdBy" = "terraform"
48+
}
49+
}
50+
51+
`

tencentcloud/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ Tencent Container Registry(TCR)
622622
tencentcloud_tcr_repositories
623623
tencentcloud_tcr_tokens
624624
tencentcloud_tcr_vpc_attachments
625+
tencentcloud_tcr_webhook_trigger_logs
625626
626627
Resource
627628
tencentcloud_tcr_instance
@@ -630,6 +631,7 @@ Tencent Container Registry(TCR)
630631
tencentcloud_tcr_token
631632
tencentcloud_tcr_vpc_attachment
632633
tencentcloud_tcr_tag_retention_rule
634+
tencentcloud_tcr_webhook_trigger
633635
634636
Video on Demand(VOD)
635637
Data Source
@@ -1378,6 +1380,7 @@ func Provider() terraform.ResourceProvider {
13781380
"tencentcloud_tcr_tokens": dataSourceTencentCloudTCRTokens(),
13791381
"tencentcloud_tcr_vpc_attachments": dataSourceTencentCloudTCRVPCAttachments(),
13801382
"tencentcloud_tcr_repositories": dataSourceTencentCloudTCRRepositories(),
1383+
"tencentcloud_tcr_webhook_trigger_logs": dataSourceTencentCloudTcrWebhookTriggerLogs(),
13811384
"tencentcloud_address_templates": dataSourceTencentCloudAddressTemplates(),
13821385
"tencentcloud_address_template_groups": dataSourceTencentCloudAddressTemplateGroups(),
13831386
"tencentcloud_protocol_templates": dataSourceTencentCloudProtocolTemplates(),
@@ -1715,6 +1718,7 @@ func Provider() terraform.ResourceProvider {
17151718
"tencentcloud_tcr_token": resourceTencentCloudTcrToken(),
17161719
"tencentcloud_tcr_vpc_attachment": resourceTencentCloudTcrVpcAttachment(),
17171720
"tencentcloud_tcr_tag_retention_rule": resourceTencentCloudTcrTagRetentionRule(),
1721+
"tencentcloud_tcr_webhook_trigger": resourceTencentCloudTcrWebhookTrigger(),
17181722
"tencentcloud_tdmq_instance": resourceTencentCloudTdmqInstance(),
17191723
"tencentcloud_tdmq_namespace": resourceTencentCloudTdmqNamespace(),
17201724
"tencentcloud_tdmq_topic": resourceTencentCloudTdmqTopic(),

tencentcloud/resource_tc_tcr_tag_retention_rule_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1212
)
1313

14-
func TestAccTencentCloudTCRTagRetentionRuleResource_basic(t *testing.T) {
14+
func TestAccTencentCloudTcrTagRetentionRuleResource_basic(t *testing.T) {
1515
t.Parallel()
1616
resource.Test(t, resource.TestCase{
1717
PreCheck: func() {

0 commit comments

Comments
 (0)