Closed GRA0007 closed 8 months ago
Voting for Prioritization
Volunteering to Work on This Issue
For anyone landing here looking for how to fully create a Lex bot with Terraform, I've created a workaround using the AWS CLI until it's officially supported. Note that I tried using awscc_lex_bot_alias, but this had other issues, where it would hang if the alias already existed.
my_bot.tf
```tf data "aws_partition" "current" {} # IAM role for the bot resource "aws_iam_role" "my_bot" { name = "MyBotRole" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [ { Action = "sts:AssumeRole" Effect = "Allow" Sid = "" Principal = { Service = "lexv2.amazonaws.com" } }, ] }) } resource "aws_iam_role_policy_attachment" "my_bot" { role = aws_iam_role.my_bot.name policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonLexFullAccess" } resource "aws_lexv2models_bot" "my_bot" { name = "MyBot" idle_session_ttl_in_seconds = 1200 # 20 minutes role_arn = aws_iam_role.my_bot.arn data_privacy { child_directed = false } } resource "aws_lexv2models_bot_locale" "my_bot" { bot_id = aws_lexv2models_bot.my_bot.id bot_version = "DRAFT" locale_id = "en_US" n_lu_intent_confidence_threshold = 0.40 # Update default fallback to enable lambda hook provisioner "local-exec" { command = "aws lexv2-models update-intent --bot-id ${aws_lexv2models_bot.my_bot.id} --locale-id ${aws_lexv2models_bot_locale.my_bot.locale_id} --bot-version DRAFT --intent-id FALLBCKINT --intent-name FallbackIntent --parent-intent-signature=AMAZON.FallbackIntent --dialog-code-hook enabled=true --region ${var.aws_region}" } } resource "aws_lexv2models_intent" "my_bot" { bot_id = aws_lexv2models_bot.my_bot.id bot_version = aws_lexv2models_bot_locale.my_bot.bot_version locale_id = aws_lexv2models_bot_locale.my_bot.locale_id name = "HelloIntent" dialog_code_hook { enabled = true } sample_utterance { utterance = "Hello" } sample_utterance { utterance = "Howdy" } } # This builds the bot after creating an intent resource "null_resource" "my_bot_build" { depends_on = [aws_lexv2models_intent.my_bot] triggers = { bot_id = aws_lexv2models_bot.my_bot.id locale_id = aws_lexv2models_bot_locale.my_bot.locale_id intent = aws_lexv2models_intent.my_bot.sample_utterance } provisioner "local-exec" { command = "./build_bot.sh ${aws_lexv2models_bot.my_bot.id} ${aws_lexv2models_bot_locale.my_bot.locale_id}" } } # Create a version after building resource "aws_lexv2models_bot_version" "my_bot" { depends_on = [null_resource.my_bot_build] bot_id = aws_lexv2models_bot.my_bot.id locale_specification = { (aws_lexv2models_bot_locale.my_bot.locale_id) = { source_bot_version = aws_lexv2models_bot_locale.my_bot.bot_version } } } # Create or update an alias after creating a new version resource "null_resource" "my_bot_alias" { depends_on = [aws_lexv2models_bot_version.my_bot] triggers = { bot_id = aws_lexv2models_bot.my_bot.id locale_id = aws_lexv2models_bot_locale.my_bot.locale_id latest_version = aws_lexv2models_bot_version.my_bot.bot_version lambda_arn = example.lambda.arn logs_arn = example.cloudwatch.arn } provisioner "local-exec" { command = "./upsert_bot_alias.sh ${aws_lexv2models_bot.my_bot.id} ${aws_lexv2models_bot_locale.my_bot.locale_id} ${aws_lexv2models_bot_version.my_bot.bot_version} '${example.lambda.arn}' '${example.cloudwatch.arn}'" } } ```
And then, the two scripts that I use to build the bot, and upsert the bot alias:
build_bot.sh
```bash
#!/bin/bash
# Usage: ./build_bot.sh
upsert_bot_alias.sh
```bash
#!/bin/bash
# Usage: ./upsert_bot_alias.sh
In this example you can see I am enabling chat logs and associating a lambda function with my bot alias as well.
Hey @GRA0007 👋 Thank you for taking the time to raise this! It looks like one of our engineers has already opened an issue tracking the need to add this to the provider, so I'm going to close this one as a duplicate. If you'd like to be notified of any further actions, I'd recommend keeping an eye on that issue.
Duplicate of #35780
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Description
This issue prompted support for initial Lex v2 resources, however as they currently stand, are not enough to fully create a Lex v2 bot using Terraform.
I am requesting a way to create bot aliases, including associating lambda functions with bot alias language support.
Additionally, I may be misunderstanding (the docs need to be fleshed out), but I don't believe there's currently any way to build the bot.
Finally, the documentation is also lacking on this regard, but I can't find a way to edit the preexisting
FallbackIntent
provided by AWS when creating a bot. Specifically, I'd like a way to enable thedialog_code_hook
.Affected Resource(s) and/or Data Source(s)
aws_lexv2models_bot_alias
Potential Terraform Configuration
References
API docs for creating an alias: https://docs.aws.amazon.com/lexv2/latest/APIReference/API_CreateBotAlias.html
Would you like to implement a fix?
No