# Amazon Connect Module This module can be used to deploy an Amazon Connect instance and all supporting resources, such as Hours of Operation, queues, etc (full list below). It also supports passing in an existing instance ID, and creating supporting resources associated to it. Common deployment examples can be found in the [./examples](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples) directory. **NOTE: At this time, due to limitations in the Amazon Connect API certain operations are not supported, such as deleting a queue. If you have created these resources with Terraform, and wish to destroy the instance, you must first remove them from the Terraform state with `terraform state rm`.** **Specifically with queues, if you delete them via Terraform and get a duplicate name error when trying to create them again, you will need to rename or import them into the Terraform state.** ## Usage The example below is the basic usage of this module and will create an Amazon Connect instance. ```hcl module "amazon_connect" { source = "aws-ia/amazonconnect/aws" version = "~> 0.0.1" instance_identity_management_type = "CONNECT_MANAGED" instance_inbound_calls_enabled = true instance_outbound_calls_enabled = true instance_alias = "my-instance-alias" } ``` ## Usage Examples * [Simple](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples/simple/main.tf) * [Instance w/ S3 Storage Configuration](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples/instance-storage-config-s3/main.tf) * [Instance w/ Kinesis Storage Configuration](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples/instance-storage-config-kinesis/main.tf) * [Instance w/ Hours of Operations](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples/hours-of-operations/main.tf) * [Instance w/ Queue](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples/queue/main.tf) * [Instance w/ Lex Bot Association](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples/lex-bot-association/main.tf) * [Complete](https://github.com/aws-ia/terraform-aws-amazonconnect/tree/main/examples/complete/main.tf) ## Dependent Resources Many resources within Amazon Connect have dependencies. A basic example is if you are creating a Queue that depends on an Hour of Operation. If you were not using this module, this would look straightforward: Without module: ```hcl resource "aws_connect_hours_of_operation" "example" { ... } resource "aws_connect_queue" "example" { ... hours_of_operation_id = aws_connect_hours_of_operation.example.hours_of_operation_id } ``` With this module, you can do the same thing in a single use of the module. It's possible by using the modules outputs as values for its variables/inputs. At first glance, this might not seem intuitive/possible, but since the Terraform plan phase "flattens" everything to resolve the DAG/order of operations for the deployment, it is completely fine. With module: ```hcl module "amazon_connect" { ... hours_of_operations = { example = { ... } } queues = { example = { hours_of_operation_id = try(module.amazon_connect.hours_of_operations["example"].hours_of_operation_id, null) } } } ``` ### Important note for Amazon Connect User Hierarchy Group The one place where this is not possible is for User Hierarchy Group resources, which have a circular dependency through `parent_group_id`. In the module, resources are created through a single resource combined with a `for_each` loop. Because of this, it would create a circular reference for Terraform to have one iteration reference itself. Instead, if you need a child/parent group relationship to be created, make a second module call for the parent group. ❌ Invalid example: ```hcl module "amazon_connect" { ... user_hierarchy_groups = { parent = { ... } child = { parent_group_id = module.amazon_connect.user_hierarchy_groups["parent"].hierarchy_group_id } } } ``` ✔️ Valid example: ```hcl module "amazon_connect" { ... user_hierarchy_groups = { child = { parent_group_id = try(module.amazon_connect_parent_group.user_hierarchy_groups["parent"].hierarchy_group_id, null) } } } module "amazon_connect_parent_group" { ... create_instance = false instance_id = module.amazon_connect.instance.id user_hierarchy_groups = { parent = {} } } ``` ## Creating/Exporting Contact Flow JSON Terraform and the Amazon Connect API expect Contact Flows and Contact Flow Modules to be provided in JSON format. Currently, the easiest way to do that is to first create the Contact Flow in the Amazon Connect management console as desired, and then retrieve the JSON format using the AWS CLI or AWS Tools for PowerShell. AWS CLI: ```shell aws connect describe-contact-flow --instance-id --contact-flow-id aws connect describe-contact-flow-module --instance-id --contact-flow-id ``` AWS Tools for PowerShell ```powershell Get-CONNContactFlow -ContactFlowId -InstanceId Get-CONNContactFlowModule -ContactFlowId -InstanceId ``` ## Module Outputs With the exception of `instance_id`, which returns the Amazon Connect Instance ID that was created or passed in, all outputs of this module return the entire resource, or collection or resources. This methodology allows the consumer of the module to access all resource attributes created, but does require some HCL if you'd like to transform it to a different structure. As an example, if you want to get a list of the queue ARNs: ```hcl module "amazon_connect" { ... } locals { queue_arns = [ for k, v in module.amazon_connect.queues : v.arn ] } ``` ## License Apache 2 Licensed. See [LICENSE](./LICENSE) for full details. ## Requirements | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.2 | | [aws](#requirement\_aws) | >= 4.26 | ## Providers | Name | Version | |------|---------| | [aws](#provider\_aws) | >= 4.26 | ## Modules No modules. ## Resources | Name | Type | |------|------| | [aws_connect_bot_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_bot_association) | resource | | [aws_connect_contact_flow.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_contact_flow) | resource | | [aws_connect_contact_flow_module.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_contact_flow_module) | resource | | [aws_connect_hours_of_operation.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_hours_of_operation) | resource | | [aws_connect_instance.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_instance) | resource | | [aws_connect_instance_storage_config.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_instance_storage_config) | resource | | [aws_connect_lambda_function_association.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_lambda_function_association) | resource | | [aws_connect_queue.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_queue) | resource | | [aws_connect_quick_connect.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_quick_connect) | resource | | [aws_connect_routing_profile.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_routing_profile) | resource | | [aws_connect_security_profile.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_security_profile) | resource | | [aws_connect_user.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_user) | resource | | [aws_connect_user_hierarchy_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_user_hierarchy_group) | resource | | [aws_connect_user_hierarchy_structure.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_user_hierarchy_structure) | resource | | [aws_connect_vocabulary.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_vocabulary) | resource | ## Inputs | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [bot\_associations](#input\_bot\_associations) | A map of Amazon Connect Lex Bot Associations.

