Skip to content
Open
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ require (

require (
github.com/hashicorp/go-uuid v1.0.3
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bh v1.3.7
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.31
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdc v1.0.1149
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdwdoris v1.0.993
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.2.2 h1:/BlN5LD/r
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm v1.2.2/go.mod h1:XIggn8QQknIzb+1lnsOiKbTQ0fjRe1uV6P+1N0L2ccI=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.3.4 h1:hTOxj4qB+UX6MflqmIYT4cPbfEqtiJEfi9tR58DxkIw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.3.4/go.mod h1:q7fZk23gy6BkZGcNw9NXFSj26R44tiJZKGxLFfOrMo0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bh v1.3.7 h1:EmqV7a3kxOzI+oPR9o8npRupCGfzgRRgIfF7KHAa1cs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bh v1.3.7/go.mod h1:jOm6mEGQbEzxX8hkRSoBfZRvCRqHtUG2jQ0gmyT8w68=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824 h1:DVKvZ6h+qd7tadUrCjVAkCCmE3TsbK2ZmwGd3AJcpWc=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi v1.0.824/go.mod h1:DvBpDX/qdJG4KKLeULmRvhAjPYiw8za0HeTSu2y/lFw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing v1.1.31 h1:teA14cAcXuGxas6+5YANQ5KCoPaQBKIb2Q8+sk08Mu0=
Expand Down
15 changes: 15 additions & 0 deletions tencentcloud/connectivity/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
apigateway "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway/v20180808"
apm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apm/v20210622"
as "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as/v20180419"
bhv20230418 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bh/v20230418"
bi "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bi/v20220105"
billing "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/billing/v20180709"
cam "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam/v20190116"
Expand Down Expand Up @@ -243,6 +244,7 @@ type TencentCloudClient struct {
gwlbv20240906Conn *gwlb.Client
billingv20180709Conn *billing.Client
igtmv20231024Conn *igtmv20231024.Client
bhv20230418Conn *bhv20230418.Client
}

// NewClientProfile returns a new ClientProfile
Expand Down Expand Up @@ -1709,6 +1711,19 @@ func (me *TencentCloudClient) UseDasbClient() *dasb.Client {
return me.dasbConn
}

// UseBhV20230418Client return BH client for service
func (me *TencentCloudClient) UseBhV20230418Client() *bhv20230418.Client {
if me.bhv20230418Conn != nil {
return me.bhv20230418Conn
}

cpf := me.NewClientProfile(300)
me.bhv20230418Conn, _ = bhv20230418.NewClient(me.Credential, me.Region, cpf)
me.bhv20230418Conn.WithHttpTransport(&LogRoundTripper{})

return me.bhv20230418Conn
}

// UseTrocketClient returns trocket client for service
func (me *TencentCloudClient) UseTrocketClient() *trocket.Client {
if me.trocketConn != nil {
Expand Down
13 changes: 13 additions & 0 deletions tencentcloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,8 @@ func Provider() *schema.Provider {
"tencentcloud_cfw_nat_fw_switches": cfw.DataSourceTencentCloudCfwNatFwSwitches(),
"tencentcloud_cfw_vpc_fw_switches": cfw.DataSourceTencentCloudCfwVpcFwSwitches(),
"tencentcloud_cfw_edge_fw_switches": cfw.DataSourceTencentCloudCfwEdgeFwSwitches(),
"tencentcloud_bh_account_groups": bh.DataSourceTencentCloudBhAccountGroups(),
"tencentcloud_bh_source_types": bh.DataSourceTencentCloudBhSourceTypes(),
"tencentcloud_cwp_machines_simple": cwp.DataSourceTencentCloudCwpMachinesSimple(),
"tencentcloud_ses_receivers": ses.DataSourceTencentCloudSesReceivers(),
"tencentcloud_ses_send_tasks": ses.DataSourceTencentCloudSesSendTasks(),
Expand Down Expand Up @@ -2401,6 +2403,17 @@ func Provider() *schema.Provider {
"tencentcloud_cfw_vpc_firewall_switch": cfw.ResourceTencentCloudCfwVpcFirewallSwitch(),
"tencentcloud_cfw_edge_firewall_switch": cfw.ResourceTencentCloudCfwEdgeFirewallSwitch(),
"tencentcloud_sg_rule": cfw.ResourceTencentCloudSgRule(),
"tencentcloud_bh_access_white_list_rule": bh.ResourceTencentCloudBhAccessWhiteListRule(),
"tencentcloud_bh_access_white_list_config": bh.ResourceTencentCloudBhAccessWhiteListConfig(),
"tencentcloud_bh_device": bh.ResourceTencentCloudBhDevice(),
"tencentcloud_bh_asset_sync_job_operation": bh.ResourceTencentCloudBhAssetSyncJobOperation(),
"tencentcloud_bh_asset_sync_flag_config": bh.ResourceTencentCloudBhAssetSyncFlagConfig(),
"tencentcloud_bh_resource": bh.ResourceTencentCloudBhResource(),
"tencentcloud_bh_reconnection_setting_config": bh.ResourceTencentCloudBhReconnectionSettingConfig(),
"tencentcloud_bh_user": bh.ResourceTencentCloudBhUser(),
"tencentcloud_bh_user_group": bh.ResourceTencentCloudBhUserGroup(),
"tencentcloud_bh_user_directory": bh.ResourceTencentCloudBhUserDirectory(),
"tencentcloud_bh_user_sync_task_operation": bh.ResourceTencentCloudBhUserSyncTaskOperation(),
"tencentcloud_dasb_acl": bh.ResourceTencentCloudDasbAcl(),
"tencentcloud_dasb_cmd_template": bh.ResourceTencentCloudDasbCmdTemplate(),
"tencentcloud_dasb_device_group": bh.ResourceTencentCloudDasbDeviceGroup(),
Expand Down
16 changes: 15 additions & 1 deletion tencentcloud/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,21 @@ tencentcloud_cfw_edge_firewall_switch
tencentcloud_sg_rule

Bastion Host(BH)
Resource
Data Source
tencentcloud_bh_account_groups
tencentcloud_bh_source_types
Resource
tencentcloud_bh_access_white_list_rule
tencentcloud_bh_access_white_list_config
tencentcloud_bh_device
tencentcloud_bh_asset_sync_job_operation
tencentcloud_bh_asset_sync_flag_config
tencentcloud_bh_resource
tencentcloud_bh_reconnection_setting_config
tencentcloud_bh_user
tencentcloud_bh_user_group
tencentcloud_bh_user_directory
tencentcloud_bh_user_sync_task_operation
tencentcloud_dasb_resource
tencentcloud_dasb_acl
tencentcloud_dasb_cmd_template
Expand Down
239 changes: 239 additions & 0 deletions tencentcloud/services/bh/data_source_tc_bh_account_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
package bh

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
bhv20230418 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/bh/v20230418"

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

func DataSourceTencentCloudBhAccountGroups() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudBhAccountGroupsRead,
Schema: map[string]*schema.Schema{
"deep_in": {
Type: schema.TypeInt,
Optional: true,
Description: "Whether to recursively query, 0 for non-recursive, 1 for recursive.",
},

"parent_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Parent account group ID, default 0, query all groups under the root account group.",
},

"group_name": {
Type: schema.TypeString,
Optional: true,
Description: "Account group name, fuzzy query.",
},

"page_num": {
Type: schema.TypeInt,
Optional: true,
Description: "Get data from which page.",
},

"account_group_set": {
Type: schema.TypeList,
Computed: true,
Description: "Account group information.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeInt,
Computed: true,
Description: "Account group ID.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Account group name.",
},
"id_path": {
Type: schema.TypeString,
Computed: true,
Description: "Account group ID path.",
},
"name_path": {
Type: schema.TypeString,
Computed: true,
Description: "Account group name path.",
},
"parent_id": {
Type: schema.TypeInt,
Computed: true,
Description: "Parent account group ID.",
},
"source": {
Type: schema.TypeInt,
Computed: true,
Description: "Account group source.",
},
"user_total": {
Type: schema.TypeInt,
Computed: true,
Description: "Total number of users under the account group.",
},
"is_leaf": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether it is a leaf node.",
},
"import_type": {
Type: schema.TypeString,
Computed: true,
Description: "Account group import type.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Account group description.",
},
"parent_org_id": {
Type: schema.TypeString,
Computed: true,
Description: "Parent source account organization ID. When using third-party import user sources, record the group ID of this group in the source organization structure.",
},
"org_id": {
Type: schema.TypeString,
Computed: true,
Description: "Source account organization ID. When using third-party import user sources, record the group ID of this group in the source organization structure.",
},
"status": {
Type: schema.TypeInt,
Computed: true,
Description: "Whether the account group has been connected, 0 means not connected, 1 means connected.",
},
},
},
},

"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}

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

var (
logId = tccommon.GetLogId(nil)
ctx = tccommon.NewResourceLifeCycleHandleFuncContext(context.Background(), logId, d, meta)
service = BhService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
)

paramMap := make(map[string]interface{})
if v, ok := d.GetOkExists("deep_in"); ok {
paramMap["DeepIn"] = helper.IntInt64(v.(int))
}

if v, ok := d.GetOkExists("parent_id"); ok {
paramMap["ParentId"] = helper.IntInt64(v.(int))
}

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

if v, ok := d.GetOkExists("page_num"); ok {
paramMap["PageNum"] = helper.IntInt64(v.(int))
}

var respData []*bhv20230418.AccountGroup
reqErr := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeBhAccountGroupsByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}

respData = result
return nil
})

