-
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): [120225468]add tencentcloud_organization_nodes and tencent…
…cloud_open_identity_center_operation (#2906) * add resource * add changelog * update --------- Co-authored-by: mikatong <mikatong@tencent.com>
- Loading branch information
1 parent
2cfd758
commit 01ec1df
Showing
13 changed files
with
538 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,7 @@ | ||
```release-note:new-resource | ||
tencentcloud_open_identity_center_operation | ||
``` | ||
|
||
```release-note:new-data-source | ||
tencentcloud_organization_nodes | ||
``` |
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
211 changes: 211 additions & 0 deletions
211
tencentcloud/services/tco/data_source_tc_organization_nodes.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,211 @@ | ||
package tco | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
|
||
"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 DataSourceTencentCloudOrganizationNodes() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceTencentCloudOrganizationNodesRead, | ||
Schema: map[string]*schema.Schema{ | ||
"tags": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Description: "Department tag search list, with a maximum of 10.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"tag_key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag key.", | ||
}, | ||
"tag_value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag value.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"items": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "List details.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"node_id": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "Organization node ID.", | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name.", | ||
}, | ||
"parent_node_id": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "Parent node ID.", | ||
}, | ||
"remark": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Remarks.", | ||
}, | ||
"create_time": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Creation time.", | ||
}, | ||
"update_time": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Update time.", | ||
}, | ||
"tags": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
Description: "Member tag list.", | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"tag_key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag key.", | ||
}, | ||
"tag_value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Tag value.", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"result_output_file": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Used to save results.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTencentCloudOrganizationNodesRead(d *schema.ResourceData, meta interface{}) error { | ||
defer tccommon.LogElapsed("data_source.tencentcloud_organization_nodes.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("tags"); ok { | ||
tagsSet := v.([]interface{}) | ||
tmpSet := make([]*organization.Tag, 0, len(tagsSet)) | ||
for _, item := range tagsSet { | ||
tagsMap := item.(map[string]interface{}) | ||
tag := organization.Tag{} | ||
if v, ok := tagsMap["tag_key"]; ok { | ||
tag.TagKey = helper.String(v.(string)) | ||
} | ||
if v, ok := tagsMap["tag_value"]; ok { | ||
tag.TagValue = helper.String(v.(string)) | ||
} | ||
tmpSet = append(tmpSet, &tag) | ||
} | ||
paramMap["Tags"] = tmpSet | ||
} | ||
|
||
var nodes []*organization.OrgNode | ||
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError { | ||
result, e := service.DescribeOrganizationNodesByFilter(ctx, paramMap) | ||
if e != nil { | ||
return tccommon.RetryError(e) | ||
} | ||
nodes = result | ||
return nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
itemList := make([]map[string]interface{}, 0, len(nodes)) | ||
ids := make([]string, 0, len(nodes)) | ||
for _, item := range nodes { | ||
itemMap := map[string]interface{}{} | ||
|
||
if item.NodeId != nil { | ||
itemMap["node_id"] = item.NodeId | ||
nodeIdStr := strconv.FormatInt(*item.NodeId, 10) | ||
ids = append(ids, nodeIdStr) | ||
} | ||
|
||
if item.Name != nil { | ||
itemMap["name"] = item.Name | ||
} | ||
|
||
if item.ParentNodeId != nil { | ||
itemMap["parent_node_id"] = item.ParentNodeId | ||
} | ||
|
||
if item.Remark != nil { | ||
itemMap["remark"] = item.Remark | ||
} | ||
|
||
if item.CreateTime != nil { | ||
itemMap["create_time"] = item.CreateTime | ||
} | ||
|
||
if item.UpdateTime != nil { | ||
itemMap["update_time"] = item.UpdateTime | ||
} | ||
|
||
tagsList := make([]map[string]interface{}, 0, len(item.Tags)) | ||
if item.Tags != nil { | ||
for _, tags := range item.Tags { | ||
tagsMap := map[string]interface{}{} | ||
|
||
if tags.TagKey != nil { | ||
tagsMap["tag_key"] = tags.TagKey | ||
} | ||
|
||
if tags.TagValue != nil { | ||
tagsMap["tag_value"] = tags.TagValue | ||
} | ||
|
||
tagsList = append(tagsList, tagsMap) | ||
} | ||
|
||
itemMap["tags"] = tagsList | ||
} | ||
itemList = append(itemList, itemMap) | ||
} | ||
|
||
_ = d.Set("items", itemList) | ||
|
||
d.SetId(helper.DataResourceIdsHash(ids)) | ||
|
||
output, ok := d.GetOk("result_output_file") | ||
if ok && output.(string) != "" { | ||
if e := tccommon.WriteToFile(output.(string), itemList); e != nil { | ||
return e | ||
} | ||
} | ||
|
||
return nil | ||
} |
12 changes: 12 additions & 0 deletions
12
tencentcloud/services/tco/data_source_tc_organization_nodes.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,12 @@ | ||
Use this data source to query detailed information of organization nodes | ||
|
||
Example Usage | ||
|
||
```hcl | ||
data "tencentcloud_organization_nodes" "organization_nodes" { | ||
tags { | ||
tag_key = "createBy" | ||
tag_value = "terraform" | ||
} | ||
} | ||
``` |
42 changes: 42 additions & 0 deletions
42
tencentcloud/services/tco/data_source_tc_organization_nodes_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,42 @@ | ||
package tco_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest" | ||
) | ||
|
||
func TestAccTencentCloudOrganizationNodesDataSource_basic(t *testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
tcacctest.AccPreCheck(t) | ||
}, | ||
Providers: tcacctest.AccProviders, | ||
Steps: []resource.TestStep{{ | ||
Config: testAccOrganizationNodesDataSource, | ||
Check: resource.ComposeTestCheckFunc( | ||
tcacctest.AccCheckTencentCloudDataSourceID("data.tencentcloud_organization_nodes.organization_nodes"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.#"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.name"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.node_id"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.parent_node_id"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.create_time"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.update_time"), | ||
resource.TestCheckResourceAttrSet("data.tencentcloud_organization_nodes.organization_nodes", "items.0.tags.#"), | ||
), | ||
}}, | ||
}) | ||
} | ||
|
||
const testAccOrganizationNodesDataSource = ` | ||
data "tencentcloud_organization_nodes" "organization_nodes" { | ||
tags { | ||
tag_key = "createBy" | ||
tag_value = "terraform" | ||
} | ||
} | ||
` |
88 changes: 88 additions & 0 deletions
88
tencentcloud/services/tco/resource_tc_open_identity_center_operation.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,88 @@ | ||
package tco | ||
|
||
import ( | ||
"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 ResourceTencentCloudOpenIdentityCenterOperation() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceTencentCloudInviteOpenIdentityCenterOperationCreate, | ||
Read: resourceTencentCloudInviteOpenIdentityCenterOperationRead, | ||
Delete: resourceTencentCloudInviteOpenIdentityCenterOperationDelete, | ||
Schema: map[string]*schema.Schema{ | ||
"zone_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Space name, which must be globally unique and contain 2-64 characters including lowercase letters, digits, and hyphens (-). It can neither start or end with a hyphen (-) nor contain two consecutive hyphens (-).", | ||
}, | ||
|
||
"zone_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Space ID. z-Prefix starts with 12 random numbers/lowercase letters followed by.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceTencentCloudInviteOpenIdentityCenterOperationCreate(d *schema.ResourceData, meta interface{}) error { | ||
defer tccommon.LogElapsed("resource.tencentcloud_open_identity_center_operation.create")() | ||
defer tccommon.InconsistentCheck(d, meta)() | ||
|
||
logId := tccommon.GetLogId(tccommon.ContextNil) | ||
|
||
var ( | ||
request = organization.NewOpenIdentityCenterRequest() | ||
response = organization.NewOpenIdentityCenterResponse() | ||
) | ||
|
||
if v, ok := d.GetOk("zone_name"); ok { | ||
request.ZoneName = helper.String(v.(string)) | ||
} | ||
|
||
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError { | ||
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseOrganizationClient().OpenIdentityCenter(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 open identity center operation failed, reason:%+v", logId, err) | ||
return err | ||
} | ||
|
||
if response.Response != nil && response.Response.ZoneId != nil { | ||
d.SetId(*response.Response.ZoneId) | ||
_ = d.Set("zone_id", *response.Response.ZoneId) | ||
} | ||
|
||
_ = response | ||
|
||
return resourceTencentCloudInviteOpenIdentityCenterOperationRead(d, meta) | ||
} | ||
|
||
func resourceTencentCloudInviteOpenIdentityCenterOperationRead(d *schema.ResourceData, meta interface{}) error { | ||
defer tccommon.LogElapsed("resource.tencentcloud_open_identity_center_operation.read")() | ||
defer tccommon.InconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} | ||
|
||
func resourceTencentCloudInviteOpenIdentityCenterOperationDelete(d *schema.ResourceData, meta interface{}) error { | ||
defer tccommon.LogElapsed("resource.tencentcloud_open_identity_center_operation.delete")() | ||
defer tccommon.InconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} |
Oops, something went wrong.