Skip to content

Commit 0d4bbd9

Browse files
authored
Merge pull request #23527 from GlennChia/f-aws_connect_user_hierarchy_structure
d/aws_connect_user_hierarchy_structure
2 parents d92726c + 40bf2a0 commit 0d4bbd9

7 files changed

+248
-2
lines changed

.changelog/23527.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-data-source
2+
aws_connect_user_hierarchy_structure
3+
```

internal/provider/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ func Provider() *schema.Provider {
504504
"aws_connect_queue": connect.DataSourceQueue(),
505505
"aws_connect_quick_connect": connect.DataSourceQuickConnect(),
506506
"aws_connect_security_profile": connect.DataSourceSecurityProfile(),
507+
"aws_connect_user_hierarchy_structure": connect.DataSourceUserHierarchyStructure(),
507508

508509
"aws_cur_report_definition": cur.DataSourceReportDefinition(),
509510

internal/service/connect/security_profile_data_source.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func dataSourceSecurityProfileRead(ctx context.Context, d *schema.ResourceData,
106106
d.Set("name", resp.SecurityProfile.SecurityProfileName)
107107

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

111111
if err != nil {
112112
return diag.FromErr(fmt.Errorf("error finding Connect Security Profile Permissions for Security Profile (%s): %w", *resp.SecurityProfile.Id, err))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package connect
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/aws/aws-sdk-go/aws"
8+
"github.com/aws/aws-sdk-go/service/connect"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
12+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
13+
)
14+
15+
func DataSourceUserHierarchyStructure() *schema.Resource {
16+
return &schema.Resource{
17+
ReadContext: dataSourceUserHierarchyStructureRead,
18+
Schema: map[string]*schema.Schema{
19+
"hierarchy_structure": {
20+
Type: schema.TypeList,
21+
Computed: true,
22+
Elem: &schema.Resource{
23+
Schema: map[string]*schema.Schema{
24+
"level_one": func() *schema.Schema {
25+
schema := connectUserHierarchyLevelDataSourceSchema()
26+
return schema
27+
}(),
28+
"level_two": func() *schema.Schema {
29+
schema := connectUserHierarchyLevelDataSourceSchema()
30+
return schema
31+
}(),
32+
"level_three": func() *schema.Schema {
33+
schema := connectUserHierarchyLevelDataSourceSchema()
34+
return schema
35+
}(),
36+
"level_four": func() *schema.Schema {
37+
schema := connectUserHierarchyLevelDataSourceSchema()
38+
return schema
39+
}(),
40+
"level_five": func() *schema.Schema {
41+
schema := connectUserHierarchyLevelDataSourceSchema()
42+
return schema
43+
}(),
44+
},
45+
},
46+
},
47+
"instance_id": {
48+
Type: schema.TypeString,
49+
Required: true,
50+
ValidateFunc: validation.StringLenBetween(1, 100),
51+
},
52+
},
53+
}
54+
}
55+
56+
// Each level shares the same schema
57+
func connectUserHierarchyLevelDataSourceSchema() *schema.Schema {
58+
return &schema.Schema{
59+
Type: schema.TypeList,
60+
Computed: true,
61+
Elem: &schema.Resource{
62+
Schema: map[string]*schema.Schema{
63+
"arn": {
64+
Type: schema.TypeString,
65+
Computed: true,
66+
},
67+
"id": {
68+
Type: schema.TypeString,
69+
Computed: true,
70+
},
71+
"name": {
72+
Type: schema.TypeString,
73+
Computed: true,
74+
},
75+
},
76+
},
77+
}
78+
}
79+
80+
func dataSourceUserHierarchyStructureRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
81+
conn := meta.(*conns.AWSClient).ConnectConn
82+
83+
instanceID := d.Get("instance_id").(string)
84+
85+
resp, err := conn.DescribeUserHierarchyStructureWithContext(ctx, &connect.DescribeUserHierarchyStructureInput{
86+
InstanceId: aws.String(instanceID),
87+
})
88+
89+
if err != nil {
90+
return diag.FromErr(fmt.Errorf("error getting Connect User Hierarchy Structure for Connect Instance (%s): %w", instanceID, err))
91+
}
92+
93+
if resp == nil || resp.HierarchyStructure == nil {
94+
return diag.FromErr(fmt.Errorf("error getting Connect User Hierarchy Structure for Connect Instance (%s): empty response", instanceID))
95+
}
96+
97+
if err := d.Set("hierarchy_structure", flattenUserHierarchyStructure(resp.HierarchyStructure)); err != nil {
98+
return diag.FromErr(fmt.Errorf("error setting Connect User Hierarchy Structure for Connect Instance: (%s)", instanceID))
99+
}
100+
101+
d.SetId(instanceID)
102+
103+
return nil
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package connect_test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/aws/aws-sdk-go/service/connect"
8+
sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
11+
)
12+
13+
func TestAccConnectUserHierarchyStructureDataSource_instanceID(t *testing.T) {
14+
rName := sdkacctest.RandomWithPrefix("resource-test-terraform")
15+
resourceName := "aws_connect_user_hierarchy_structure.test"
16+
datasourceName := "data.aws_connect_user_hierarchy_structure.test"
17+
18+
resource.Test(t, resource.TestCase{
19+
PreCheck: func() { acctest.PreCheck(t) },
20+
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID),
21+
Providers: acctest.Providers,
22+
Steps: []resource.TestStep{
23+
{
24+
Config: testAccUserHierarchyStructureDataSourceConfig_InstanceID(rName),
25+
Check: resource.ComposeAggregateTestCheckFunc(
26+
resource.TestCheckResourceAttrPair(datasourceName, "instance_id", resourceName, "instance_id"),
27+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.#", resourceName, "hierarchy_structure.#"),
28+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_one.#", resourceName, "hierarchy_structure.0.level_one.#"),
29+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_one.0.name", resourceName, "hierarchy_structure.0.level_one.0.name"),
30+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_two.#", resourceName, "hierarchy_structure.0.level_two.#"),
31+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_two.0.name", resourceName, "hierarchy_structure.0.level_two.0.name"),
32+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_three.#", resourceName, "hierarchy_structure.0.level_three.#"),
33+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_three.0.name", resourceName, "hierarchy_structure.0.level_three.0.name"),
34+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_four.#", resourceName, "hierarchy_structure.0.level_four.#"),
35+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_four.0.name", resourceName, "hierarchy_structure.0.level_four.0.name"),
36+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_five.#", resourceName, "hierarchy_structure.0.level_five.#"),
37+
resource.TestCheckResourceAttrPair(datasourceName, "hierarchy_structure.0.level_five.0.name", resourceName, "hierarchy_structure.0.level_five.0.name"),
38+
),
39+
},
40+
},
41+
})
42+
}
43+
44+
func testAccUserHierarchyStructureBaseDataSourceConfig(rName string) string {
45+
return fmt.Sprintf(`
46+
resource "aws_connect_instance" "test" {
47+
identity_management_type = "CONNECT_MANAGED"
48+
inbound_calls_enabled = true
49+
instance_alias = %[1]q
50+
outbound_calls_enabled = true
51+
}
52+
53+
resource "aws_connect_user_hierarchy_structure" "test" {
54+
instance_id = aws_connect_instance.test.id
55+
56+
hierarchy_structure {
57+
level_one {
58+
name = "levelone"
59+
}
60+
61+
level_two {
62+
name = "leveltwo"
63+
}
64+
65+
level_three {
66+
name = "levelthree"
67+
}
68+
69+
level_four {
70+
name = "levelfour"
71+
}
72+
73+
level_five {
74+
name = "levelfive"
75+
}
76+
}
77+
}
78+
`, rName)
79+
}
80+
81+
func testAccUserHierarchyStructureDataSourceConfig_InstanceID(rName string) string {
82+
return acctest.ConfigCompose(
83+
testAccUserHierarchyStructureBaseDataSourceConfig(rName),
84+
`
85+
data "aws_connect_user_hierarchy_structure" "test" {
86+
instance_id = aws_connect_instance.test.id
87+
88+
depends_on = [
89+
aws_connect_user_hierarchy_structure.test,
90+
]
91+
}
92+
`)
93+
}

website/docs/d/connect_security_profile.html.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ In addition to all of the arguments above, the following attributes are exported
4949
* `id` - The identifier of the hosting Amazon Connect Instance and identifier of the Security Profile separated by a colon (`:`).
5050
* `organization_resource_id` - The organization resource identifier for the security profile.
5151
* `permissions` - Specifies a list of permissions assigned to the security profile.
52-
* `tags` - A map of tags to assign to the Security Profile.
52+
* `tags` - A map of tags to assign to the Security Profile.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
subcategory: "Connect"
3+
layout: "aws"
4+
page_title: "AWS: aws_connect_user_hierarchy_structure"
5+
description: |-
6+
Provides details about a specific Amazon Connect User Hierarchy Structure
7+
---
8+
9+
# Data Source: aws_connect_user_hierarchy_structure
10+
11+
Provides details about a specific Amazon Connect User Hierarchy Structure
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "aws_connect_user_hierarchy_structure" "test" {
17+
instance_id = aws_connect_instance.test.id
18+
}
19+
```
20+
21+
## Argument Reference
22+
23+
The following arguments are supported:
24+
25+
* `instance_id` - (Required) Reference to the hosting Amazon Connect Instance
26+
27+
## Attributes Reference
28+
29+
In addition to all of the argument above, the following attributes are exported:
30+
31+
* `hierarchy_structure` - A block that defines the hierarchy structure's levels. The `hierarchy_structure` block is documented below.
32+
33+
A `hierarchy_structure` block supports the following attributes:
34+
35+
* `level_one` - A block that defines the details of level one. The level block is documented below.
36+
* `level_two` - A block that defines the details of level two. The level block is documented below.
37+
* `level_three` - A block that defines the details of level three. The level block is documented below.
38+
* `level_four` - A block that defines the details of level four. The level block is documented below.
39+
* `level_five` - A block that defines the details of level five. The level block is documented below.
40+
41+
Each level block supports the following attributes:
42+
43+
* `arn` - The Amazon Resource Name (ARN) of the hierarchy level.
44+
* `id` - The identifier of the hierarchy level.
45+
* `name` - The name of the user hierarchy level. Must not be more than 50 characters.

0 commit comments

Comments
 (0)