The key of the map is the Lex Bot `name`. The value is the configuration for that Lex Bot, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_bot_association) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
name = string
lex_region = optional(string)
}
}
| `any` | `{}` | no | | [contact\_flow\_module\_tags](#input\_contact\_flow\_module\_tags) | Additional tags to add to all Contact Flow Module resources. | `map(string)` | `{}` | no | | [contact\_flow\_modules](#input\_contact\_flow\_modules) | A map of Amazon Connect Contact Flow Modules.

The key of the map is the Contact Flow Module `name`. The value is the configuration for that Contact Flow, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_contact_flow_module) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
content = optional(string) # one required
content_hash = optional(string) # one required
description = optional(string)
filename = optional(string) # one required
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [contact\_flow\_tags](#input\_contact\_flow\_tags) | Additional tags to add to all Contact Flow resources. | `map(string)` | `{}` | no | | [contact\_flows](#input\_contact\_flows) | A map of Amazon Connect Contact Flows.

The key of the map is the Contact Flow `name`. The value is the configuration for that Contact Flow, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_contact_flow) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
content = optional(string) # one required
content_hash = optional(string) # one required
description = optional(string)
filename = optional(string) # one required
tags = optional(map(string))
type = optional(string)
}
}
| `any` | `{}` | no | | [create\_instance](#input\_create\_instance) | Controls if the aws\_connect\_instance resource should be created. Defaults to true. | `bool` | `true` | no | | [hours\_of\_operations](#input\_hours\_of\_operations) | A map of Amazon Connect Hours of Operations.

The key of the map is the Hours of Operation `name`. The value is the configuration for that Hours of Operation, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_hours_of_operation) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
config = [
{
day = string
end_time = {
hours = number
minutes = number
}
start_time = {
hours = number
minutes = number
}
}
]
description = optional(string)
tags = optional(map(string))
time_zone = string
}
}
| `any` | `{}` | no | | [hours\_of\_operations\_tags](#input\_hours\_of\_operations\_tags) | Additional tags to add to all Hours of Operations resources. | `map(string)` | `{}` | no | | [instance\_alias](#input\_instance\_alias) | Specifies the name of the instance. Required if instance\_directory\_id not specified. | `string` | `null` | no | | [instance\_auto\_resolve\_best\_voices\_enabled](#input\_instance\_auto\_resolve\_best\_voices\_enabled) | Specifies whether auto resolve best voices is enabled. Defaults to true. | `bool` | `null` | no | | [instance\_contact\_flow\_logs\_enabled](#input\_instance\_contact\_flow\_logs\_enabled) | Specifies whether contact flow logs are enabled. Defaults to false. | `bool` | `null` | no | | [instance\_contact\_lens\_enabled](#input\_instance\_contact\_lens\_enabled) | Specifies whether contact lens is enabled. Defaults to true. | `bool` | `null` | no | | [instance\_directory\_id](#input\_instance\_directory\_id) | The identifier for the directory if instance\_identity\_management\_type is EXISTING\_DIRECTORY. | `string` | `null` | no | | [instance\_early\_media\_enabled](#input\_instance\_early\_media\_enabled) | Specifies whether early media for outbound calls is enabled. Defaults to true if instance\_outbound\_calls\_enabled is true. | `bool` | `null` | no | | [instance\_id](#input\_instance\_id) | If create\_instance is set to false, you may still create other resources and pass in an instance ID that was created outside this module. Ignored if create\_instance is true. | `string` | `null` | no | | [instance\_identity\_management\_type](#input\_instance\_identity\_management\_type) | Specifies the identity management type attached to the instance. Allowed values are: SAML, CONNECT\_MANAGED, EXISTING\_DIRECTORY. | `string` | `null` | no | | [instance\_inbound\_calls\_enabled](#input\_instance\_inbound\_calls\_enabled) | Specifies whether inbound calls are enabled. | `bool` | `null` | no | | [instance\_outbound\_calls\_enabled](#input\_instance\_outbound\_calls\_enabled) | Specifies whether outbound calls are enabled. | `bool` | `null` | no | | [instance\_storage\_configs](#input\_instance\_storage\_configs) | A map of Amazon Connect Instance Storage Configs.

The key of the map is the Instance Storage Config `resource_type`. The value is the configuration for that Instance Storage Config, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_instance_storage_config#storage_config) (except `resource_type` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
kinesis_firehose_config = optional({
firehose_arn = string
})
kinesis_stream_config = optional({
stream_arn = string
})
kinesis_video_stream_config = optional({
encryption_config = {
encryption_type = string
key_id = string
}
prefix = string
retention_period_hours = number
})
s3_config = optional({
bucket_name = string
bucket_prefix = string
encryption_config = optional({
encryption_type = string
key_id = string
})
})
storage_type = string
}
}
| `any` | `{}` | no | | [lambda\_function\_associations](#input\_lambda\_function\_associations) | A map of Lambda Function ARNs to associate to the Amazon Connect Instance, the key is a static/arbitrary name and value is the Lambda ARN.

Example/available options:
{
= string
}
| `map(string)` | `{}` | no | | [queue\_tags](#input\_queue\_tags) | Additional tags to add to all Queue resources. | `map(string)` | `{}` | no | | [queues](#input\_queues) | A map of Amazon Connect Queues.

The key of the map is the Queue `name`. The value is the configuration for that Queue, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_queue) (except `name` which is the key, and `instance_id which` is created or passed in).

Example/available options:
{
= {
description = optional(string)
hours_of_operation_id = string
max_contacts = optional(number)
outbound_caller_config = optional({
outbound_caller_id_name = optional(string)
outbound_caller_id_number_id = optional(string)
outbound_flow_id = optional(string)
})
quick_connect_ids = optional(list(string))
status = optional(string)
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [quick\_connect\_tags](#input\_quick\_connect\_tags) | Additional tags to add to all Quick Connect resources. | `map(string)` | `{}` | no | | [quick\_connects](#input\_quick\_connects) | A map of Amazon Connect Quick Connect.

The key of the map is the Quick Connect `name`. The value is the configuration for that Quick Connect, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_quick_connect) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
description = optional(string)
quick_connect_config = {
quick_connect_type = string
phone_config = optional({
phone_number = string
})
queue_config = optional({
contact_flow_id = string
queue_id = string
})
user_config = optional({
contact_flow_id = string
queue_id = string
})
})
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [routing\_profile\_tags](#input\_routing\_profile\_tags) | Additional tags to add to all Routing Profile resources. | `map(string)` | `{}` | no | | [routing\_profiles](#input\_routing\_profiles) | A map of Amazon Connect Routing Profile.

The key of the map is the Routing Profile `name`. The value is the configuration for that Routing Profile, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_routing_profile) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
default_outbound_queue_id = string
description = string
media_concurrencies = [
{
channel = string
concurrency = number
}
]
queue_configs = optional([
{
channel = string
delay = number
priority = number
queue_id = string
}
])
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [security\_profile\_tags](#input\_security\_profile\_tags) | Additional tags to add to all Security Profile resources. | `map(string)` | `{}` | no | | [security\_profiles](#input\_security\_profiles) | A map of Amazon Connect Security Profile.

The key of the map is the Security Profile `name`. The value is the configuration for that Security Profile, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_security_profile) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
description = optional(string)
permissions = optional(list(string))
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [tags](#input\_tags) | A map of tags to add to all resources. | `map(string)` | `{}` | no | | [user\_hierarchy\_group\_tags](#input\_user\_hierarchy\_group\_tags) | Additional tags to add to all User Hierarchy Group resources. | `map(string)` | `{}` | no | | [user\_hierarchy\_groups](#input\_user\_hierarchy\_groups) | A map of Amazon Connect User Hierarchy Groups.

The key of the map is the User Hierarchy Group `name`. The value is the configuration for that User, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_user_hierarchy_group) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
parent_group_id = optional(string)
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [user\_hierarchy\_structure](#input\_user\_hierarchy\_structure) | A map of Amazon Connect User Hierarchy Structure, containing keys for for zero or many levels: `level_one`, `level_two`, `level_three`, `level_four`, and `level_five`. The values are the `name` for that level. See [documentation here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_user_hierarchy_structure).

Example/available options:
{
level_one = string
}
| `map(string)` | `{}` | no | | [user\_tags](#input\_user\_tags) | Additional tags to add to all User resources. | `map(string)` | `{}` | no | | [users](#input\_users) | A map of Amazon Connect Users.

The key of the map is the User `name`. The value is the configuration for that User, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_user) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
directory_user_id = optional(string)
hierarchy_group_id = optional(string)
identity_info = optional({
email = optional(string)
first_name = optional(string)
last_name = optional(string)
})
password = optional(string)
phone_config = {
phone_type = string
after_contact_work_time_limit = optional(number)
auto_accept = optional(bool)
desk_phone_number = optional(string)
}
routing_profile_id = string
security_profile_ids = list(string)
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [vocabularies](#input\_vocabularies) | A map of Amazon Connect Vocabularies.

The key of the map is the Vocabulary `name`. The value is the configuration for that Vocabulary, supporting all arguments [documented here](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/connect_vocabulary) (except `name` which is the key, and `instance_id` which is created or passed in).

Example/available options:
{
= {
content = string
language_code = string
tags = optional(map(string))
}
}
| `any` | `{}` | no | | [vocabulary\_tags](#input\_vocabulary\_tags) | Additional tags to add to all Vocabulary resources. | `map(string)` | `{}` | no | ## Outputs | Name | Description | |------|-------------| | [bot\_associations](#output\_bot\_associations) | Full output attributes of aws\_connect\_bot\_association resource(s). | | [contact\_flow\_modules](#output\_contact\_flow\_modules) | Full output attributes of aws\_connect\_contact\_flow\_module resource(s). | | [contact\_flows](#output\_contact\_flows) | Full output attributes of aws\_connect\_contact\_flow resource(s). | | [hours\_of\_operations](#output\_hours\_of\_operations) | Full output attributes of aws\_connect\_hours\_of\_operation resource(s). | | [instance](#output\_instance) | Full output attributes of aws\_connect\_instance resource. | | [instance\_id](#output\_instance\_id) | Amazon Connect instance ID. If create\_instance = false, var.instance\_id is returned. | | [instance\_storage\_configs](#output\_instance\_storage\_configs) | Full output attributes of aws\_connect\_instance\_storage\_config resource(s). | | [lambda\_function\_associations](#output\_lambda\_function\_associations) | Full output attributes of aws\_connect\_lambda\_function\_association resource(s). | | [queues](#output\_queues) | Full output attributes of aws\_connect\_queue resource(s). | | [quick\_connects](#output\_quick\_connects) | Full output attributes of aws\_connect\_quick\_connect resource(s). | | [routing\_profiles](#output\_routing\_profiles) | Full output attributes of aws\_connect\_routing\_profile resource(s). | | [security\_profiles](#output\_security\_profiles) | Full output attributes of aws\_connect\_security\_profile resource(s). | | [user\_hierarchy\_groups](#output\_user\_hierarchy\_groups) | Full output attributes of aws\_connect\_user\_hierarchy\_group resource(s). | | [user\_hierarchy\_structure](#output\_user\_hierarchy\_structure) | Full output attributes of aws\_connect\_user\_hierarchy\_structure resource(s). | | [users](#output\_users) | Full output attributes of aws\_connect\_user resource(s). | | [vocabularies](#output\_vocabularies) | Full output attributes of aws\_connect\_vocabulary resource(s). |