-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
d/aws_connect_contact_flow_module (#22518)
* feat(connect): contact flow module datasrc schema * feat(connect): contact flow module datasrc reads uses either contact_flow_module_id or name DescribeContactFlowModuleWithContext api ListContactFlowModulesPagesWithContext api * feat(connect): contact flow mod datasrc provider * test(connect): id for contact flow mod datasrc * test(connect): name for contact flow mod datasrc * docs(connect): data source for contact flow module * ci(connect): changelog contact flow module datasrc * test(connect): check status even when name is used * docs(connect): status returned for both queries
- Loading branch information
Showing
6 changed files
with
324 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,3 @@ | ||
```release-note:new-data-source | ||
aws_connect_contact_flow_module | ||
``` |
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
148 changes: 148 additions & 0 deletions
148
internal/service/connect/contact_flow_module_data_source.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,148 @@ | ||
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-provider-aws/internal/conns" | ||
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" | ||
) | ||
|
||
func DataSourceContactFlowModule() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceContactFlowModuleRead, | ||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"contact_flow_module_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ExactlyOneOf: []string{"contact_flow_module_id", "name"}, | ||
}, | ||
"content": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"instance_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ExactlyOneOf: []string{"name", "contact_flow_module_id"}, | ||
}, | ||
"state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": tftags.TagsSchemaComputed(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceContactFlowModuleRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn := meta.(*conns.AWSClient).ConnectConn | ||
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig | ||
|
||
instanceID := d.Get("instance_id").(string) | ||
|
||
input := &connect.DescribeContactFlowModuleInput{ | ||
InstanceId: aws.String(instanceID), | ||
} | ||
|
||
if v, ok := d.GetOk("contact_flow_module_id"); ok { | ||
input.ContactFlowModuleId = aws.String(v.(string)) | ||
} else if v, ok := d.GetOk("name"); ok { | ||
name := v.(string) | ||
contactFlowModuleSummary, err := dataSourceGetConnectContactFlowModuleSummaryByName(ctx, conn, instanceID, name) | ||
|
||
if err != nil { | ||
return diag.FromErr(fmt.Errorf("error finding Connect Contact Flow Module Summary by name (%s): %w", name, err)) | ||
} | ||
|
||
if contactFlowModuleSummary == nil { | ||
return diag.FromErr(fmt.Errorf("error finding Connect Contact Flow Module Summary by name (%s): not found", name)) | ||
} | ||
|
||
input.ContactFlowModuleId = contactFlowModuleSummary.Id | ||
} | ||
|
||
resp, err := conn.DescribeContactFlowModuleWithContext(ctx, input) | ||
|
||
if err != nil { | ||
return diag.FromErr(fmt.Errorf("error getting Connect Contact Flow Module: %w", err)) | ||
} | ||
|
||
if resp == nil || resp.ContactFlowModule == nil { | ||
return diag.FromErr(fmt.Errorf("error getting Connect Contact Flow Module: empty response")) | ||
} | ||
|
||
contactFlowModule := resp.ContactFlowModule | ||
|
||
d.Set("arn", contactFlowModule.Arn) | ||
d.Set("contact_flow_module_id", contactFlowModule.Id) | ||
d.Set("content", contactFlowModule.Content) | ||
d.Set("description", contactFlowModule.Description) | ||
d.Set("name", contactFlowModule.Name) | ||
d.Set("state", contactFlowModule.State) | ||
d.Set("status", contactFlowModule.Status) | ||
|
||
if err := d.Set("tags", KeyValueTags(contactFlowModule.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
return diag.FromErr(fmt.Errorf("error setting tags: %s", err)) | ||
} | ||
|
||
d.SetId(fmt.Sprintf("%s:%s", instanceID, aws.StringValue(contactFlowModule.Id))) | ||
|
||
return nil | ||
} | ||
|
||
func dataSourceGetConnectContactFlowModuleSummaryByName(ctx context.Context, conn *connect.Connect, instanceID, name string) (*connect.ContactFlowModuleSummary, error) { | ||
var result *connect.ContactFlowModuleSummary | ||
|
||
input := &connect.ListContactFlowModulesInput{ | ||
InstanceId: aws.String(instanceID), | ||
MaxResults: aws.Int64(ListContactFlowModulesMaxResults), | ||
} | ||
|
||
err := conn.ListContactFlowModulesPagesWithContext(ctx, input, func(page *connect.ListContactFlowModulesOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, cf := range page.ContactFlowModulesSummaryList { | ||
if cf == nil { | ||
continue | ||
} | ||
|
||
if aws.StringValue(cf.Name) == name { | ||
result = cf | ||
return false | ||
} | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
116 changes: 116 additions & 0 deletions
116
internal/service/connect/contact_flow_module_data_source_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,116 @@ | ||
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 TestAccConnectContactFlowModuleDataSource_contactFlowModuleID(t *testing.T) { | ||
rName := sdkacctest.RandomWithPrefix("resource-test-terraform") | ||
resourceName := "aws_connect_contact_flow_module.test" | ||
datasourceName := "data.aws_connect_contact_flow_module.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID), | ||
Providers: acctest.Providers, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccContactFlowModuleDataSourceConfig_ContactFlowModuleID(rName, resourceName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "contact_flow_module_id", resourceName, "contact_flow_module_id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "instance_id", resourceName, "instance_id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "content", resourceName, "content"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "state"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "status"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccConnectContactFlowModuleDataSource_name(t *testing.T) { | ||
rName := sdkacctest.RandomWithPrefix("resource-test-terraform") | ||
rName2 := sdkacctest.RandomWithPrefix("resource-test-terraform") | ||
resourceName := "aws_connect_contact_flow_module.test" | ||
datasourceName := "data.aws_connect_contact_flow_module.test" | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
ErrorCheck: acctest.ErrorCheck(t, connect.EndpointsID), | ||
Providers: acctest.Providers, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccContactFlowModuleDataSourceConfig_Name(rName, rName2), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(datasourceName, "id", resourceName, "id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "contact_flow_module_id", resourceName, "contact_flow_module_id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "instance_id", resourceName, "instance_id"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "content", resourceName, "content"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "state"), | ||
resource.TestCheckResourceAttrSet(datasourceName, "status"), | ||
resource.TestCheckResourceAttrPair(datasourceName, "tags.%", resourceName, "tags.%"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccContactFlowModuleBaseDataSourceConfig(rName, rName2 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_contact_flow_module" "test" { | ||
instance_id = aws_connect_instance.test.id | ||
name = %[2]q | ||
description = "Test Contact Flow Module Description" | ||
content = file("./test-fixtures/connect_contact_flow_module.json") | ||
tags = { | ||
"Name" = "Test Contact Flow Module", | ||
"Application" = "Terraform", | ||
"Method" = "Create" | ||
} | ||
} | ||
`, rName, rName2) | ||
} | ||
|
||
func testAccContactFlowModuleDataSourceConfig_ContactFlowModuleID(rName, rName2 string) string { | ||
return acctest.ConfigCompose( | ||
testAccContactFlowModuleBaseDataSourceConfig(rName, rName2), | ||
` | ||
data "aws_connect_contact_flow_module" "test" { | ||
instance_id = aws_connect_instance.test.id | ||
contact_flow_module_id = aws_connect_contact_flow_module.test.contact_flow_module_id | ||
} | ||
`) | ||
} | ||
|
||
func testAccContactFlowModuleDataSourceConfig_Name(rName, rName2 string) string { | ||
return acctest.ConfigCompose( | ||
testAccContactFlowModuleBaseDataSourceConfig(rName, rName2), | ||
` | ||
data "aws_connect_contact_flow_module" "test" { | ||
instance_id = aws_connect_instance.test.id | ||
name = aws_connect_contact_flow_module.test.name | ||
} | ||
`) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
subcategory: "Connect" | ||
layout: "aws" | ||
page_title: "AWS: aws_connect_contact_flow_module" | ||
description: |- | ||
Provides details about a specific Amazon Connect Contact Flow Module. | ||
--- | ||
|
||
# Data Source: aws_connect_contact_flow_module | ||
|
||
Provides details about a specific Amazon Connect Contact Flow Module. | ||
|
||
## Example Usage | ||
|
||
By `name` | ||
|
||
```hcl | ||
data "aws_connect_contact_flow_module" "example" { | ||
instance_id = "aaaaaaaa-bbbb-cccc-dddd-111111111111" | ||
name = "example" | ||
} | ||
``` | ||
|
||
By `contact_flow_module_id` | ||
|
||
```hcl | ||
data "aws_connect_contact_flow_module" "example" { | ||
instance_id = "aaaaaaaa-bbbb-cccc-dddd-111111111111" | ||
contact_flow_module_id = "cccccccc-bbbb-cccc-dddd-111111111111" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
~> **NOTE:** `instance_id` and one of either `name` or `contact_flow_module_id` is required. | ||
|
||
The following arguments are supported: | ||
|
||
* `contact_flow_module_id` - (Optional) Returns information on a specific Contact Flow Module by contact flow module id | ||
* `instance_id` - (Required) Reference to the hosting Amazon Connect Instance | ||
* `name` - (Optional) Returns information on a specific Contact Flow Module by name | ||
|
||
## Attributes Reference | ||
|
||
In addition to all of the arguments above, the following attributes are exported: | ||
|
||
* `arn` - The Amazon Resource Name (ARN) of the Contact Flow Module. | ||
* `content` - Specifies the logic of the Contact Flow Module. | ||
* `description` - Specifies the description of the Contact Flow Module. | ||
* `tags` - A map of tags to assign to the Contact Flow Module. | ||
* `state` - Specifies the type of Contact Flow Module Module. Values are either `ACTIVE` or `ARCHIVED`. | ||
* `status` - The status of the Contact Flow Module Module. Values are either `PUBLISHED` or `SAVED`. |