Terraform script to create aws lexbot exception BadRequestException: The resource 'FallbackIntent' referenced

182 Views Asked by At

I wrote terraform script to create a lexbot in AWS. It is a very simple script. name, child_directed, abort_statment, intent are "Required" attributes for the "aws_lex_bot" resource.

It somehow throws error about the "intent" attribute Error: creating Lex Bot (Chat_AutoReply): BadRequestException: The resource 'FallbackIntent' referenced in resource 'Chat_AutoReply' was not found. Choose another resource.

   resource "aws_lex_bot" "chatbot-autoreply" {        
              name = "Chat_AutoReply"
              child_directed = false
              abort_statement {
                  message {
                      content_type = "PlainText"
                      content      = "Script aborted refer abort_statement"
                  }         
              }
              intent {
                   intent_name    = "FallbackIntent"
                   intent_version = "1"
              }
      }
1

There are 1 best solutions below

0
Marcin On

You have to create aws_lex_intent and then use that in aws_lex_bot, e.g.:

resource "aws_lex_intent" "fallback" {
   ...
}

resource "aws_lex_bot" "chatbot-autoreply" {        
              name = "Chat_AutoReply"
              child_directed = false
              abort_statement {
                  message {
                      content_type = "PlainText"
                      content      = "Script aborted refer abort_statement"
                  }         
              }
              intent {
                   intent_name    = aws_lex_intent.fallback.name
                   intent_version = "1"
              }
      }