Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tco): [121226730] support organization share #3029

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .changelog/3029.txt
Original file line number Diff line number Diff line change
@@ -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
```
6 changes: 6 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,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(),
Expand Down Expand Up @@ -2178,6 +2181,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(),
Expand Down
6 changes: 6 additions & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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"
}
```
Original file line number Diff line number Diff line change
@@ -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 ]
}
`
Loading
Loading