if reqErr != nil {
return reqErr
}

accountGroupSetList := make([]map[string]interface{}, 0, len(respData))
if respData != nil {
for _, accountGroupSet := range respData {
accountGroupSetMap := map[string]interface{}{}
if accountGroupSet.Id != nil {
accountGroupSetMap["id"] = accountGroupSet.Id
}

if accountGroupSet.Name != nil {
accountGroupSetMap["name"] = accountGroupSet.Name
}

if accountGroupSet.IdPath != nil {
accountGroupSetMap["id_path"] = accountGroupSet.IdPath
}

if accountGroupSet.NamePath != nil {
accountGroupSetMap["name_path"] = accountGroupSet.NamePath
}

if accountGroupSet.ParentId != nil {
accountGroupSetMap["parent_id"] = accountGroupSet.ParentId
}

if accountGroupSet.Source != nil {
accountGroupSetMap["source"] = accountGroupSet.Source
}

if accountGroupSet.UserTotal != nil {
accountGroupSetMap["user_total"] = accountGroupSet.UserTotal
}

if accountGroupSet.IsLeaf != nil {
accountGroupSetMap["is_leaf"] = accountGroupSet.IsLeaf
}

if accountGroupSet.ImportType != nil {
accountGroupSetMap["import_type"] = accountGroupSet.ImportType
}

if accountGroupSet.Description != nil {
accountGroupSetMap["description"] = accountGroupSet.Description
}

if accountGroupSet.ParentOrgId != nil {
accountGroupSetMap["parent_org_id"] = accountGroupSet.ParentOrgId
}

if accountGroupSet.OrgId != nil {
accountGroupSetMap["org_id"] = accountGroupSet.OrgId
}

if accountGroupSet.Status != nil {
accountGroupSetMap["status"] = accountGroupSet.Status
}

accountGroupSetList = append(accountGroupSetList, accountGroupSetMap)
}

_ = d.Set("account_group_set", accountGroupSetList)
}

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

return nil
}
7 changes: 7 additions & 0 deletions tencentcloud/services/bh/data_source_tc_bh_account_groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Use this data source to query detailed information of BH account groups

Example Usage

```hcl
data "tencentcloud_bh_account_groups" "example" {}
```
29 changes: 29 additions & 0 deletions tencentcloud/services/bh/data_source_tc_bh_account_groups_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package bh_test

import (
"testing"

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

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

func TestAccTencentCloudBhAccountGroupsDataSource_basic(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() {
tcacctest.AccPreCheck(t)
},
Providers: tcacctest.AccProviders,
Steps: []resource.TestStep{{
Config: testAccBhAccountGroupsDataSource,
Check: resource.ComposeTestCheckFunc(
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_bh_account_groups.example"),
),
}},
})
}

const testAccBhAccountGroupsDataSource = `
data "tencentcloud_bh_account_groups" "example" {}
`
Loading
Loading