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

d/aws_connect_user_hierarchy_structure #23527

Merged
3 changes: 3 additions & 0 deletions .changelog/23527.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_connect_user_hierarchy_structure
```
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ func Provider() *schema.Provider {
"aws_connect_queue": connect.DataSourceQueue(),
"aws_connect_quick_connect": connect.DataSourceQuickConnect(),
"aws_connect_security_profile": connect.DataSourceSecurityProfile(),
"aws_connect_user_hierarchy_structure": connect.DataSourceUserHierarchyStructure(),

"aws_cur_report_definition": cur.DataSourceReportDefinition(),

Expand Down
2 changes: 1 addition & 1 deletion internal/service/connect/security_profile_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func dataSourceSecurityProfileRead(ctx context.Context, d *schema.ResourceData,
d.Set("name", resp.SecurityProfile.SecurityProfileName)

// reading permissions requires a separate API call
permissions, err := getConnectSecurityProfilePermissions(ctx, conn, instanceID, *resp.SecurityProfile.Id)
permissions, err := getSecurityProfilePermissions(ctx, conn, instanceID, *resp.SecurityProfile.Id)

if err != nil {
return diag.FromErr(fmt.Errorf("error finding Connect Security Profile Permissions for Security Profile (%s): %w", *resp.SecurityProfile.Id, err))
Expand Down
104 changes: 104 additions & 0 deletions internal/service/connect/user_hierarchy_structure_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package connect

import (
"context"
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/connect"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
)

func DataSourceUserHierarchyStructure() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceUserHierarchyStructureRead,
Schema: map[string]*schema.Schema{
"hierarchy_structure": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"level_one": func() *schema.Schema {
schema := connectUserHierarchyLevelDataSourceSchema()
return schema
}(),
"level_two": func() *schema.Schema {
schema := connectUserHierarchyLevelDataSourceSchema()
return schema
}(),
"level_three": func() *schema.Schema {
schema := connectUserHierarchyLevelDataSourceSchema()
return schema
}(),
"level_four": func() *schema.Schema {
schema := connectUserHierarchyLevelDataSourceSchema()
return schema
}(),
"level_five": func() *schema.Schema {
schema := connectUserHierarchyLevelDataSourceSchema()
return schema
}(),
},
},
},
"instance_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 100),
},
},
}
}

// Each level shares the same schema
func connectUserHierarchyLevelDataSourceSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
}
}

func dataSourceUserHierarchyStructureRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).ConnectConn

instanceID := d.Get("instance_id").(string)

resp, err := conn.DescribeUserHierarchyStructureWithContext(ctx, &connect.DescribeUserHierarchyStructureInput{
InstanceId: aws.String(instanceID),
})

if err != nil {
return diag.FromErr(fmt.Errorf("error getting Connect User Hierarchy Structure for Connect Instance (%s): %w", instanceID, err))
}

if resp == nil || resp.HierarchyStructure == nil {
return diag.FromErr(fmt.Errorf("error getting Connect User Hierarchy Structure for Connect Instance (%s): empty response", instanceID))
}

if err := d.Set("hierarchy_structure", flattenUserHierarchyStructure(resp.HierarchyStructure)); err != nil {
return diag.FromErr(fmt.Errorf("error setting Connect User Hierarchy Structure for Connect Instance: (%s)", instanceID))
}

d.SetId(instanceID)

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package connect_test

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/connect"
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
)

func TestAccConnectUserHierarchyStructureDataSource_instanceID(t *testing.T) {
rName := sdkacctest.RandomWithPrefix("resource-test-terraform")
resourceName := "aws_connect_user_hierarchy_structure.test"
datasourceName := "data.aws_connect_user_hierarchy_structure.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID),
Providers: acctest.Providers,
Steps: []resource.TestStep{
{
Config: testAccUserHierarchyStructureDataSourceConfig_InstanceID(rName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(datasourceName, "instance_id", resourceName, "instance_id"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.#", resourceName, "hierarchy_structure.#"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_one.#", resourceName, "hierarchy_structure.0.level_one.#"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_one.0.name", resourceName, "hierarchy_structure.0.level_one.0.name"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_two.#", resourceName, "hierarchy_structure.0.level_two.#"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_two.0.name", resourceName, "hierarchy_structure.0.level_two.0.name"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_three.#", resourceName, "hierarchy_structure.0.level_three.#"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_three.0.name", resourceName, "hierarchy_structure.0.level_three.0.name"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_four.#", resourceName, "hierarchy_structure.0.level_four.#"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_four.0.name", resourceName, "hierarchy_structure.0.level_four.0.name"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_five.#", resourceName, "hierarchy_structure.0.level_five.#"),
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_five.0.name", resourceName, "hierarchy_structure.0.level_five.0.name"),
),
},
},
})
}

func testAccUserHierarchyStructureBaseDataSourceConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_connect_instance" "test" {
identity_management_type = "CONNECT_MANAGED"
inbound_calls_enabled = true
instance_alias = %[1]q
outbound_calls_enabled = true
}

resource "aws_connect_user_hierarchy_structure" "test" {
instance_id = aws_connect_instance.test.id

hierarchy_structure {
level_one {
name = "levelone"
}

level_two {
name = "leveltwo"
}

level_three {
name = "levelthree"
}

level_four {
name = "levelfour"
}

level_five {
name = "levelfive"
}
}
}
`, rName)
}

