@@ -6,36 +6,39 @@ Example Usage
66Create normally
77
88```hcl
9+ data "tencentcloud_user_info" "info" {}
10+
911locals {
10- uin = data.tencentcloud_user_info.info.uin
12+ uin = data.tencentcloud_user_info.info.owner_uin
1113}
1214
13- data "tencentcloud_user_info" "info" {}
15+ output "uin" {
16+ value = local.uin
17+ }
1418
1519resource "tencentcloud_cam_role" "foo" {
16- name = "cam-role-test"
17- document = <<EOF
18- {
19- "version": "2.0",
20- "statement": [
20+ name = "cam-role-test"
21+ document = jsonencode(
2122 {
22- "action": [
23- "name/sts:AssumeRole"
24- ],
25- "effect": "allow",
26- "principal": {
27- "qcs": [
28- "qcs::cam::uin/${local.uin}:uin/${local.uin}"
29- ]
30- }
23+ statement = [
24+ {
25+ action = "name/sts:AssumeRole"
26+ effect = "allow"
27+ principal = {
28+ qcs = [
29+ "qcs::cam::uin/${local.uin}:root",
30+ ]
31+ }
32+ },
33+ ]
34+ version = "2.0"
3135 }
32- ]
33- }
34- EOF
35- description = "test"
36- console_login = true
37- tags = {
38- test = "tf-cam-role",
36+ )
37+ console_login = true
38+ description = "test"
39+ session_duration = 7200
40+ tags = {
41+ test = "tf-cam-role"
3942 }
4043}
4144```
@@ -151,6 +154,11 @@ func resourceTencentCloudCamRole() *schema.Resource {
151154 Optional : true ,
152155 Description : "Indicates whether the CAM role can login or not." ,
153156 },
157+ "session_duration" : {
158+ Type : schema .TypeInt ,
159+ Optional : true ,
160+ Description : "The maximum validity period of the temporary key for creating a role." ,
161+ },
154162 "create_time" : {
155163 Type : schema .TypeString ,
156164 Computed : true ,
@@ -199,6 +207,9 @@ func resourceTencentCloudCamRoleCreate(d *schema.ResourceData, meta interface{})
199207 }
200208 request .ConsoleLogin = & loginInt
201209 }
210+ if v , ok := d .GetOkExists ("session_duration" ); ok {
211+ request .SessionDuration = helper .IntUint64 (v .(int ))
212+ }
202213
203214 var response * cam.CreateRoleResponse
204215 err := resource .Retry (writeRetryTimeout , func () * resource.RetryError {
@@ -257,7 +268,7 @@ func resourceTencentCloudCamRoleCreate(d *schema.ResourceData, meta interface{})
257268 return err
258269 }
259270 }
260- time .Sleep (10 * time .Second )
271+ time .Sleep (5 * time .Second )
261272 return resourceTencentCloudCamRoleRead (d , meta )
262273}
263274
@@ -293,6 +304,7 @@ func resourceTencentCloudCamRoleRead(d *schema.ResourceData, meta interface{}) e
293304
294305 _ = d .Set ("name" , instance .RoleName )
295306 _ = d .Set ("document" , instance .PolicyDocument )
307+ _ = d .Set ("session_duration" , instance .SessionDuration )
296308 _ = d .Set ("create_time" , instance .AddTime )
297309 _ = d .Set ("update_time" , instance .UpdateTime )
298310 if instance .Description != nil {
@@ -441,6 +453,10 @@ func resourceTencentCloudCamRoleUpdate(d *schema.ResourceData, meta interface{})
441453 return err
442454 }
443455 }
456+
457+ if d .HasChange ("session_duration" ) {
458+ return fmt .Errorf ("`session_duration` do not support change now." )
459+ }
444460 return resourceTencentCloudCamRoleRead (d , meta )
445461}
446462
0 commit comments