From 0ae5bc7f784935707c7e9d05f93f688616899d31 Mon Sep 17 00:00:00 2001 From: tongyiming <1290863722@qq.com> Date: Fri, 20 Dec 2024 19:58:31 +0800 Subject: [PATCH] feat(tco): [121226730] support organization share (#3029) * support organization share * add changelog --------- Co-authored-by: mikatong --- .changelog/3029.txt | 23 ++ tencentcloud/provider.go | 6 + tencentcloud/provider.md | 6 + ..._tc_organization_org_share_unit_members.go | 133 +++++++++ ..._tc_organization_org_share_unit_members.md | 11 + ...rganization_org_share_unit_members_test.go | 51 ++++ ...c_organization_org_share_unit_resources.go | 188 +++++++++++++ ...c_organization_org_share_unit_resources.md | 10 + ...anization_org_share_unit_resources_test.go | 49 ++++ ..._source_tc_organization_org_share_units.go | 195 +++++++++++++ ..._source_tc_organization_org_share_units.md | 10 + ...ce_tc_organization_org_share_units_test.go | 41 +++ ...pt_join_share_unit_invitation_operation.go | 85 ++++++ ...pt_join_share_unit_invitation_operation.md | 9 + ...in_share_unit_invitation_operation_test.go | 43 +++ ...tc_organization_org_share_unit_resource.go | 263 ++++++++++++++++++ ...tc_organization_org_share_unit_resource.md | 20 ++ ...ganization_org_share_unit_resource_test.go | 47 ++++ ...ct_join_share_unit_invitation_operation.go | 85 ++++++ ...ct_join_share_unit_invitation_operation.md | 9 + ...in_share_unit_invitation_operation_test.go | 38 +++ .../tco/service_tencentcloud_organization.go | 215 ++++++++++++++ ...ation_org_share_unit_members.html.markdown | 39 +++ ...ion_org_share_unit_resources.html.markdown | 39 +++ ...organization_org_share_units.html.markdown | 37 +++ ...re_unit_invitation_operation.html.markdown | 35 +++ ...tion_org_share_unit_resource.html.markdown | 53 ++++ ...re_unit_invitation_operation.html.markdown | 35 +++ website/tencentcloud.erb | 18 ++ 29 files changed, 1793 insertions(+) create mode 100644 .changelog/3029.txt create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.go create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.md create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members_test.go create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.go create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.md create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources_test.go create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_units.go create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_units.md create mode 100644 tencentcloud/services/tco/data_source_tc_organization_org_share_units_test.go create mode 100644 tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.go create mode 100644 tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.md create mode 100644 tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation_test.go create mode 100644 tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.go create mode 100644 tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.md create mode 100644 tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource_test.go create mode 100644 tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.go create mode 100644 tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.md create mode 100644 tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation_test.go create mode 100644 website/docs/d/organization_org_share_unit_members.html.markdown create mode 100644 website/docs/d/organization_org_share_unit_resources.html.markdown create mode 100644 website/docs/d/organization_org_share_units.html.markdown create mode 100644 website/docs/r/accept_join_share_unit_invitation_operation.html.markdown create mode 100644 website/docs/r/organization_org_share_unit_resource.html.markdown create mode 100644 website/docs/r/reject_join_share_unit_invitation_operation.html.markdown diff --git a/.changelog/3029.txt b/.changelog/3029.txt new file mode 100644 index 0000000000..3c78e74076 --- /dev/null +++ b/.changelog/3029.txt @@ -0,0 +1,23 @@ +```release-note:new-resource +tencentcloud_organization_org_share_unit_resource +``` + +```release-note:new-resource +tencentcloud_accept_join_share_unit_invitation_operation +``` + +```release-note:new-resource +tencentcloud_reject_join_share_unit_invitation_operation +``` + +```release-note:new-data-source +tencentcloud_organization_org_share_unit_resources +``` + +```release-note:new-data-source +tencentcloud_organization_org_share_units +``` + +```release-note:new-data-source +tencentcloud_organization_org_share_unit_members +``` diff --git a/tencentcloud/provider.go b/tencentcloud/provider.go index 787c183bc0..72ec4cabc8 100644 --- a/tencentcloud/provider.go +++ b/tencentcloud/provider.go @@ -1117,6 +1117,9 @@ func Provider() *schema.Provider { "tencentcloud_identity_center_role_configurations": tco.DataSourceTencentCloudIdentityCenterRoleConfigurations(), "tencentcloud_identity_center_users": tco.DataSourceTencentCloudIdentityCenterUsers(), "tencentcloud_organization_nodes": tco.DataSourceTencentCloudOrganizationNodes(), + "tencentcloud_organization_org_share_unit_resources": tco.DataSourceTencentCloudOrganizationOrgShareUnitResources(), + "tencentcloud_organization_org_share_units": tco.DataSourceTencentCloudOrganizationOrgShareUnits(), + "tencentcloud_organization_org_share_unit_members": tco.DataSourceTencentCloudOrganizationOrgShareUnitMembers(), "tencentcloud_pts_scenario_with_jobs": pts.DataSourceTencentCloudPtsScenarioWithJobs(), "tencentcloud_cam_list_attached_user_policy": cam.DataSourceTencentCloudCamListAttachedUserPolicy(), "tencentcloud_cam_secret_last_used_time": cam.DataSourceTencentCloudCamSecretLastUsedTime(), @@ -2193,6 +2196,9 @@ func Provider() *schema.Provider { "tencentcloud_csip_risk_center": csip.ResourceTencentCloudCsipRiskCenter(), "tencentcloud_organization_org_share_unit_member": tco.ResourceTencentCloudOrganizationOrgShareUnitMember(), "tencentcloud_organization_org_share_unit": tco.ResourceTencentCloudOrganizationOrgShareUnit(), + "tencentcloud_organization_org_share_unit_resource": tco.ResourceTencentCloudOrganizationOrgShareUnitResource(), + "tencentcloud_accept_join_share_unit_invitation_operation": tco.ResourceTencentCloudAcceptJoinShareUnitInvitationOperation(), + "tencentcloud_reject_join_share_unit_invitation_operation": tco.ResourceTencentCloudRejectJoinShareUnitInvitationOperation(), "tencentcloud_kubernetes_addon": tke.ResourceTencentCloudKubernetesAddon(), "tencentcloud_kubernetes_addon_config": tke.ResourceTencentCloudKubernetesAddonConfig(), "tencentcloud_kubernetes_native_node_pool": tke.ResourceTencentCloudKubernetesNativeNodePool(), diff --git a/tencentcloud/provider.md b/tencentcloud/provider.md index c592f06364..27ca8ec980 100644 --- a/tencentcloud/provider.md +++ b/tencentcloud/provider.md @@ -1706,6 +1706,9 @@ Tencent Cloud Organization (TCO) tencentcloud_identity_center_role_configurations tencentcloud_identity_center_users tencentcloud_organization_nodes + tencentcloud_organization_org_share_unit_resources + tencentcloud_organization_org_share_units + tencentcloud_organization_org_share_unit_members Resource tencentcloud_organization_instance tencentcloud_organization_org_node @@ -1737,6 +1740,9 @@ Tencent Cloud Organization (TCO) tencentcloud_identity_center_scim_credential_status tencentcloud_identity_center_scim_credential tencentcloud_identity_center_scim_synchronization_status + tencentcloud_organization_org_share_unit_resource + tencentcloud_accept_join_share_unit_invitation_operation + tencentcloud_reject_join_share_unit_invitation_operation TDSQL-C for PostgreSQL(TDCPG) Data Source diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.go b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.go new file mode 100644 index 0000000000..39efffc2b6 --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.go @@ -0,0 +1,133 @@ +package tco + +import ( + "context" + + "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 DataSourceTencentCloudOrganizationOrgShareUnitMembers() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudOrganizationOrgShareUnitMembersRead, + Schema: map[string]*schema.Schema{ + "unit_id": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit ID.", + }, + + "area": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit area.", + }, + + "search_key": { + Type: schema.TypeString, + Optional: true, + Description: "Search for keywords. Support member Uin searches.", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Shared unit member list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "share_member_uin": { + Type: schema.TypeInt, + Required: true, + Description: "Shared member Uin.", + }, + "create_time": { + Type: schema.TypeString, + Required: true, + Description: "Creation time.", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudOrganizationOrgShareUnitMembersRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_organization_org_share_unit_members.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("unit_id"); ok { + paramMap["UnitId"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("area"); ok { + paramMap["Area"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("search_key"); ok { + paramMap["SearchKey"] = helper.String(v.(string)) + } + + var respData []*organization.ShareUnitMember + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeOrganizationOrgShareUnitMembersByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + respData = result + return nil + }) + if err != nil { + return err + } + + var ids []string + itemsList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, items := range respData { + itemsMap := map[string]interface{}{} + + var shareMemberUin int64 + if items.ShareMemberUin != nil { + itemsMap["share_member_uin"] = items.ShareMemberUin + shareMemberUin = *items.ShareMemberUin + } + + if items.CreateTime != nil { + itemsMap["create_time"] = items.CreateTime + } + + ids = append(ids, helper.Int64ToStr(shareMemberUin)) + itemsList = append(itemsList, itemsMap) + } + + _ = d.Set("items", itemsList) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), itemsList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.md b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.md new file mode 100644 index 0000000000..96cf2490cc --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.md @@ -0,0 +1,11 @@ +Use this data source to query detailed information of organization organization_org_share_unit_members + +Example Usage + +```hcl +data "tencentcloud_organization_org_share_unit_members" "organization_org_share_unit_members" { + unit_id = "xxxxxx" + area = "ap-guangzhou" + search_key = "xxxxxx" +} +``` diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members_test.go b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members_test.go new file mode 100644 index 0000000000..c8d2265441 --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members_test.go @@ -0,0 +1,51 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudOrganizationOrgShareUnitMembersDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOrganizationOrgShareUnitMembersDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_organization_org_share_unit_members.organization_org_share_unit_members"), + resource.TestCheckResourceAttr("data.tencentcloud_organization_org_share_unit_members.organization_org_share_unit_members", "items.#", "1"), + ), + }, + }, + }) +} + +const testAccOrganizationOrgShareUnitMembersDataSource = ` +resource "tencentcloud_organization_org_share_unit" "org_share_unit" { + name = "iac-test" + area = "ap-guangzhou" + description = "iac-test" +} + +resource "tencentcloud_organization_org_share_unit_member" "org_share_unit_member" { + unit_id = tencentcloud_organization_org_share_unit.org_share_unit.unit_id + area = tencentcloud_organization_org_share_unit.org_share_unit.area + members { + share_member_uin=100038074517 + } +} + +data "tencentcloud_organization_org_share_unit_members" "organization_org_share_unit_members" { + unit_id = split("#", tencentcloud_organization_org_share_unit.org_share_unit.id)[1] + area = "ap-guangzhou" + search_key = "100038074517" + depends_on = [ tencentcloud_organization_org_share_unit_member.org_share_unit_member ] +} +` diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.go b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.go new file mode 100644 index 0000000000..22df2db50a --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.go @@ -0,0 +1,188 @@ +package tco + +import ( + "context" + + "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 DataSourceTencentCloudOrganizationOrgShareUnitResources() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudOrganizationOrgShareUnitResourcesRead, + Schema: map[string]*schema.Schema{ + "unit_id": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit ID.", + }, + + "area": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit area.", + }, + + "search_key": { + Type: schema.TypeString, + Optional: true, + Description: "Search for keywords. Support product resource ID search.", + }, + + "type": { + Type: schema.TypeString, + Optional: true, + Description: "Shared resource type.", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Shared unit resource list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "resource_id": { + Type: schema.TypeString, + Required: true, + Description: "Shared resource ID.", + }, + "type": { + Type: schema.TypeString, + Required: true, + Description: "Shared resource type.", + }, + "create_time": { + Type: schema.TypeString, + Required: true, + Description: "Creation time.", + }, + "product_resource_id": { + Type: schema.TypeString, + Required: true, + Description: "Product resource ID.", + }, + "shared_member_num": { + Type: schema.TypeInt, + Required: true, + Description: "Number of shared unit members.", + }, + "shared_member_use_num": { + Type: schema.TypeInt, + Required: true, + Description: "Number of shared unit members in use.", + }, + "share_manager_uin": { + Type: schema.TypeInt, + Required: true, + Description: "Sharing administrator OwnerUin.", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudOrganizationOrgShareUnitResourcesRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_organization_org_share_unit_resources.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("unit_id"); ok { + paramMap["UnitId"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("area"); ok { + paramMap["Area"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("search_key"); ok { + paramMap["SearchKey"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("type"); ok { + paramMap["Type"] = helper.String(v.(string)) + } + + var respData []*organization.ShareUnitResource + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeOrganizationOrgShareUnitResourcesByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + respData = result + return nil + }) + if err != nil { + return err + } + + var ids []string + itemsList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, items := range respData { + itemsMap := map[string]interface{}{} + + var resourceId string + if items.ResourceId != nil { + itemsMap["resource_id"] = items.ResourceId + resourceId = *items.ResourceId + } + + if items.Type != nil { + itemsMap["type"] = items.Type + } + + if items.CreateTime != nil { + itemsMap["create_time"] = items.CreateTime + } + + if items.ProductResourceId != nil { + itemsMap["product_resource_id"] = items.ProductResourceId + } + + if items.SharedMemberNum != nil { + itemsMap["shared_member_num"] = items.SharedMemberNum + } + + if items.SharedMemberUseNum != nil { + itemsMap["shared_member_use_num"] = items.SharedMemberUseNum + } + + if items.ShareManagerUin != nil { + itemsMap["share_manager_uin"] = items.ShareManagerUin + } + + ids = append(ids, resourceId) + itemsList = append(itemsList, itemsMap) + } + + _ = d.Set("items", itemsList) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), itemsList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.md b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.md new file mode 100644 index 0000000000..cf340a4c37 --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources.md @@ -0,0 +1,10 @@ +Use this data source to query detailed information of organization organization_org_share_unit_resources + +Example Usage + +```hcl +data "tencentcloud_organization_org_share_unit_resources" "organization_org_share_unit_resources" { + area = "ap-guangzhou" + unit_id = "xxxxxx" +} +``` diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources_test.go b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources_test.go new file mode 100644 index 0000000000..8ef252cfd2 --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_unit_resources_test.go @@ -0,0 +1,49 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudOrganizationOrgShareUnitResourcesDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOrganizationOrgShareUnitResourcesDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_organization_org_share_unit_resources.organization_org_share_unit_resources"), + resource.TestCheckResourceAttr("data.tencentcloud_organization_org_share_unit_resources.organization_org_share_unit_resources", "items.#", "1"), + ), + }, + }, + }) +} + +const testAccOrganizationOrgShareUnitResourcesDataSource = ` +resource "tencentcloud_organization_org_share_unit" "org_share_unit" { + name = "iac-test" + area = "ap-guangzhou" + description = "iac-test" +} + +resource "tencentcloud_organization_org_share_unit_resource" "organization_org_share_unit_resource" { + unit_id = split("#", tencentcloud_organization_org_share_unit.org_share_unit.id)[1] + area = "ap-guangzhou" + type = "secret" + product_resource_id = "100027395662/keep-tf" +} + +data "tencentcloud_organization_org_share_unit_resources" "organization_org_share_unit_resources" { + area = "ap-guangzhou" + unit_id = split("#", tencentcloud_organization_org_share_unit.org_share_unit.id)[1] + depends_on = [ tencentcloud_organization_org_share_unit_resource.organization_org_share_unit_resource ] +} +` diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_units.go b/tencentcloud/services/tco/data_source_tc_organization_org_share_units.go new file mode 100644 index 0000000000..49f42b708c --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_units.go @@ -0,0 +1,195 @@ +package tco + +import ( + "context" + + "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 DataSourceTencentCloudOrganizationOrgShareUnits() *schema.Resource { + return &schema.Resource{ + Read: dataSourceTencentCloudOrganizationOrgShareUnitsRead, + Schema: map[string]*schema.Schema{ + "area": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit area.", + }, + + "search_key": { + Type: schema.TypeString, + Optional: true, + Description: "Search for keywords. Support UnitId and Name searches.", + }, + + "items": { + Type: schema.TypeList, + Computed: true, + Description: "Shared unit list.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "unit_id": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit ID.", + }, + "name": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit name.", + }, + "uin": { + Type: schema.TypeInt, + Required: true, + Description: "Shared unit manager Uin.", + }, + "owner_uin": { + Type: schema.TypeInt, + Required: true, + Description: "Shared unit manager OwnerUin.", + }, + "area": { + Type: schema.TypeString, + Required: true, + Description: "Shared unit area.", + }, + "description": { + Type: schema.TypeString, + Required: true, + Description: "description.", + }, + "create_time": { + Type: schema.TypeString, + Required: true, + Description: "Create time.", + }, + "share_resource_num": { + Type: schema.TypeInt, + Required: true, + Description: "Number of shared unit resources.", + }, + "share_member_num": { + Type: schema.TypeInt, + Required: true, + Description: "Number of shared unit members.", + }, + "share_scope": { + Type: schema.TypeInt, + Required: true, + Description: "Shared scope. Value: 1-Only allowed to share within the group organization 2-allowed to share to any account.", + }, + }, + }, + }, + + "result_output_file": { + Type: schema.TypeString, + Optional: true, + Description: "Used to save results.", + }, + }, + } +} + +func dataSourceTencentCloudOrganizationOrgShareUnitsRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("data_source.tencentcloud_organization_org_share_units.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("area"); ok { + paramMap["Area"] = helper.String(v.(string)) + } + + if v, ok := d.GetOk("search_key"); ok { + paramMap["SearchKey"] = helper.String(v.(string)) + } + + var respData []*organization.ManagerShareUnit + err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { + result, e := service.DescribeOrganizationOrgShareUnitsByFilter(ctx, paramMap) + if e != nil { + return tccommon.RetryError(e) + } + respData = result + return nil + }) + if err != nil { + return err + } + + var ids []string + itemsList := make([]map[string]interface{}, 0, len(respData)) + if respData != nil { + for _, items := range respData { + itemsMap := map[string]interface{}{} + + var unitId string + if items.UnitId != nil { + itemsMap["unit_id"] = items.UnitId + unitId = *items.UnitId + } + + if items.Name != nil { + itemsMap["name"] = items.Name + } + + if items.Uin != nil { + itemsMap["uin"] = items.Uin + } + + if items.OwnerUin != nil { + itemsMap["owner_uin"] = items.OwnerUin + } + + if items.Area != nil { + itemsMap["area"] = items.Area + } + + if items.Description != nil { + itemsMap["description"] = items.Description + } + + if items.CreateTime != nil { + itemsMap["create_time"] = items.CreateTime + } + + if items.ShareResourceNum != nil { + itemsMap["share_resource_num"] = items.ShareResourceNum + } + + if items.ShareMemberNum != nil { + itemsMap["share_member_num"] = items.ShareMemberNum + } + + if items.ShareScope != nil { + itemsMap["share_scope"] = items.ShareScope + } + + ids = append(ids, unitId) + itemsList = append(itemsList, itemsMap) + } + + _ = d.Set("items", itemsList) + } + + d.SetId(helper.DataResourceIdsHash(ids)) + + output, ok := d.GetOk("result_output_file") + if ok && output.(string) != "" { + if e := tccommon.WriteToFile(output.(string), itemsList); e != nil { + return e + } + } + + return nil +} diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_units.md b/tencentcloud/services/tco/data_source_tc_organization_org_share_units.md new file mode 100644 index 0000000000..2564313645 --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_units.md @@ -0,0 +1,10 @@ +Use this data source to query detailed information of organization organization_org_share_units + +Example Usage + +```hcl +data "tencentcloud_organization_org_share_units" "organization_org_share_units" { + area = "ap-guangzhou" + search_key = "xxxxxx" +} +``` diff --git a/tencentcloud/services/tco/data_source_tc_organization_org_share_units_test.go b/tencentcloud/services/tco/data_source_tc_organization_org_share_units_test.go new file mode 100644 index 0000000000..73370aaac1 --- /dev/null +++ b/tencentcloud/services/tco/data_source_tc_organization_org_share_units_test.go @@ -0,0 +1,41 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudOrganizationOrgShareUnitsDataSource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOrganizationOrgShareUnitsDataSource, + Check: resource.ComposeTestCheckFunc( + tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_organization_org_share_units.organization_org_share_units"), + resource.TestCheckResourceAttr("data.tencentcloud_organization_org_share_units.organization_org_share_units", "items.#", "1"), + ), + }, + }, + }) +} + +const testAccOrganizationOrgShareUnitsDataSource = ` +resource "tencentcloud_organization_org_share_unit" "org_share_unit" { + name = "iac-test-1" + area = "ap-guangzhou" + description = "iac-test" +} + +data "tencentcloud_organization_org_share_units" "organization_org_share_units" { + area = "ap-guangzhou" + search_key = split("#", tencentcloud_organization_org_share_unit.org_share_unit.id)[1] +} +` diff --git a/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.go b/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.go new file mode 100644 index 0000000000..46d4ea2e45 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.go @@ -0,0 +1,85 @@ +package tco + +import ( + "context" + "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 ResourceTencentCloudAcceptJoinShareUnitInvitationOperation() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudAcceptJoinShareUnitInvitationOperationCreate, + Read: resourceTencentCloudAcceptJoinShareUnitInvitationOperationRead, + Delete: resourceTencentCloudAcceptJoinShareUnitInvitationOperationDelete, + Schema: map[string]*schema.Schema{ + "unit_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Shared unit ID.", + }, + }, + } +} + +func resourceTencentCloudAcceptJoinShareUnitInvitationOperationCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_accept_join_share_unit_invitation_operation.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + var ( + unitId string + ) + var ( + request = organization.NewAcceptJoinShareUnitInvitationRequest() + response = organization.NewAcceptJoinShareUnitInvitationResponse() + ) + + if v, ok := d.GetOk("unit_id"); ok { + request.UnitId = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().AcceptJoinShareUnitInvitationWithContext(ctx, 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 create accept join share unit invitation operation failed, reason:%+v", logId, err) + return err + } + + _ = response + + d.SetId(unitId) + + return resourceTencentCloudAcceptJoinShareUnitInvitationOperationRead(d, meta) +} + +func resourceTencentCloudAcceptJoinShareUnitInvitationOperationRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_accept_join_share_unit_invitation_operation.read")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudAcceptJoinShareUnitInvitationOperationDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_accept_join_share_unit_invitation_operation.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.md b/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.md new file mode 100644 index 0000000000..4cce935584 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation.md @@ -0,0 +1,9 @@ +Provides a resource to create a organization accept_join_share_unit_invitation_operation + +Example Usage + +```hcl +resource "tencentcloud_accept_join_share_unit_invitation_operation" "accept_join_share_unit_invitation_operation" { + unit_id = "xxxxxx" +} +``` diff --git a/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation_test.go b/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation_test.go new file mode 100644 index 0000000000..7c26c3ab3e --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_accept_join_share_unit_invitation_operation_test.go @@ -0,0 +1,43 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudAcceptJoinShareUnitInvitationOperationResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccAcceptJoinShareUnitInvitationOperation, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_accept_join_share_unit_invitation_operation.accept_join_share_unit_invitation_operation", "id"), + ), + }, + { + ResourceName: "tencentcloud_accept_join_share_unit_invitation_operation.accept_join_share_unit_invitation_operation", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccAcceptJoinShareUnitInvitationOperation = ` +resource "tencentcloud_organization_org_share_unit" "org_share_unit" { + name = "iac-test-1" + area = "ap-guangzhou" + description = "iac-test" +} +resource "tencentcloud_accept_join_share_unit_invitation_operation" "accept_join_share_unit_invitation_operation" { + unit_id = split("#", tencentcloud_organization_org_share_unit.org_share_unit.id)[1] +} +` diff --git a/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.go b/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.go new file mode 100644 index 0000000000..0683c90480 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.go @@ -0,0 +1,263 @@ +package tco + +import ( + "context" + "fmt" + "log" + "strings" + + "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 ResourceTencentCloudOrganizationOrgShareUnitResource() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudOrganizationOrgShareUnitResourceCreate, + Read: resourceTencentCloudOrganizationOrgShareUnitResourceRead, + Delete: resourceTencentCloudOrganizationOrgShareUnitResourceDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Schema: map[string]*schema.Schema{ + "unit_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Shared unit ID.", + }, + + "area": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Shared unit area.", + }, + + "type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Shared resource type.", + }, + + "product_resource_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Product Resource ID.", + }, + + "resource_id": { + Type: schema.TypeString, + Computed: true, + Description: "Shared resource ID.", + }, + + "create_time": { + Type: schema.TypeString, + Computed: true, + Description: "Create time.", + }, + + "shared_member_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of shared unit members.", + }, + + "shared_member_use_num": { + Type: schema.TypeInt, + Computed: true, + Description: "Number of shared unit members in use.", + }, + + "share_manager_uin": { + Type: schema.TypeInt, + Computed: true, + Description: "Sharing administrator OwnerUin.", + }, + }, + } +} + +func resourceTencentCloudOrganizationOrgShareUnitResourceCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_organization_org_share_unit_resource.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + var ( + unitId string + area string + shareResourceType string + productResourceId string + ) + var ( + request = organization.NewAddShareUnitResourcesRequest() + response = organization.NewAddShareUnitResourcesResponse() + ) + + if v, ok := d.GetOk("unit_id"); ok { + unitId = v.(string) + request.UnitId = helper.String(unitId) + } + + if v, ok := d.GetOk("area"); ok { + area = v.(string) + request.Area = helper.String(area) + } + + if v, ok := d.GetOk("type"); ok { + shareResourceType = v.(string) + request.Type = helper.String(shareResourceType) + } + + productResource := organization.ProductResource{} + if v, ok := d.GetOk("product_resource_id"); ok { + productResourceId = v.(string) + productResource.ProductResourceId = helper.String(productResourceId) + } + request.Resources = []*organization.ProductResource{&productResource} + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().AddShareUnitResourcesWithContext(ctx, 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 create organization org share unit resource failed, reason:%+v", logId, err) + return err + } + + _ = response + + d.SetId(strings.Join([]string{unitId, area, shareResourceType, productResourceId}, tccommon.FILED_SP)) + + return resourceTencentCloudOrganizationOrgShareUnitResourceRead(d, meta) +} + +func resourceTencentCloudOrganizationOrgShareUnitResourceRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_organization_org_share_unit_resource.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()} + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 4 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + unitId := idSplit[0] + area := idSplit[1] + shareResourceType := idSplit[2] + productResourceId := idSplit[3] + + _ = d.Set("unit_id", unitId) + _ = d.Set("area", area) + _ = d.Set("type", shareResourceType) + _ = d.Set("product_resource_id", productResourceId) + + respData, err := service.DescribeOrganizationOrgShareUnitResourceById(ctx, unitId, area, shareResourceType, productResourceId) + if err != nil { + return err + } + + if respData == nil { + d.SetId("") + log.Printf("[WARN]%s resource `organization_org_share_unit_resource` [%s] not found, please check if it has been deleted.\n", logId, d.Id()) + return nil + } + if respData.ResourceId != nil { + _ = d.Set("resource_id", respData.ResourceId) + } + + if respData.Type != nil { + _ = d.Set("type", respData.Type) + } + + if respData.CreateTime != nil { + _ = d.Set("create_time", respData.CreateTime) + } + + if respData.ProductResourceId != nil { + _ = d.Set("product_resource_id", respData.ProductResourceId) + } + + if respData.SharedMemberNum != nil { + _ = d.Set("shared_member_num", respData.SharedMemberNum) + } + + if respData.SharedMemberUseNum != nil { + _ = d.Set("shared_member_use_num", respData.SharedMemberUseNum) + } + + if respData.ShareManagerUin != nil { + _ = d.Set("share_manager_uin", respData.ShareManagerUin) + } + + return nil +} + +func resourceTencentCloudOrganizationOrgShareUnitResourceDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_organization_org_share_unit_resource.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + idSplit := strings.Split(d.Id(), tccommon.FILED_SP) + if len(idSplit) != 4 { + return fmt.Errorf("id is broken,%s", d.Id()) + } + unitId := idSplit[0] + area := idSplit[1] + shareResourceType := idSplit[2] + productResourceId := idSplit[3] + + var ( + request = organization.NewDeleteShareUnitResourcesRequest() + response = organization.NewDeleteShareUnitResourcesResponse() + ) + + request.UnitId = helper.String(unitId) + + request.Area = helper.String(area) + + request.Type = helper.String(shareResourceType) + + shareResource := organization.ShareResource{} + shareResource.ProductResourceId = helper.String(productResourceId) + request.Resources = []*organization.ShareResource{&shareResource} + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().DeleteShareUnitResourcesWithContext(ctx, 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 delete organization org share unit resource failed, reason:%+v", logId, err) + return err + } + + _ = response + return nil +} diff --git a/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.md b/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.md new file mode 100644 index 0000000000..4683300890 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource.md @@ -0,0 +1,20 @@ +Provides a resource to create a organization organization_org_share_unit_resource + +Example Usage + +```hcl +resource "tencentcloud_organization_org_share_unit_resource" "organization_org_share_unit_resource" { + unit_id = "xxxxxx" + area = "ap-guangzhou" + type = "secret" + product_resource_id = "xxxxxx" +} +``` + +Import + +organization organization_org_share_unit_resource can be imported using the id, e.g. + +``` +terraform import tencentcloud_organization_org_share_unit_resource.organization_org_share_unit_resource ${unit_id}#${area}#${share_resource_type}#${product_resource_id} +``` diff --git a/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource_test.go b/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource_test.go new file mode 100644 index 0000000000..f5d00568a3 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_organization_org_share_unit_resource_test.go @@ -0,0 +1,47 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudOrganizationOrgShareUnitResourceResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{ + { + Config: testAccOrganizationOrgShareUnitResource, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("tencentcloud_organization_org_share_unit_resource.organization_org_share_unit_resource", "id"), + ), + }, + { + ResourceName: "tencentcloud_organization_org_share_unit_resource.organization_org_share_unit_resource", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccOrganizationOrgShareUnitResource = ` +resource "tencentcloud_organization_org_share_unit" "org_share_unit" { + name = "iac-test" + area = "ap-guangzhou" + description = "iac-test" +} + +resource "tencentcloud_organization_org_share_unit_resource" "organization_org_share_unit_resource" { + unit_id = split("#", tencentcloud_organization_org_share_unit.org_share_unit.id)[1] + area = "ap-guangzhou" + type = "secret" + product_resource_id = "100027395662/keep-tf" +} +` diff --git a/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.go b/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.go new file mode 100644 index 0000000000..eec2a8b4f2 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.go @@ -0,0 +1,85 @@ +package tco + +import ( + "context" + "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 ResourceTencentCloudRejectJoinShareUnitInvitationOperation() *schema.Resource { + return &schema.Resource{ + Create: resourceTencentCloudRejectJoinShareUnitInvitationOperationCreate, + Read: resourceTencentCloudRejectJoinShareUnitInvitationOperationRead, + Delete: resourceTencentCloudRejectJoinShareUnitInvitationOperationDelete, + Schema: map[string]*schema.Schema{ + "unit_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Shared unit ID.", + }, + }, + } +} + +func resourceTencentCloudRejectJoinShareUnitInvitationOperationCreate(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_reject_join_share_unit_invitation_operation.create")() + defer tccommon.InconsistentCheck(d, meta)() + + logId := tccommon.GetLogId(tccommon.ContextNil) + + ctx := tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta) + + var ( + unitId string + ) + var ( + request = organization.NewRejectJoinShareUnitInvitationRequest() + response = organization.NewRejectJoinShareUnitInvitationResponse() + ) + + if v, ok := d.GetOk("unit_id"); ok { + request.UnitId = helper.String(v.(string)) + } + + err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { + result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().RejectJoinShareUnitInvitationWithContext(ctx, 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 create reject join share unit invitation operation failed, reason:%+v", logId, err) + return err + } + + _ = response + + d.SetId(unitId) + + return resourceTencentCloudRejectJoinShareUnitInvitationOperationRead(d, meta) +} + +func resourceTencentCloudRejectJoinShareUnitInvitationOperationRead(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_reject_join_share_unit_invitation_operation.read")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} + +func resourceTencentCloudRejectJoinShareUnitInvitationOperationDelete(d *schema.ResourceData, meta interface{}) error { + defer tccommon.LogElapsed("resource.tencentcloud_reject_join_share_unit_invitation_operation.delete")() + defer tccommon.InconsistentCheck(d, meta)() + + return nil +} diff --git a/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.md b/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.md new file mode 100644 index 0000000000..ca38865c61 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation.md @@ -0,0 +1,9 @@ +Provides a resource to create a organization reject_join_share_unit_invitation_operation + +Example Usage + +```hcl +resource "tencentcloud_reject_join_share_unit_invitation_operation" "reject_join_share_unit_invitation_operation" { + unit_id = "xxxxxx" +} +``` diff --git a/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation_test.go b/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation_test.go new file mode 100644 index 0000000000..2de86f8790 --- /dev/null +++ b/tencentcloud/services/tco/resource_tc_reject_join_share_unit_invitation_operation_test.go @@ -0,0 +1,38 @@ +package tco_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" +) + +func TestAccTencentCloudRejectJoinShareUnitInvitationOperationResource_basic(t *testing.T) { + t.Parallel() + resource.Test(t, resource.TestCase{ + PreCheck: func() { + tcacctest.AccPreCheck(t) + }, + Providers: tcacctest.AccProviders, + Steps: []resource.TestStep{{ + Config: testAccRejectJoinShareUnitInvitationOperation, + Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_reject_join_share_unit_invitation_operation.reject_join_share_unit_invitation_operation", "id")), + }, { + ResourceName: "tencentcloud_reject_join_share_unit_invitation_operation.reject_join_share_unit_invitation_operation", + ImportState: true, + ImportStateVerify: true, + }}, + }) +} + +const testAccRejectJoinShareUnitInvitationOperation = ` +resource "tencentcloud_organization_org_share_unit" "org_share_unit" { + name = "iac-test-1" + area = "ap-guangzhou" + description = "iac-test" +} +resource "tencentcloud_reject_join_share_unit_invitation_operation" "reject_join_share_unit_invitation_operation" { + unit_id = split("#", tencentcloud_organization_org_share_unit.org_share_unit.id)[1] +} +` diff --git a/tencentcloud/services/tco/service_tencentcloud_organization.go b/tencentcloud/services/tco/service_tencentcloud_organization.go index f6dbf7902f..e7de41d9ff 100644 --- a/tencentcloud/services/tco/service_tencentcloud_organization.go +++ b/tencentcloud/services/tco/service_tencentcloud_organization.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common" "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" @@ -1979,3 +1980,217 @@ func (me *OrganizationService) DescribeIdentityCenterScimSynchronizationStatusBy ret = response.Response return } + +func (me *OrganizationService) DescribeOrganizationOrgShareUnitResourceById(ctx context.Context, unitId string, area string, shareResourceType string, productResourceId string) (ret *organization.ShareUnitResource, errRet error) { + logId := tccommon.GetLogId(ctx) + + request := organization.NewDescribeShareUnitResourcesRequest() + request.UnitId = helper.String(unitId) + request.Area = helper.String(area) + request.SearchKey = helper.String(productResourceId) + request.Type = helper.String(shareResourceType) + + 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()) + } + }() + + var ( + limit uint64 = 50 + offset uint64 = 0 + ) + request.Limit = &limit + request.Offset = &offset + + for { + ratelimit.Check(request.GetAction()) + + response, err := me.client.UseOrganizationClient().DescribeShareUnitResources(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 + } + + for _, item := range response.Response.Items { + if *item.ProductResourceId == productResourceId { + ret = item + return + } + } + if len(response.Response.Items) < int(limit) { + break + } + + offset += limit + + } + return +} + +func (me *OrganizationService) DescribeOrganizationOrgShareUnitResourcesByFilter(ctx context.Context, param map[string]interface{}) (ret []*organization.ShareUnitResource, errRet error) { + var ( + logId = common.GetLogId(ctx) + request = organization.NewDescribeShareUnitResourcesRequest() + ) + + 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 == "UnitId" { + request.UnitId = v.(*string) + } + if k == "Area" { + request.Area = v.(*string) + } + if k == "SearchKey" { + request.SearchKey = v.(*string) + } + if k == "Type" { + request.Type = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + var ( + offset uint64 = 0 + limit uint64 = 50 + ) + for { + request.Offset = &offset + request.Limit = &limit + response, err := me.client.UseOrganizationClient().DescribeShareUnitResources(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 || len(response.Response.Items) < 1 { + break + } + ret = append(ret, response.Response.Items...) + if len(response.Response.Items) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *OrganizationService) DescribeOrganizationOrgShareUnitsByFilter(ctx context.Context, param map[string]interface{}) (ret []*organization.ManagerShareUnit, errRet error) { + var ( + logId = common.GetLogId(ctx) + request = organization.NewDescribeShareUnitsRequest() + ) + + 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 == "Area" { + request.Area = v.(*string) + } + if k == "SearchKey" { + request.SearchKey = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + var ( + offset uint64 = 0 + limit uint64 = 100 + ) + for { + request.Offset = &offset + request.Limit = &limit + response, err := me.client.UseOrganizationClient().DescribeShareUnits(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 || len(response.Response.Items) < 1 { + break + } + ret = append(ret, response.Response.Items...) + if len(response.Response.Items) < int(limit) { + break + } + + offset += limit + } + + return +} + +func (me *OrganizationService) DescribeOrganizationOrgShareUnitMembersByFilter(ctx context.Context, param map[string]interface{}) (ret []*organization.ShareUnitMember, errRet error) { + var ( + logId = common.GetLogId(ctx) + request = organization.NewDescribeShareUnitMembersRequest() + ) + + 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 == "UnitId" { + request.UnitId = v.(*string) + } + if k == "Area" { + request.Area = v.(*string) + } + if k == "SearchKey" { + request.SearchKey = v.(*string) + } + } + + ratelimit.Check(request.GetAction()) + + var ( + offset uint64 = 0 + limit uint64 = 50 + ) + for { + request.Offset = &offset + request.Limit = &limit + response, err := me.client.UseOrganizationClient().DescribeShareUnitMembers(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 || len(response.Response.Items) < 1 { + break + } + ret = append(ret, response.Response.Items...) + if len(response.Response.Items) < int(limit) { + break + } + + offset += limit + } + + return +} diff --git a/website/docs/d/organization_org_share_unit_members.html.markdown b/website/docs/d/organization_org_share_unit_members.html.markdown new file mode 100644 index 0000000000..9cb1ab4a01 --- /dev/null +++ b/website/docs/d/organization_org_share_unit_members.html.markdown @@ -0,0 +1,39 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_organization_org_share_unit_members" +sidebar_current: "docs-tencentcloud-datasource-organization_org_share_unit_members" +description: |- + Use this data source to query detailed information of organization organization_org_share_unit_members +--- + +# tencentcloud_organization_org_share_unit_members + +Use this data source to query detailed information of organization organization_org_share_unit_members + +## Example Usage + +```hcl +data "tencentcloud_organization_org_share_unit_members" "organization_org_share_unit_members" { + unit_id = "xxxxxx" + area = "ap-guangzhou" + search_key = "xxxxxx" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `area` - (Required, String) Shared unit area. +* `unit_id` - (Required, String) Shared unit ID. +* `result_output_file` - (Optional, String) Used to save results. +* `search_key` - (Optional, String) Search for keywords. Support member Uin searches. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `items` - Shared unit member list. + + diff --git a/website/docs/d/organization_org_share_unit_resources.html.markdown b/website/docs/d/organization_org_share_unit_resources.html.markdown new file mode 100644 index 0000000000..7e5767dab5 --- /dev/null +++ b/website/docs/d/organization_org_share_unit_resources.html.markdown @@ -0,0 +1,39 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_organization_org_share_unit_resources" +sidebar_current: "docs-tencentcloud-datasource-organization_org_share_unit_resources" +description: |- + Use this data source to query detailed information of organization organization_org_share_unit_resources +--- + +# tencentcloud_organization_org_share_unit_resources + +Use this data source to query detailed information of organization organization_org_share_unit_resources + +## Example Usage + +```hcl +data "tencentcloud_organization_org_share_unit_resources" "organization_org_share_unit_resources" { + area = "ap-guangzhou" + unit_id = "xxxxxx" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `area` - (Required, String) Shared unit area. +* `unit_id` - (Required, String) Shared unit ID. +* `result_output_file` - (Optional, String) Used to save results. +* `search_key` - (Optional, String) Search for keywords. Support product resource ID search. +* `type` - (Optional, String) Shared resource type. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `items` - Shared unit resource list. + + diff --git a/website/docs/d/organization_org_share_units.html.markdown b/website/docs/d/organization_org_share_units.html.markdown new file mode 100644 index 0000000000..f51d452074 --- /dev/null +++ b/website/docs/d/organization_org_share_units.html.markdown @@ -0,0 +1,37 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_organization_org_share_units" +sidebar_current: "docs-tencentcloud-datasource-organization_org_share_units" +description: |- + Use this data source to query detailed information of organization organization_org_share_units +--- + +# tencentcloud_organization_org_share_units + +Use this data source to query detailed information of organization organization_org_share_units + +## Example Usage + +```hcl +data "tencentcloud_organization_org_share_units" "organization_org_share_units" { + area = "ap-guangzhou" + search_key = "xxxxxx" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `area` - (Required, String) Shared unit area. +* `result_output_file` - (Optional, String) Used to save results. +* `search_key` - (Optional, String) Search for keywords. Support UnitId and Name searches. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `items` - Shared unit list. + + diff --git a/website/docs/r/accept_join_share_unit_invitation_operation.html.markdown b/website/docs/r/accept_join_share_unit_invitation_operation.html.markdown new file mode 100644 index 0000000000..2c95f28150 --- /dev/null +++ b/website/docs/r/accept_join_share_unit_invitation_operation.html.markdown @@ -0,0 +1,35 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_accept_join_share_unit_invitation_operation" +sidebar_current: "docs-tencentcloud-resource-accept_join_share_unit_invitation_operation" +description: |- + Provides a resource to create a organization accept_join_share_unit_invitation_operation +--- + +# tencentcloud_accept_join_share_unit_invitation_operation + +Provides a resource to create a organization accept_join_share_unit_invitation_operation + +## Example Usage + +```hcl +resource "tencentcloud_accept_join_share_unit_invitation_operation" "accept_join_share_unit_invitation_operation" { + unit_id = "xxxxxx" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `unit_id` - (Required, String, ForceNew) Shared unit ID. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/docs/r/organization_org_share_unit_resource.html.markdown b/website/docs/r/organization_org_share_unit_resource.html.markdown new file mode 100644 index 0000000000..8d90b67935 --- /dev/null +++ b/website/docs/r/organization_org_share_unit_resource.html.markdown @@ -0,0 +1,53 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_organization_org_share_unit_resource" +sidebar_current: "docs-tencentcloud-resource-organization_org_share_unit_resource" +description: |- + Provides a resource to create a organization organization_org_share_unit_resource +--- + +# tencentcloud_organization_org_share_unit_resource + +Provides a resource to create a organization organization_org_share_unit_resource + +## Example Usage + +```hcl +resource "tencentcloud_organization_org_share_unit_resource" "organization_org_share_unit_resource" { + unit_id = "xxxxxx" + area = "ap-guangzhou" + type = "secret" + product_resource_id = "xxxxxx" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `area` - (Required, String, ForceNew) Shared unit area. +* `product_resource_id` - (Required, String, ForceNew) Product Resource ID. +* `type` - (Required, String, ForceNew) Shared resource type. +* `unit_id` - (Required, String, ForceNew) Shared unit ID. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. +* `create_time` - Create time. +* `resource_id` - Shared resource ID. +* `share_manager_uin` - Sharing administrator OwnerUin. +* `shared_member_num` - Number of shared unit members. +* `shared_member_use_num` - Number of shared unit members in use. + + +## Import + +organization organization_org_share_unit_resource can be imported using the id, e.g. + +``` +terraform import tencentcloud_organization_org_share_unit_resource.organization_org_share_unit_resource ${unit_id}#${area}#${share_resource_type}#${product_resource_id} +``` + diff --git a/website/docs/r/reject_join_share_unit_invitation_operation.html.markdown b/website/docs/r/reject_join_share_unit_invitation_operation.html.markdown new file mode 100644 index 0000000000..df7f9a8a7c --- /dev/null +++ b/website/docs/r/reject_join_share_unit_invitation_operation.html.markdown @@ -0,0 +1,35 @@ +--- +subcategory: "Tencent Cloud Organization (TCO)" +layout: "tencentcloud" +page_title: "TencentCloud: tencentcloud_reject_join_share_unit_invitation_operation" +sidebar_current: "docs-tencentcloud-resource-reject_join_share_unit_invitation_operation" +description: |- + Provides a resource to create a organization reject_join_share_unit_invitation_operation +--- + +# tencentcloud_reject_join_share_unit_invitation_operation + +Provides a resource to create a organization reject_join_share_unit_invitation_operation + +## Example Usage + +```hcl +resource "tencentcloud_reject_join_share_unit_invitation_operation" "reject_join_share_unit_invitation_operation" { + unit_id = "xxxxxx" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `unit_id` - (Required, String, ForceNew) Shared unit ID. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - ID of the resource. + + + diff --git a/website/tencentcloud.erb b/website/tencentcloud.erb index 34001dd1a8..2dce43a160 100644 --- a/website/tencentcloud.erb +++ b/website/tencentcloud.erb @@ -4483,6 +4483,15 @@
  • tencentcloud_organization_org_share_area
  • +
  • + tencentcloud_organization_org_share_unit_members +
  • +
  • + tencentcloud_organization_org_share_unit_resources +
  • +
  • + tencentcloud_organization_org_share_units +
  • tencentcloud_organization_services
  • @@ -4491,6 +4500,9 @@
  • Resources