From ada38c65ccce31b589be2fcd0ff716ec01b140b1 Mon Sep 17 00:00:00 2001 From: WeiMengXS Date: Tue, 1 Aug 2023 18:48:34 +0800 Subject: [PATCH 1/7] fix: modify cam doc --- tencentcloud/resource_tc_cam_group.go | 4 +-- .../resource_tc_cam_group_membership.go | 29 +++++++++++++++++-- ...resource_tc_cam_group_policy_attachment.go | 22 ++++++++++++-- tencentcloud/resource_tc_cam_policy.go | 4 +-- .../resource_tc_cam_policy_by_name.go | 4 +-- tencentcloud/resource_tc_cam_role.go | 4 +-- tencentcloud/resource_tc_cam_role_by_name.go | 2 +- .../resource_tc_cam_role_policy_attachment.go | 22 ++++++++++++-- ...e_tc_cam_role_policy_attachment_by_name.go | 22 ++++++++++++-- tencentcloud/resource_tc_cam_role_sso.go | 2 +- tencentcloud/resource_tc_cam_saml_provider.go | 4 +-- tencentcloud/resource_tc_cam_user.go | 6 ++-- .../resource_tc_cam_user_policy_attachment.go | 20 +++++++++++-- 13 files changed, 115 insertions(+), 30 deletions(-) diff --git a/tencentcloud/resource_tc_cam_group.go b/tencentcloud/resource_tc_cam_group.go index f7be334600..e9b250623f 100644 --- a/tencentcloud/resource_tc_cam_group.go +++ b/tencentcloud/resource_tc_cam_group.go @@ -5,8 +5,8 @@ Example Usage ```hcl resource "tencentcloud_cam_group" "foo" { - name = "cam-group-test" - remark = "test" + name = "tf_cam_group" + remark = "tf_group_remark" } ``` diff --git a/tencentcloud/resource_tc_cam_group_membership.go b/tencentcloud/resource_tc_cam_group_membership.go index 69b752ddee..73f763e156 100644 --- a/tencentcloud/resource_tc_cam_group_membership.go +++ b/tencentcloud/resource_tc_cam_group_membership.go @@ -4,10 +4,33 @@ Provides a resource to create a CAM group membership. Example Usage ```hcl -resource "tencentcloud_cam_group_membership" "foo" { - group_id = tencentcloud_cam_group.foo.id - user_names = [tencentcloud_cam_user.foo.name, tencentcloud_cam_user.bar.name] +variable "cam_group_basic" { + default = "keep-cam-group" } + +data "tencentcloud_cam_groups" "groups" { + name = var.cam_group_basic +} + +resource "tencentcloud_cam_user" "foo" { + name = "tf_cam_user" + remark = "tf_user_remark" + console_login = true + use_api = true + need_reset_password = true + password = "Gail@1234" + phone_num = "12345678910" + country_code = "86" + email = "1234@qq.com" + force_delete = true +} + + +resource "tencentcloud_cam_group_membership" "group_membership_basic" { + group_id = data.tencentcloud_cam_groups.groups.group_list.0.group_id + user_names = [tencentcloud_cam_user.foo.id] +} + ``` Import diff --git a/tencentcloud/resource_tc_cam_group_policy_attachment.go b/tencentcloud/resource_tc_cam_group_policy_attachment.go index 86b291cefc..2acb49c59d 100644 --- a/tencentcloud/resource_tc_cam_group_policy_attachment.go +++ b/tencentcloud/resource_tc_cam_group_policy_attachment.go @@ -4,9 +4,25 @@ Provides a resource to create a CAM group policy attachment. Example Usage ```hcl -resource "tencentcloud_cam_group_policy_attachment" "foo" { - group_id = tencentcloud_cam_group.foo.id - policy_id = tencentcloud_cam_policy.foo.id +variable "cam_policy_basic" { + default = "keep-cam-policy" +} + +variable "cam_group_basic" { + default = "keep-cam-group" +} + +data "tencentcloud_cam_groups" "groups" { + name = var.cam_group_basic +} + +data "tencentcloud_cam_policies" "policy" { + name = var.cam_policy_basic +} + +resource "tencentcloud_cam_group_policy_attachment" "group_policy_attachment_basic" { + group_id = data.tencentcloud_cam_groups.groups.group_list.0.group_id + policy_id = data.tencentcloud_cam_policies.policy.policy_list.0.policy_id } ``` diff --git a/tencentcloud/resource_tc_cam_policy.go b/tencentcloud/resource_tc_cam_policy.go index 935811ec52..37fe10a2ba 100644 --- a/tencentcloud/resource_tc_cam_policy.go +++ b/tencentcloud/resource_tc_cam_policy.go @@ -5,7 +5,7 @@ Example Usage ```hcl resource "tencentcloud_cam_policy" "foo" { - name = "cam-policy-test" + name = "tf_cam_policy" document = < Date: Tue, 1 Aug 2023 18:49:31 +0800 Subject: [PATCH 2/7] fix: modify cam doc --- website/docs/r/cam_group.html.markdown | 4 +-- .../docs/r/cam_group_membership.html.markdown | 27 ++++++++++++++++--- .../cam_group_policy_attachment.html.markdown | 22 ++++++++++++--- website/docs/r/cam_policy.html.markdown | 4 +-- website/docs/r/cam_role.html.markdown | 4 +-- .../cam_role_policy_attachment.html.markdown | 22 ++++++++++++--- website/docs/r/cam_role_sso.html.markdown | 2 +- .../docs/r/cam_saml_provider.html.markdown | 4 +-- website/docs/r/cam_user.html.markdown | 6 ++--- .../cam_user_policy_attachment.html.markdown | 20 +++++++++++--- 10 files changed, 91 insertions(+), 24 deletions(-) diff --git a/website/docs/r/cam_group.html.markdown b/website/docs/r/cam_group.html.markdown index 7186902bb6..c702277864 100644 --- a/website/docs/r/cam_group.html.markdown +++ b/website/docs/r/cam_group.html.markdown @@ -15,8 +15,8 @@ Provides a resource to create a CAM group. ```hcl resource "tencentcloud_cam_group" "foo" { - name = "cam-group-test" - remark = "test" + name = "tf_cam_group" + remark = "tf_group_remark" } ``` diff --git a/website/docs/r/cam_group_membership.html.markdown b/website/docs/r/cam_group_membership.html.markdown index e7e4988448..242527d613 100644 --- a/website/docs/r/cam_group_membership.html.markdown +++ b/website/docs/r/cam_group_membership.html.markdown @@ -14,9 +14,30 @@ Provides a resource to create a CAM group membership. ## Example Usage ```hcl -resource "tencentcloud_cam_group_membership" "foo" { - group_id = tencentcloud_cam_group.foo.id - user_names = [tencentcloud_cam_user.foo.name, tencentcloud_cam_user.bar.name] +variable "cam_group_basic" { + default = "keep-cam-group" +} + +data "tencentcloud_cam_groups" "groups" { + name = var.cam_group_basic +} + +resource "tencentcloud_cam_user" "foo" { + name = "tf_cam_user" + remark = "tf_user_remark" + console_login = true + use_api = true + need_reset_password = true + password = "Gail@1234" + phone_num = "12345678910" + country_code = "86" + email = "1234@qq.com" + force_delete = true +} + +resource "tencentcloud_cam_group_membership" "group_membership_basic" { + group_id = data.tencentcloud_cam_groups.groups.group_list.0.group_id + user_names = [tencentcloud_cam_user.foo.id] } ``` diff --git a/website/docs/r/cam_group_policy_attachment.html.markdown b/website/docs/r/cam_group_policy_attachment.html.markdown index 30d777bcda..809bea8271 100644 --- a/website/docs/r/cam_group_policy_attachment.html.markdown +++ b/website/docs/r/cam_group_policy_attachment.html.markdown @@ -14,9 +14,25 @@ Provides a resource to create a CAM group policy attachment. ## Example Usage ```hcl -resource "tencentcloud_cam_group_policy_attachment" "foo" { - group_id = tencentcloud_cam_group.foo.id - policy_id = tencentcloud_cam_policy.foo.id +variable "cam_policy_basic" { + default = "keep-cam-policy" +} + +variable "cam_group_basic" { + default = "keep-cam-group" +} + +data "tencentcloud_cam_groups" "groups" { + name = var.cam_group_basic +} + +data "tencentcloud_cam_policies" "policy" { + name = var.cam_policy_basic +} + +resource "tencentcloud_cam_group_policy_attachment" "group_policy_attachment_basic" { + group_id = data.tencentcloud_cam_groups.groups.group_list.0.group_id + policy_id = data.tencentcloud_cam_policies.policy.policy_list.0.policy_id } ``` diff --git a/website/docs/r/cam_policy.html.markdown b/website/docs/r/cam_policy.html.markdown index 41f7fcec6d..e44ea4bc9c 100644 --- a/website/docs/r/cam_policy.html.markdown +++ b/website/docs/r/cam_policy.html.markdown @@ -15,7 +15,7 @@ Provides a resource to create a CAM policy. ```hcl resource "tencentcloud_cam_policy" "foo" { - name = "cam-policy-test" + name = "tf_cam_policy" document = < Date: Wed, 2 Aug 2023 11:12:46 +0800 Subject: [PATCH 3/7] fix: modify cam doc --- examples/tencentcloud-cam/main.tf | 102 ++++++++++++++++--------- examples/tencentcloud-cam/user-info.tf | 5 ++ examples/tencentcloud-cam/variables.tf | 21 ----- tencentcloud/resource_tc_cam_role.go | 33 +++++++- website/docs/r/cam_role.html.markdown | 33 +++++++- 5 files changed, 129 insertions(+), 65 deletions(-) create mode 100644 examples/tencentcloud-cam/user-info.tf diff --git a/examples/tencentcloud-cam/main.tf b/examples/tencentcloud-cam/main.tf index 8d58b3c8c8..a34b0c1c35 100644 --- a/examples/tencentcloud-cam/main.tf +++ b/examples/tencentcloud-cam/main.tf @@ -1,3 +1,50 @@ +terraform { + required_providers { + tencentcloud = { + source = "tencentcloudstack/tencentcloud" + } + } +} +provider "tencentcloud" { + region = "ap-guangzhou" +} + +data "tencentcloud_cam_users" "users" { + name = tencentcloud_cam_user.example.id +} + +data "tencentcloud_cam_roles" "roles" { + role_id = tencentcloud_cam_role.example.id +} + +data "tencentcloud_cam_policies" "policies" { + policy_id = tencentcloud_cam_policy.example.id +} + +data "tencentcloud_cam_groups" "groups" { + group_id = tencentcloud_cam_group.example.id +} + +data "tencentcloud_cam_group_memberships" "memberships" { + group_id = tencentcloud_cam_group_membership.example.id +} + +data "tencentcloud_cam_user_policy_attachments" "user_policy_attachments" { + user_name = tencentcloud_cam_user_policy_attachment.example.user_name +} + +data "tencentcloud_cam_role_policy_attachments" "role_policy_attachments" { + role_id = tencentcloud_cam_role_policy_attachment.example.role_id +} + +data "tencentcloud_cam_group_policy_attachments" "group_policy_attachments" { + group_id = tencentcloud_cam_group_policy_attachment.example.group_id +} + +data "tencentcloud_cam_saml_providers" "saml_providers" { + name = tencentcloud_cam_saml_provider.example.id +} + resource "tencentcloud_cam_group" "example" { name = "example" remark = "example" @@ -23,7 +70,25 @@ resource "tencentcloud_cam_policy" "example" { resource "tencentcloud_cam_role" "example" { name = "example" - document = var.role_document + document =<:uin/"] + "qcs": [ + "qcs::cam::uin/${local.uin}:uin/${local.uin}" + ] } } ] @@ -33,6 +43,17 @@ EOF Create with SAML provider ```hcl +variable "saml-provider" { + default = "example" +} + +locals { + uin = data.tencentcloud_user_info.info.uin + saml_provider = var.saml-provider +} + +data "tencentcloud_user_info" "info" {} + resource "tencentcloud_cam_role" "boo" { name = "tf_cam_role" document = <:saml-provider/"] + "qcs": [ + "qcs::cam::uin/${local.uin}:saml-provider/${local.saml_provider}" + ] } } ] diff --git a/website/docs/r/cam_role.html.markdown b/website/docs/r/cam_role.html.markdown index ec7a01187e..d1d41c1b86 100644 --- a/website/docs/r/cam_role.html.markdown +++ b/website/docs/r/cam_role.html.markdown @@ -16,6 +16,12 @@ Provides a resource to create a CAM role. ### Create normally ```hcl +locals { + uin = data.tencentcloud_user_info.info.uin +} + +data "tencentcloud_user_info" "info" {} + resource "tencentcloud_cam_role" "foo" { name = "cam-role-test" document = <:uin/"] + "qcs": [ + "qcs::cam::uin/${local.uin}:uin/${local.uin}" + ] } } ] @@ -43,6 +53,17 @@ EOF ### Create with SAML provider ```hcl +variable "saml-provider" { + default = "example" +} + +locals { + uin = data.tencentcloud_user_info.info.uin + saml_provider = var.saml-provider +} + +data "tencentcloud_user_info" "info" {} + resource "tencentcloud_cam_role" "boo" { name = "tf_cam_role" document = <:saml-provider/"] + "qcs": [ + "qcs::cam::uin/${local.uin}:saml-provider/${local.saml_provider}" + ] } } ] From cacdb1bac9c8d4127e01559e01276bc287b4a127 Mon Sep 17 00:00:00 2001 From: WeiMengXS Date: Wed, 2 Aug 2023 11:28:06 +0800 Subject: [PATCH 4/7] fix: add Resource doc --- tencentcloud/provider.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 553539620b..aa2060003c 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -213,8 +213,11 @@ Cloud Access Management(CAM) Resource tencentcloud_cam_role + tencentcloud_cam_role_by_name tencentcloud_cam_role_policy_attachment + tencentcloud_cam_role_policy_attachment_by_name tencentcloud_cam_policy + tencentcloud_cam_policy_by_name tencentcloud_cam_user tencentcloud_cam_user_policy_attachment tencentcloud_cam_group From 5f6605f4d909ba9ca2d1e1c5f3613de89863701a Mon Sep 17 00:00:00 2001 From: WeiMengXS Date: Wed, 2 Aug 2023 11:30:23 +0800 Subject: [PATCH 5/7] fix: fix Resource doc --- .../docs/r/cam_policy_by_name.html.markdown | 64 +++++++++++++ website/docs/r/cam_role_by_name.html.markdown | 93 +++++++++++++++++++ ...le_policy_attachment_by_name.html.markdown | 63 +++++++++++++ website/tencentcloud.erb | 9 ++ 4 files changed, 229 insertions(+) create mode 100644 website/docs/r/cam_policy_by_name.html.markdown create mode 100644 website/docs/r/cam_role_by_name.html.markdown create mode 100644 website/docs/r/cam_role_policy_attachment_by_name.html.markdown diff --git a/website/docs/r/cam_policy_by_name.html.markdown b/website/docs/r/cam_policy_by_name.html.markdown new file mode 100644 index 0000000000..2e6a144163 --- /dev/null +++ b/website/docs/r/cam_policy_by_name.html.markdown @@ -0,0 +1,64 @@ +--- +subcategory: "Cloud Access Management(CAM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cam_policy_by_name" +sidebar_current: "docs-tencentcloud-resource-cam_policy_by_name" +description: |- + Provides a resource to create a CAM policy. +--- + +# tencentcloud_cam_policy_by_name + +Provides a resource to create a CAM policy. + +## Example Usage + +```hcl +resource "tencentcloud_cam_policy_by_name" "foo" { + name = "tf_cam_policy_name" + document = <:uin/"] + } + } + ] +} +EOF + description = "test" + console_login = true + tags = { + test = "tf-cam-role", + } +} +``` + +### Create with SAML provider + +```hcl +resource "tencentcloud_cam_role_by_name" "boo" { + name = "cam-role-test" + document = <:saml-provider/"] + } + } + ] +} +EOF + description = "test" + console_login = true +} +``` + +## Argument Reference + +The following arguments are supported: + +* `document` - (Required, String) Document of the CAM role. The syntax refers to [CAM POLICY](https://intl.cloud.tencent.com/document/product/598/10604). There are some notes when using this para in terraform: 1. The elements in json claimed supporting two types as `string` and `array` only support type `array`; 2. Terraform does not support the `root` syntax, when appears, it must be replaced with the uin it stands for. +* `name` - (Required, String, ForceNew) Name of CAM role. +* `console_login` - (Optional, Bool, ForceNew) Indicates whether the CAM role can login or not. +* `description` - (Optional, String) Description of the CAM role. +* `tags` - (Optional, Map) A list of tags used to associate different resources. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `create_time` - Create time of the CAM role. +* `update_time` - The last update time of the CAM role. + + +## Import + +CAM role can be imported using the name, e.g. + +``` +$ terraform import tencentcloud_cam_role_by_name.foo cam-role-test +``` + diff --git a/website/docs/r/cam_role_policy_attachment_by_name.html.markdown b/website/docs/r/cam_role_policy_attachment_by_name.html.markdown new file mode 100644 index 0000000000..3698bd48ba --- /dev/null +++ b/website/docs/r/cam_role_policy_attachment_by_name.html.markdown @@ -0,0 +1,63 @@ +--- +subcategory: "Cloud Access Management(CAM)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_cam_role_policy_attachment_by_name" +sidebar_current: "docs-tencentcloud-resource-cam_role_policy_attachment_by_name" +description: |- + Provides a resource to create a CAM role policy attachment. +--- + +# tencentcloud_cam_role_policy_attachment_by_name + +Provides a resource to create a CAM role policy attachment. + +## Example Usage + +```hcl +variable "cam_policy_basic" { + default = "keep-cam-policy" +} + +variable "cam_role_basic" { + default = "keep-cam-role" +} + +data "tencentcloud_cam_policies" "policy" { + name = var.cam_policy_basic +} + +data "tencentcloud_cam_roles" "roles" { + name = var.cam_role_basic +} + +resource "tencentcloud_cam_role_policy_attachment_by_name" "role_policy_attachment_basic" { + role_name = var.cam_role_basic + policy_name = var.cam_policy_basic +} +``` + +## Argument Reference + +The following arguments are supported: + +* `policy_name` - (Required, String, ForceNew) Name of the policy. +* `role_name` - (Required, String, ForceNew) Name of the attached CAM role. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `create_mode` - Mode of Creation of the CAM role policy attachment. `1` means the CAM policy attachment is created by production, and the others indicate syntax strategy ways. +* `create_time` - The create time of the CAM role policy attachment. +* `policy_type` - Type of the policy strategy. `User` means customer strategy and `QCS` means preset strategy. + + +## Import + +CAM role policy attachment can be imported using the id, e.g. + +``` +$ terraform import tencentcloud_cam_role_policy_attachment_by_name.foo ${role_name}#${policy_name} +``` + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 94bbecf54c..ed27d0f3f6 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -402,12 +402,21 @@
  • tencentcloud_cam_policy
  • +
  • + tencentcloud_cam_policy_by_name +
  • tencentcloud_cam_role
  • +
  • + tencentcloud_cam_role_by_name +
  • tencentcloud_cam_role_policy_attachment
  • +
  • + tencentcloud_cam_role_policy_attachment_by_name +
  • tencentcloud_cam_role_sso
  • From b39612708c47b14ab10b89ec31daab28564aa78e Mon Sep 17 00:00:00 2001 From: WeiMengXS Date: Wed, 2 Aug 2023 11:34:49 +0800 Subject: [PATCH 6/7] fix: fix Resource doc --- tencentcloud/provider.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index aa2060003c..f6e7a601c7 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -213,11 +213,11 @@ Cloud Access Management(CAM) Resource tencentcloud_cam_role - tencentcloud_cam_role_by_name + tencentcloud_cam_role_by_name tencentcloud_cam_role_policy_attachment - tencentcloud_cam_role_policy_attachment_by_name + tencentcloud_cam_role_policy_attachment_by_name tencentcloud_cam_policy - tencentcloud_cam_policy_by_name + tencentcloud_cam_policy_by_name tencentcloud_cam_user tencentcloud_cam_user_policy_attachment tencentcloud_cam_group From 97338ce40a8a4630cd2b065eac7f85583eea1669 Mon Sep 17 00:00:00 2001 From: WeiMengXS Date: Wed, 2 Aug 2023 19:45:24 +0800 Subject: [PATCH 7/7] fix: fix example doc --- .../resource_tc_cam_user_policy_attachment.go | 16 +++++++++++++++- .../r/cam_user_policy_attachment.html.markdown | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tencentcloud/resource_tc_cam_user_policy_attachment.go b/tencentcloud/resource_tc_cam_user_policy_attachment.go index 3d93f8aa6d..3d49fa3ffe 100644 --- a/tencentcloud/resource_tc_cam_user_policy_attachment.go +++ b/tencentcloud/resource_tc_cam_user_policy_attachment.go @@ -10,7 +10,21 @@ variable "cam_user_basic" { resource "tencentcloud_cam_policy" "policy_basic" { name = "tf_cam_attach_user_policy" - document = "{\"version\":\"2.0\",\"statement\":[{\"action\":[\"cos:*\"],\"resource\":[\"*\"],\"effect\":\"allow\"},{\"effect\":\"allow\",\"action\":[\"monitor:*\",\"cam:ListUsersForGroup\",\"cam:ListGroups\",\"cam:GetGroup\"],\"resource\":[\"*\"]}]}" + document =jsonencode({ + "version":"2.0", + "statement":[ + { + "action":["cos:*"], + "resource":["*"], + "effect":"allow", + }, + { + "effect":"allow", + "action":["monitor:*","cam:ListUsersForGroup","cam:ListGroups","cam:GetGroup"], + "resource":["*"], + } + ] + }) description = "tf_test" } diff --git a/website/docs/r/cam_user_policy_attachment.html.markdown b/website/docs/r/cam_user_policy_attachment.html.markdown index 4799304242..877ca6ce86 100644 --- a/website/docs/r/cam_user_policy_attachment.html.markdown +++ b/website/docs/r/cam_user_policy_attachment.html.markdown @@ -19,8 +19,22 @@ variable "cam_user_basic" { } resource "tencentcloud_cam_policy" "policy_basic" { - name = "tf_cam_attach_user_policy" - document = "{\"version\":\"2.0\",\"statement\":[{\"action\":[\"cos:*\"],\"resource\":[\"*\"],\"effect\":\"allow\"},{\"effect\":\"allow\",\"action\":[\"monitor:*\",\"cam:ListUsersForGroup\",\"cam:ListGroups\",\"cam:GetGroup\"],\"resource\":[\"*\"]}]}" + name = "tf_cam_attach_user_policy" + document = jsonencode({ + "version" : "2.0", + "statement" : [ + { + "action" : ["cos:*"], + "resource" : ["*"], + "effect" : "allow", + }, + { + "effect" : "allow", + "action" : ["monitor:*", "cam:ListUsersForGroup", "cam:ListGroups", "cam:GetGroup"], + "resource" : ["*"], + } + ] + }) description = "tf_test" }