@@ -11,6 +11,9 @@ resource "tencentcloud_scf_trigger_config" "trigger_config" {
1111 type = "timer"
1212 qualifier = "$DEFAULT"
1313 namespace = "default"
14+ trigger_desc = "* 1 2 * * * *"
15+ description = "func"
16+ custom_argument = "Information"
1417}
1518```
1619
@@ -26,6 +29,7 @@ package tencentcloud
2629
2730import (
2831 "context"
32+ "encoding/json"
2933 "fmt"
3034 "log"
3135 "strings"
@@ -48,70 +52,132 @@ func resourceTencentCloudScfTriggerConfig() *schema.Resource {
4852 Schema : map [string ]* schema.Schema {
4953 "function_name" : {
5054 Required : true ,
55+ ForceNew : true ,
5156 Type : schema .TypeString ,
52- Description : "Function name." ,
57+ Description : "function name." ,
5358 },
5459
5560 "trigger_name" : {
5661 Required : true ,
62+ ForceNew : true ,
5763 Type : schema .TypeString ,
58- Description : "Trigger name ." ,
64+ Description : "trigger Name ." ,
5965 },
6066
6167 "type" : {
6268 Required : true ,
6369 Type : schema .TypeString ,
64- Description : "Trigger Type ." ,
70+ Description : "trigger type ." ,
6571 },
6672
6773 "enable" : {
68- Required : true ,
74+ Optional : true ,
6975 Type : schema .TypeString ,
70- Description : "Initial status of the trigger. Values: ` OPEN` (enabled); ` CLOSE` disabled) ." ,
76+ Description : "The trigger is turned on or off, and the parameter passed as OPEN is turned on, and CLOSE is turned off ." ,
7177 },
7278
7379 "qualifier" : {
7480 Optional : true ,
7581 Type : schema .TypeString ,
76- Description : "Function version. It defaults to ` $LATEST`. It's recommended to use ` [$DEFAULT](https://intl.cloud.tencent.com/document/product/583/36149?from_cn_redirect=1#.E9.BB.98.E8.AE.A4.E5.88.AB.E5.90.8D)` for canary release." ,
82+ Description : "The version of the function, the default is $LATEST, it is recommended to fill in [$DEFAULT] to facilitate the subsequent grayscale release of the version ." ,
7783 },
7884
7985 "namespace" : {
8086 Optional : true ,
87+ ForceNew : true ,
8188 Type : schema .TypeString ,
82- Default : "default" ,
83- Description : "Function namespace." ,
89+ Description : "function namespace." ,
8490 },
8591
8692 "trigger_desc" : {
8793 Optional : true ,
88- Computed : true ,
8994 Type : schema .TypeString ,
90- Description : "To update a COS trigger, this field is required. It stores the data {event:cos:ObjectCreated:*} in the JSON format. The data content of this field is in the same format as that of SetTrigger. This field is optional if a scheduled trigger or CMQ trigger is to be deleted." ,
95+ Description : "TriggerDesc parameter." ,
96+ },
97+
98+ "description" : {
99+ Optional : true ,
100+ Type : schema .TypeString ,
101+ Description : "Trigger description." ,
102+ },
103+
104+ "custom_argument" : {
105+ Optional : true ,
106+ Type : schema .TypeString ,
107+ Description : "User Additional Information." ,
91108 },
92109 },
93110 }
94111}
95112
113+ type TriggerDesc struct {
114+ Cron string `json:"cron"`
115+ }
116+
96117func resourceTencentCloudScfTriggerConfigCreate (d * schema.ResourceData , meta interface {}) error {
97118 defer logElapsed ("resource.tencentcloud_scf_trigger_config.create" )()
98119 defer inconsistentCheck (d , meta )()
99120
121+ logId := getLogId (contextNil )
122+
100123 var (
124+ request = scf .NewUpdateTriggerRequest ()
101125 functionName string
102126 triggerName string
103127 namespace string
104128 )
129+
105130 if v , ok := d .GetOk ("function_name" ); ok {
106- functionName = v .(string )
131+ request .FunctionName = helper .String (v .(string ))
132+ functionName = * request .FunctionName
133+ }
134+
135+ if v , ok := d .GetOk ("trigger_name" ); ok {
136+ request .TriggerName = helper .String (v .(string ))
137+ triggerName = * request .TriggerName
138+ }
139+
140+ if v , ok := d .GetOk ("type" ); ok {
141+ request .Type = helper .String (v .(string ))
142+ }
143+
144+ if v , ok := d .GetOk ("enable" ); ok {
145+ request .Enable = helper .String (v .(string ))
146+ }
147+
148+ if v , ok := d .GetOk ("qualifier" ); ok {
149+ request .Qualifier = helper .String (v .(string ))
107150 }
108151
109152 if v , ok := d .GetOk ("namespace" ); ok {
110- namespace = v .(string )
153+ request .Namespace = helper .String (v .(string ))
154+ namespace = * request .Namespace
111155 }
112156
113- if v , ok := d .GetOk ("trigger_name" ); ok {
114- triggerName = v .(string )
157+ if v , ok := d .GetOk ("trigger_desc" ); ok {
158+ request .TriggerDesc = helper .String (v .(string ))
159+ }
160+
161+ if v , ok := d .GetOk ("description" ); ok {
162+ request .Description = helper .String (v .(string ))
163+ }
164+
165+ if v , ok := d .GetOk ("custom_argument" ); ok {
166+ request .CustomArgument = helper .String (v .(string ))
167+ }
168+
169+ err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
170+ result , e := meta .(* TencentCloudClient ).apiV3Conn .UseScfClient ().UpdateTrigger (request )
171+ if e != nil {
172+ return retryError (e )
173+ } else {
174+ log .Printf ("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n " , logId , request .GetAction (), request .ToJsonString (), result .ToJsonString ())
175+ }
176+ return nil
177+ })
178+ if err != nil {
179+ log .Printf ("[CRITAL]%s operate scf triggerConfig failed, reason:%+v" , logId , err )
180+ return err
115181 }
116182
117183 d .SetId (functionName + FILED_SP + namespace + FILED_SP + triggerName )
@@ -173,7 +239,20 @@ func resourceTencentCloudScfTriggerConfigRead(d *schema.ResourceData, meta inter
173239 }
174240
175241 if triggerConfig .TriggerDesc != nil {
176- _ = d .Set ("trigger_desc" , triggerConfig .TriggerDesc )
242+ var triggerDesc TriggerDesc
243+ err := json .Unmarshal ([]byte (* triggerConfig .TriggerDesc ), & triggerDesc )
244+ if err != nil {
245+ return err
246+ }
247+ _ = d .Set ("trigger_desc" , triggerDesc .Cron )
248+ }
249+
250+ if triggerConfig .CustomArgument != nil {
251+ _ = d .Set ("custom_argument" , triggerConfig .CustomArgument )
252+ }
253+
254+ if triggerConfig .CustomArgument != nil {
255+ _ = d .Set ("description" , triggerConfig .Description )
177256 }
178257
179258 return nil
@@ -185,7 +264,7 @@ func resourceTencentCloudScfTriggerConfigUpdate(d *schema.ResourceData, meta int
185264
186265 logId := getLogId (contextNil )
187266
188- request := scf .NewUpdateTriggerStatusRequest ()
267+ request := scf .NewUpdateTriggerRequest ()
189268
190269 idSplit := strings .Split (d .Id (), FILED_SP )
191270 if len (idSplit ) != 3 {
@@ -199,14 +278,14 @@ func resourceTencentCloudScfTriggerConfigUpdate(d *schema.ResourceData, meta int
199278 request .Namespace = & namespace
200279 request .TriggerName = & triggerName
201280
202- if v , ok := d .GetOk ("enable" ); ok {
203- request .Enable = helper .String (v .(string ))
204- }
205-
206281 if v , ok := d .GetOk ("type" ); ok {
207282 request .Type = helper .String (v .(string ))
208283 }
209284
285+ if v , ok := d .GetOk ("enable" ); ok {
286+ request .Enable = helper .String (v .(string ))
287+ }
288+
210289 if v , ok := d .GetOk ("qualifier" ); ok {
211290 request .Qualifier = helper .String (v .(string ))
212291 }
@@ -215,8 +294,16 @@ func resourceTencentCloudScfTriggerConfigUpdate(d *schema.ResourceData, meta int
215294 request .TriggerDesc = helper .String (v .(string ))
216295 }
217296
297+ if v , ok := d .GetOk ("description" ); ok {
298+ request .Description = helper .String (v .(string ))
299+ }
300+
301+ if v , ok := d .GetOk ("custom_argument" ); ok {
302+ request .CustomArgument = helper .String (v .(string ))
303+ }
304+
218305 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
219- result , e := meta .(* TencentCloudClient ).apiV3Conn .UseScfClient ().UpdateTriggerStatus (request )
306+ result , e := meta .(* TencentCloudClient ).apiV3Conn .UseScfClient ().UpdateTrigger (request )
220307 if e != nil {
221308 return retryError (e )
222309 } else {
0 commit comments