-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tco): [121226730] support organization share (#3029)
* support organization share * add changelog --------- Co-authored-by: mikatong <[email protected]>
- Loading branch information
1 parent
39632b5
commit 0ae5bc7
Showing
29 changed files
with
1,793 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
11 changes: 11 additions & 0 deletions
11
tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
``` |
51 changes: 51 additions & 0 deletions
51
tencentcloud/services/tco/data_source_tc_organization_org_share_unit_members_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
} | ||
` |
Oops, something went wrong.