From 01ec1df7c0c963ce2dfb4c51147b9388de9a583f Mon Sep 17 00:00:00 2001 From: tongyiming <1290863722@qq.com> Date: Wed, 23 Oct 2024 20:42:51 +0800 Subject: [PATCH] feat(tco): [120225468]add tencentcloud_organization_nodes and tencentcloud_open_identity_center_operation (#2906) * add resource * add changelog * update --------- Co-authored-by: mikatong --- .changelog/2906.txt | 7 + tencentcloud/provider.go | 2 + tencentcloud/provider.md | 2 + .../tco/data_source_tc_organization_nodes.go | 211 ++++++++++++++++++ .../tco/data_source_tc_organization_nodes.md | 12 + .../data_source_tc_organization_nodes_test.go | 42 ++++ ...ource_tc_open_identity_center_operation.go | 88 ++++++++ ...ource_tc_open_identity_center_operation.md | 9 + ..._tc_open_identity_center_operation_test.go | 34 +++ .../tco/service_tencentcloud_organization.go | 47 ++++ .../docs/d/organization_nodes.html.markdown | 43 ++++ ...en_identity_center_operation.html.markdown | 35 +++ website/tencentcloud.erb | 6 + 13 files changed, 538 insertions(+) create mode 100644 .changelog/2906.txt create mode 100644 tencentcloud/services/tco/data_source_tc_organization_nodes.go create mode 100644 tencentcloud/services/tco/data_source_tc_organization_nodes.md create mode 100644 tencentcloud/services/tco/data_source_tc_organization_nodes_test.go create mode 100644 tencentcloud/services/tco/resource_tc_open_identity_center_operation.go create mode 100644 tencentcloud/services/tco/resource_tc_open_identity_center_operation.md create mode 100644 tencentcloud/services/tco/resource_tc_open_identity_center_operation_test.go create mode 100644 website/docs/d/organization_nodes.html.markdown create mode 100644 website/docs/r/open_identity_center_operation.html.markdown diff --git a/.changelog/2906.txt b/.changelog/2906.txt new file mode 100644 index 0000000000..0ac3340089 --- /dev/null +++ b/.changelog/2906.txt @@ -0,0 +1,7 @@ +```release-note:new-resource +tencentcloud_open_identity_center_operation +``` + +```release-note:new-data-source +tencentcloud_organization_nodes +``` \ No newline at end of file diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index a19be2f264..f5c80bba37 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1094,6 +1094,7 @@ func Provider() *schema.Provider { "tencentcloud_identity_center_groups": tco.DataSourceTencentCloudIdentityCenterGroups(), "tencentcloud_identity_center_role_configurations": tco.DataSourceTencentCloudIdentityCenterRoleConfigurations(), "tencentcloud_identity_center_users": tco.DataSourceTencentCloudIdentityCenterUsers(), + "tencentcloud_organization_nodes": tco.DataSourceTencentCloudOrganizationNodes(), "tencentcloud_pts_scenario_with_jobs": pts.DataSourceTencentCloudPtsScenarioWithJobs(), "tencentcloud_cam_list_attached_user_policy": cam.DataSourceTencentCloudCamListAttachedUserPolicy(), "tencentcloud_cam_secret_last_used_time": cam.DataSourceTencentCloudCamSecretLastUsedTime(), @@ -1833,6 +1834,7 @@ func Provider() *schema.Provider { "tencentcloud_identity_center_user_sync_provisioning": tco.ResourceTencentCloudIdentityCenterUserSyncProvisioning(), "tencentcloud_identity_center_role_assignment": tco.ResourceTencentCloudIdentityCenterRoleAssignment(), "tencentcloud_invite_organization_member_operation": tco.ResourceTencentCloudInviteOrganizationMemberOperation(), + "tencentcloud_open_identity_center_operation": tco.ResourceTencentCloudOpenIdentityCenterOperation(), "tencentcloud_dbbrain_sql_filter": dbbrain.ResourceTencentCloudDbbrainSqlFilter(), "tencentcloud_dbbrain_security_audit_log_export_task": dbbrain.ResourceTencentCloudDbbrainSecurityAuditLogExportTask(), "tencentcloud_dbbrain_db_diag_report_task": dbbrain.ResourceTencentCloudDbbrainDbDiagReportTask(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index 1b37a01ca3..05db050e98 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -1682,6 +1682,7 @@ Tencent Cloud Organization (TCO) tencentcloud_identity_center_groups tencentcloud_identity_center_role_configurations tencentcloud_identity_center_users + tencentcloud_organization_nodes Resource tencentcloud_organization_instance tencentcloud_organization_org_node @@ -1708,6 +1709,7 @@ Tencent Cloud Organization (TCO) tencentcloud_identity_center_user_sync_provisioning tencentcloud_identity_center_role_assignment tencentcloud_invite_organization_member_operation + tencentcloud_open_identity_center_operation TDSQL-C for PostgreSQL(TDCPG) Data Source diff --git a/tencentcloud/services/tco/data_source_tc_organization_nodes.go b/tencentcloud/services/tco/data_source_tc_organization_nodes.go new file mode 100644 index 0000000000..ca93fd82ed --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_nodes.go @@ -0,0 +1,211 @@ +package tco + +import ( + "context" + "strconv" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + organization "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization/v20210331" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func DataSourceTencentCloudOrganizationNodes() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudOrganizationNodesRead, + Schema: map[string]*schema.Schema{ + "tags": { + Type: schema.TypeList, + Optional: true, + Description: "Department tag search list, with a maximum of 10.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "tag_key": { + Type: schema.TypeString, + Required: true, + Description: "Tag key.", + }, + "tag_value": { + Type: schema.TypeString, + Required: true, + Description: "Tag value.", + }, + }, + }, + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Description: "List details.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "node_id": { + Type: schema.TypeInt, + Required: true, + Description: "Organization node ID.", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Name.", + }, + "parent_node_id": { + Type: schema.TypeInt, + Required: true, + Description: "Parent node ID.", + }, + "remark": { + Type: schema.TypeString, + Required: true, + Description: "Remarks.", + }, + "create_time": { + Type: schema.TypeString, + Required: true, + Description: "Creation time.", + }, + "update_time": { + Type: schema.TypeString, + Required: true, + Description: "Update time.", + }, + "tags": { + Type: schema.TypeList, + Required: true, + Description: "Member tag list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "tag_key": { + Type: schema.TypeString, + Required: true, + Description: "Tag key.", + }, + "tag_value": { + Type: schema.TypeString, + Required: true, + Description: "Tag value.", + }, + }, + }, + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudOrganizationNodesRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_organization_nodes.read")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + service := OrganizationService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()} + + paramMap := make(map[string]interface{}) + if v, ok := d.GetOk("tags"); ok { + tagsSet := v.([]interface{}) + tmpSet := make([]*organization.Tag, 0, len(tagsSet)) + for _, item := range tagsSet { + tagsMap := item.(map[string]interface{}) + tag := organization.Tag{} + if v, ok := tagsMap["tag_key"]; ok { + tag.TagKey = helper.String(v.(string)) + } + if v, ok := tagsMap["tag_value"]; ok { + tag.TagValue = helper.String(v.(string)) + } + tmpSet = append(tmpSet, &tag) + } + paramMap["Tags"] = tmpSet + } + + var nodes []*organization.OrgNode + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeOrganizationNodesByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + nodes = result + return nil + }) + if err != nil { + return err + } + + itemList := make([]map[string]interface{}, 0, len(nodes)) + ids := make([]string, 0, len(nodes)) + for _, item := range nodes { + itemMap := map[string]interface{}{} + + if item.NodeId != nil { + itemMap["node_id"] = item.NodeId + nodeIdStr := strconv.FormatInt(*item.NodeId, 10) + ids = append(ids, nodeIdStr) + } + + if item.Name != nil { + itemMap["name"] = item.Name + } + + if item.ParentNodeId != nil { + itemMap["parent_node_id"] = item.ParentNodeId + } + + if item.Remark != nil { + itemMap["remark"] = item.Remark + } + + if item.CreateTime != nil { + itemMap["create_time"] = item.CreateTime + } + + if item.UpdateTime != nil { + itemMap["update_time"] = item.UpdateTime + } + + tagsList := make([]map[string]interface{}, 0, len(item.Tags)) + if item.Tags != nil { + for _, tags := range item.Tags { + tagsMap := map[string]interface{}{} + + if tags.TagKey != nil { + tagsMap["tag_key"] = tags.TagKey + } + + if tags.TagValue != nil { + tagsMap["tag_value"] = tags.TagValue + } + + tagsList = append(tagsList, tagsMap) + } + + itemMap["tags"] = tagsList + } + itemList = append(itemList, itemMap) + } + + _ = d.Set("items", itemList) + + d.SetId(helper.DataResourceIdsHash(ids)) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), itemList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/tco/data_source_tc_organization_nodes.md b/tencentcloud/services/tco/data_source_tc_organization_nodes.md new file mode 100644 index 0000000000..96370800fd --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_nodes.md @@ -0,0 +1,12 @@ +Use this data source to query detailed information of organization nodes + +Example Usage + +```hcl +data "tencentcloud_organization_nodes" "organization_nodes" { + tags { + tag_key = "createBy" + tag_value = "terraform" + } +} +``` diff --git a/tencentcloud/services/tco/data_source_tc_organization_nodes_test.go b/tencentcloud/services/tco/data_source_tc_organization_nodes_test.go new file mode 100644 index 0000000000..14f0dde781 --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_nodes_test.go @@ -0,0 +1,42 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudOrganizationNodesDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccOrganizationNodesDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_organization_nodes.organization_nodes"), + resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.#"), + resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.name"), + resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.node_id"), + resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.parent_node_id"), + resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.create_time"), + resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.update_time"), + resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.tags.#"), + ), + }}, + }) +} + +const testAccOrganizationNodesDataSource = ` + +data "tencentcloud_organization_nodes" "organization_nodes" { + tags { + tag_key = "createBy" + tag_value = "terraform" + } +} +` diff --git a/tencentcloud/services/tco/resource_tc_open_identity_center_operation.go b/tencentcloud/services/tco/resource_tc_open_identity_center_operation.go new file mode 100644 index 0000000000..b7f3d70787 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_open_identity_center_operation.go @@ -0,0 +1,88 @@ +package tco + +import ( + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + organization "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization/v20210331" + + tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" +) + +func ResourceTencentCloudOpenIdentityCenterOperation() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudInviteOpenIdentityCenterOperationCreate, + Read: resourceTencentCloudInviteOpenIdentityCenterOperationRead, + Delete: resourceTencentCloudInviteOpenIdentityCenterOperationDelete, + Schema: map[string]*schema.Schema{ + "zone_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Space name, which must be globally unique and contain 2-64 characters including lowercase letters, digits, and hyphens (-). It can neither start or end with a hyphen (-) nor contain two consecutive hyphens (-).", + }, + + "zone_id": { + Type: schema.TypeString, + Computed: true, + Description: "Space ID. z-Prefix starts with 12 random numbers/lowercase letters followed by.", + }, + }, + } +} + +func resourceTencentCloudInviteOpenIdentityCenterOperationCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_open_identity_center_operation.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + var ( + request = organization.NewOpenIdentityCenterRequest() + response = organization.NewOpenIdentityCenterResponse() + ) + + if v, ok := d.GetOk("zone_name"); ok { + request.ZoneName = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().OpenIdentityCenter(request) + if e != nil { + return tccommon.RetryError(e) + } else { + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) + } + response = result + return nil + }) + if err != nil { + log.Printf("[CRITAL]%s open identity center operation failed, reason:%+v", logId, err) + return err + } + + if response.Response != nil && response.Response.ZoneId != nil { + d.SetId(*response.Response.ZoneId) + _ = d.Set("zone_id", *response.Response.ZoneId) + } + + _ = response + + return resourceTencentCloudInviteOpenIdentityCenterOperationRead(d, meta) +} + +func resourceTencentCloudInviteOpenIdentityCenterOperationRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_open_identity_center_operation.read")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudInviteOpenIdentityCenterOperationDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_open_identity_center_operation.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/tco/resource_tc_open_identity_center_operation.md b/tencentcloud/services/tco/resource_tc_open_identity_center_operation.md new file mode 100644 index 0000000000..1e1e72ad83 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_open_identity_center_operation.md @@ -0,0 +1,9 @@ +Provides a resource to open identity center + +Example Usage + +```hcl +resource "tencentcloud_open_identity_center_operation" "open_identity_center_operation" { + zone_name = "test" +} +``` \ No newline at end of file diff --git a/tencentcloud/services/tco/resource_tc_open_identity_center_operation_test.go b/tencentcloud/services/tco/resource_tc_open_identity_center_operation_test.go new file mode 100644 index 0000000000..067cdaa06e --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_open_identity_center_operation_test.go @@ -0,0 +1,34 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudOpenIdentityCenterOperationResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOpenIdentityCenterOperation, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_open_identity_center_operation.open_identity_center_operation", "id"), + resource.TestCheckResourceAttrSet("tencentcloud_open_identity_center_operation.open_identity_center_operation", "zone_id"), + ), + }, + }, + }) +} + +const testAccOpenIdentityCenterOperation = ` +resource "tencentcloud_open_identity_center_operation" "open_identity_center_operation" { + zone_name = "test" +} +` diff --git a/tencentcloud/services/tco/service_tencentcloud_organization.go b/tencentcloud/services/tco/service_tencentcloud_organization.go index 3ec36adea8..8d0bad282b 100644 --- a/tencentcloud/services/tco/service_tencentcloud_organization.go +++ b/tencentcloud/services/tco/service_tencentcloud_organization.go @@ -1847,3 +1847,50 @@ func (me *OrganizationService) DescribeIdentityCenterRoleConfigurationsByFilter( return } + +func (me *OrganizationService) DescribeOrganizationNodesByFilter(ctx context.Context, param map[string]interface{}) (nodes []*organization.OrgNode, errRet error) { + var ( + logId = tccommon.GetLogId(ctx) + request = organization.NewDescribeOrganizationNodesRequest() + ) + + defer func() { + if errRet != nil { + log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error()) + } + }() + + for k, v := range param { + if k == "Tags" { + request.Tags = v.([]*organization.Tag) + } + } + + var ( + limit int64 = 50 + offset int64 = 0 + ) + request.Limit = &limit + request.Offset = &offset + nodes = make([]*organization.OrgNode, 0) + + for { + ratelimit.Check(request.GetAction()) + response, err := me.client.UseOrganizationClient().DescribeOrganizationNodes(request) + if err != nil { + errRet = err + return + } + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString()) + + if response == nil || response.Response == nil { + return + } + + nodes = append(nodes, response.Response.Items...) + if len(response.Response.Items) < int(limit) { + break + } + } + return +} diff --git a/website/docs/d/organization_nodes.html.markdown b/website/docs/d/organization_nodes.html.markdown new file mode 100644 index 0000000000..7f600cb40f --- /dev/null +++ b/website/docs/d/organization_nodes.html.markdown @@ -0,0 +1,43 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_organization_nodes" +sidebar_current: "docs-tencentcloud-datasource-organization_nodes" +description: |- + Use this data source to query detailed information of organization nodes +--- + +# tencentcloud_organization_nodes + +Use this data source to query detailed information of organization nodes + +## Example Usage + +```hcl +data "tencentcloud_organization_nodes" "organization_nodes" { + tags { + tag_key = "createBy" + tag_value = "terraform" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `result_output_file` - (Optional, String) Used to save results. +* `tags` - (Optional, List) Department tag search list, with a maximum of 10. + +The `tags` object supports the following: + +* `tag_key` - (Required, String) Tag key. +* `tag_value` - (Required, String) Tag value. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `items` - List details. + + diff --git a/website/docs/r/open_identity_center_operation.html.markdown b/website/docs/r/open_identity_center_operation.html.markdown new file mode 100644 index 0000000000..3c151c6566 --- /dev/null +++ b/website/docs/r/open_identity_center_operation.html.markdown @@ -0,0 +1,35 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_open_identity_center_operation" +sidebar_current: "docs-tencentcloud-resource-open_identity_center_operation" +description: |- + Provides a resource to open identity center +--- + +# tencentcloud_open_identity_center_operation + +Provides a resource to open identity center + +## Example Usage + +```hcl +resource "tencentcloud_open_identity_center_operation" "open_identity_center_operation" { + zone_name = "test" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `zone_name` - (Required, String, ForceNew) Space name, which must be globally unique and contain 2-64 characters including lowercase letters, digits, and hyphens (-). It can neither start or end with a hyphen (-) nor contain two consecutive hyphens (-). + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `zone_id` - Space ID. z-Prefix starts with 12 random numbers/lowercase letters followed by. + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 1d88decb4e..4b2fdbf57c 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -4420,6 +4420,9 @@
  • tencentcloud_organization_members
  • +
  • + tencentcloud_organization_nodes +
  • tencentcloud_organization_org_auth_node
  • @@ -4473,6 +4476,9 @@
  • tencentcloud_invite_organization_member_operation
  • +
  • + tencentcloud_open_identity_center_operation +
  • tencentcloud_organization_instance