func testAccUserHierarchyStructureDataSourceConfig_InstanceID(rName string) string {
return acctest.ConfigCompose(
testAccUserHierarchyStructureBaseDataSourceConfig(rName),
`
data "aws_connect_user_hierarchy_structure" "test" {
instance_id = aws_connect_instance.test.id

depends_on = [
aws_connect_user_hierarchy_structure.test,
]
}
`)
}
2 changes: 1 addition & 1 deletion website/docs/d/connect_security_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ In addition to all of the arguments above, the following attributes are exported
* `id` - The identifier of the hosting Amazon Connect Instance and identifier of the Security Profile separated by a colon (`:`).
* `organization_resource_id` - The organization resource identifier for the security profile.
* `permissions` - Specifies a list of permissions assigned to the security profile.
* `tags` - A map of tags to assign to the Security Profile.
* `tags` - A map of tags to assign to the Security Profile.
45 changes: 45 additions & 0 deletions website/docs/d/connect_user_hierarchy_structure.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
subcategory: "Connect"
layout: "aws"
page_title: "AWS: aws_connect_user_hierarchy_structure"
description: |-
Provides details about a specific Amazon Connect User Hierarchy Structure
---

# Data Source: aws_connect_user_hierarchy_structure

Provides details about a specific Amazon Connect User Hierarchy Structure

## Example Usage

```hcl
data "aws_connect_user_hierarchy_structure" "test" {
instance_id = aws_connect_instance.test.id
}
```

## Argument Reference

The following arguments are supported:

* `instance_id` - (Required) Reference to the hosting Amazon Connect Instance

## Attributes Reference

In addition to all of the argument above, the following attributes are exported:

* `hierarchy_structure` - A block that defines the hierarchy structure's levels. The `hierarchy_structure` block is documented below.

A `hierarchy_structure` block supports the following attributes:

* `level_one` - A block that defines the details of level one. The level block is documented below.
* `level_two` - A block that defines the details of level two. The level block is documented below.
* `level_three` - A block that defines the details of level three. The level block is documented below.
* `level_four` - A block that defines the details of level four. The level block is documented below.
* `level_five` - A block that defines the details of level five. The level block is documented below.

Each level block supports the following attributes:

* `arn` - The Amazon Resource Name (ARN) of the hierarchy level.
* `id` - The identifier of the hierarchy level.
* `name` - The name of the user hierarchy level. Must not be more than 50 characters.