Skip to content

feat(tco): [119343954] add new resource tencentcloud_organization_service_assign, data source tencentcloud_organization_services #2792

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

Merged
merged 2 commits into from
Aug 30, 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
7 changes: 7 additions & 0 deletions .changelog/2792.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
tencentcloud_organization_service_assign
```

```release-note:new-data-source
tencentcloud_organization_services
```
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.984
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.970
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.984
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.991
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.960
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.762
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.692
Expand All @@ -69,7 +69,7 @@ require (
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mongodb v1.0.949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor v1.0.844
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/mps v1.0.853
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.910
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.991
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.873
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.859
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/pts v1.0.762
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.978 h1:3pid
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.978/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.984 h1:QLSx+ibsV68NXKgzofPuo1gxFwYSWk2++rvxZxNjbVo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.984/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.991 h1:0Xg2IUktDgGsjBv82WTmTQdHZFRwS2XDUnuOHexCxVw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.991/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860 h1:F3esKBIT3HW9+7Gt8cVgf8X06VdGIczpgLBUECzSEzU=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/csip v1.0.860/go.mod h1:NZo1WplQcC314kMlCRUoy8NQju2BnolIJj7NAWgsuhY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624 h1:nEZqsoqt1pEoaP9JjkHQy3/H00suCfzlHW1qOm2nYD8=
Expand Down Expand Up @@ -1048,6 +1050,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.856 h
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.856/go.mod h1:Ln9igPci1mCEe4gzekGpMMn/x9im6XlDh2bqvWnUMDo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.910 h1:KQJSiP2zV2VP4brIqSGGvx/3uoJ2Y3X5S5RsqjR77Ag=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.910/go.mod h1:9cT5rPLn6J+M5Gt5eS6NrgJnqsAcQjimu4JMS76UORQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.991 h1:udOXXxVAf2If4uvM6pot/K3iH67nUctaIqmt0QKarhM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/organization v1.0.991/go.mod h1:1QZV9ZlcmYEVz/kA5jj8jHDjQsEKbT13WJBywZzaX2U=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.873 h1:kqNFHpILFWPbOUAUrH1i6+IfkLWWEAZLYfj9RZ0WM+0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres v1.0.873/go.mod h1:Mjkr/911Pw0VopTfXt5zt46TnV3IrX01mvjZ66RsRRg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/privatedns v1.0.859 h1:VrE3qzwzWB5mV/ejTJuwZbqZ/CNYLoc8X+uFbWEEOnY=
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,7 @@ func Provider() *schema.Provider {
"tencentcloud_organization_org_financial_by_product": tco.DataSourceTencentCloudOrganizationOrgFinancialByProduct(),
"tencentcloud_organization_org_auth_node": tco.DataSourceTencentCloudOrganizationOrgAuthNode(),
"tencentcloud_organization_members": tco.DataSourceTencentCloudOrganizationMembers(),
"tencentcloud_organization_services": tco.DataSourceTencentCloudOrganizationServices(),
"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 @@ -1783,6 +1784,7 @@ func Provider() *schema.Provider {
"tencentcloud_organization_org_manage_policy_config": tco.ResourceTencentCloudOrganizationOrgManagePolicyConfig(),
"tencentcloud_organization_org_manage_policy": tco.ResourceTencentCloudOrganizationOrgManagePolicy(),
"tencentcloud_organization_org_manage_policy_target": tco.ResourceTencentCloudOrganizationOrgManagePolicyTarget(),
"tencentcloud_organization_service_assign": tco.ResourceTencentCloudOrganizationServiceAssign(),
"tencentcloud_dbbrain_sql_filter": dbbrain.ResourceTencentCloudDbbrainSqlFilter(),
"tencentcloud_dbbrain_security_audit_log_export_task": dbbrain.ResourceTencentCloudDbbrainSecurityAuditLogExportTask(),
"tencentcloud_dbbrain_db_diag_report_task": dbbrain.ResourceTencentCloudDbbrainDbDiagReportTask(),
Expand Down
2 changes: 2 additions & 0 deletions tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ Tencent Cloud Organization (TCO)
tencentcloud_organization_org_financial_by_month
tencentcloud_organization_org_financial_by_product
tencentcloud_organization_org_share_area
tencentcloud_organization_services
Resource
tencentcloud_organization_instance
tencentcloud_organization_org_node
Expand All @@ -1673,6 +1674,7 @@ Tencent Cloud Organization (TCO)
tencentcloud_organization_quit_organization_operation
tencentcloud_organization_org_share_unit
tencentcloud_organization_org_share_unit_member
tencentcloud_organization_service_assign

TDSQL-C for PostgreSQL(TDCPG)
Data Source
Expand Down
212 changes: 212 additions & 0 deletions tencentcloud/services/tco/data_source_tc_organization_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
package tco

import (
"context"
"strconv"

tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"

"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"

"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)

func DataSourceTencentCloudOrganizationServices() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudOrganizationServicesRead,
Schema: map[string]*schema.Schema{
"search_key": {
Optional: true,
Type: schema.TypeString,
Description: "Keyword for search by name.",
},
// computed
"items": {
Computed: true,
Type: schema.TypeList,
Description: "Organization service list.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Organization service ID. Note: This field may return null, indicating that no valid values can be obtained.",
},
"product_name": {
Type: schema.TypeString,
Computed: true,
Description: "Organization service product name. Note: This field may return null, indicating that no valid values can be obtained.",
},
"is_assign": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether to support delegation. Valid values: 1 (yes), 2 (no). Note: This field may return null, indicating that no valid values can be obtained.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Organization service description. Note: This field may return null, indicating that no valid values can be obtained.",
},
"member_num": {
Type: schema.TypeString,
Computed: true,
Description: "Number of the current delegated admins. Note: This field may return null, indicating that no valid values can be obtained.",
},
"document": {
Type: schema.TypeString,
Computed: true,
Description: "Help documentation. Note: This field may return null, indicating that no valid values can be obtained.",
},
"console_url": {
Type: schema.TypeString,
Computed: true,
Description: "Console path of the organization service product. Note: This field may return null, indicating that no valid values can be obtained.",
},
"is_usage_status": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether to access the usage status. Valid values: 1 (yes), 2 (no). Note: This field may return null, indicating that no valid values can be obtained.",
},
"can_assign_count": {
Type: schema.TypeInt,
Computed: true,
Description: "Limit for the number of delegated admins. Note: This field may return null, indicating that no valid values can be obtained.",
},
"product": {
Type: schema.TypeString,
Computed: true,
Description: "Organization service product identifier. Note: This field may return null, indicating that no valid values can be obtained.",
},
"service_grant": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether to support organization service authorization. Valid values: 1 (yes), 2 (no). Note: This field may return null, indicating that no valid values can be obtained.",
},
"grant_status": {
Type: schema.TypeString,
Computed: true,
Description: "Enabling status of organization service authorization. This field is valid when ServiceGrant is 1. Valid values: Enabled, Disabled. Note: This field may return null, indicating that no valid values can be obtained.",
},
"is_set_management_scope": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether to support setting the delegated management scope. Valid values: 1 (yes), 2 (no).\nNote: This field may return null, indicating that no valid values can be obtained.",
},
},
},
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

func dataSourceTencentCloudOrganizationServicesRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_organization_services.read")()
defer tccommon.InconsistentCheck(d, meta)()

var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = OrganizationService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
items []*organization.OrganizationServiceAssign
)

paramMap := make(map[string]interface{})

if v, ok := d.GetOk("search_key"); ok {
paramMap["SearchKey"] = helper.String(v.(string))
}

err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeOrganizationServicesByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}

items = result
return nil
})

if err != nil {
return err
}

ids := make([]string, 0, len(items))
tmpList := make([]map[string]interface{}, 0, len(items))

if items != nil {
for _, item := range items {
orgServiceAssignMap := map[string]interface{}{}

if item.ServiceId != nil {
orgServiceAssignMap["service_id"] = item.ServiceId
serviceIdStr := strconv.FormatUint(*item.ServiceId, 10)
ids = append(ids, serviceIdStr)
}

if item.ProductName != nil {
orgServiceAssignMap["product_name"] = item.ProductName
}

if item.IsAssign != nil {
orgServiceAssignMap["is_assign"] = item.IsAssign
}

if item.Description != nil {
orgServiceAssignMap["description"] = item.Description
}

if item.MemberNum != nil {
orgServiceAssignMap["member_num"] = item.MemberNum
}

if item.ConsoleUrl != nil {
orgServiceAssignMap["console_url"] = item.ConsoleUrl
}

if item.IsUsageStatus != nil {
orgServiceAssignMap["is_usage_status"] = item.IsUsageStatus
}

if item.CanAssignCount != nil {
orgServiceAssignMap["can_assign_count"] = item.CanAssignCount
}

if item.Product != nil {
orgServiceAssignMap["product"] = item.Product
}

if item.ServiceGrant != nil {
orgServiceAssignMap["service_grant"] = item.ServiceGrant
}

if item.GrantStatus != nil {
orgServiceAssignMap["grant_status"] = item.GrantStatus
}

if item.IsSetManagementScope != nil {
orgServiceAssignMap["is_set_management_scope"] = item.IsSetManagementScope
}

tmpList = append(tmpList, orgServiceAssignMap)
}

_ = d.Set("items", tmpList)
}

d.SetId(helper.DataResourceIdsHash(ids))
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), tmpList); e != nil {
return e
}
}

return nil
}
17 changes: 17 additions & 0 deletions tencentcloud/services/tco/data_source_tc_organization_services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Use this data source to query detailed information of organization services

Example Usage

Query all organization services

```hcl
data "tencentcloud_organization_services" "services" {}
```

Query organization services by filter

```hcl
data "tencentcloud_organization_services" "services" {
search_key = "KeyWord"
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package tco_test

import (
"testing"

tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// go test -i; go test -test.run TestAccTencentCloudOrganizationServicesDataSource_basic -v
func TestAccTencentCloudOrganizationServicesDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{
{
Config: testAccOrganizationServices,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_organization_services.services"),
),
},
},
})
}

const testAccOrganizationServices = `
data "tencentcloud_organization_services" "services" {}
`
Loading
Loading