hashicorp / terraform-provider-awscc

Terraform AWS Cloud Control provider
https://registry.terraform.io/providers/hashicorp/awscc/latest/docs
Mozilla Public License 2.0
240 stars 107 forks source link

Long deploy time for Lex bot and validation errors #548

Open joelzhuang opened 2 years ago

joelzhuang commented 2 years ago

Community Note

Terraform CLI and Terraform AWS Cloud Control Provider Version

Terraform v1.2.2 on linux_amd64

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

terraform {
  required_providers {
    #
    awscc = {
      source  = "hashicorp/awscc"
      version = "0.24.0"
    }
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.17"
    }
  }
}

# Configure the AWS Provider
provider "awscc" {
  region = "ap-southeast-2"
}
provider "aws" {
  region = "ap-southeast-2"
}

# Lex variables
variable "nlu_confidence_threshold" {
  description = "nlu_confidence_threshold"
  type        = number
  default     = 0.5
}

# Create my first bot (empty)
resource "awscc_lex_bot" "demo_lexv2_bot" {
  name     = "testBot"
  # role_arn = aws_iam_service_linked_role.lex_service_role.arn
  role_arn = "arn:aws:iam::<account-id>:role/aws-service-role/lexv2.amazonaws.com/AWSServiceRoleForLexV2Bots"
  data_privacy = {
    child_directed = false
  }
  idle_session_ttl_in_seconds = 300
  bot_locales = [
    {
      locale_id                = "en_AU"
      nlu_confidence_threshold = var.nlu_confidence_threshold
      slot_types = [
        {
          name = "Slot1"
          slot_type_values = [
            {
              sample_value = {
                value="test"
              }
            }
          ],
          value_selection_setting = {
            resolution_strategy = "ORIGINAL_VALUE"
          }
        }
      ],
      intents = [
        {
          name        = "testIntent"
          description = "test description"
          sample_utterances = [
            {
              utterance = "hello"
            },
            {
              utterance = "hi"
            }
          ]
          slots = [
            {
              name           = "SlotIntent1"
              slot_type_name = "Slot1"
              value_elicitation_setting = {
                slot_constraint = "Required"
                prompt_specification = {
                  max_retries = 1
                  message_groups_list = [
                    {
                      message = {
                        plain_text_message = {
                          value = "I need a slot thanks"
                        }
                      }
                    }
                  ]
                }
              }
            }
          ]
        },
        {
          name                    = "FallbackIntent"
          description             = "test description"
          parent_intent_signature = "AMAZON.FallbackIntent"
          # sample_utterances = [
          #   {
          #     utterance = "test"
          #   }
          # ]
          slots = [
            {
              name           = "fallbackSlot"
              slot_type_name = "Slot1"
              value_elicitation_setting = {
                slot_constraint = "Required"
                prompt_specification = {
                  max_retries = 1
                  message_groups_list = [
                    {
                      message = {
                        plain_text_message = {
                          value = "I need a slot thanks"
                        }
                      }
                    }
                  ]
                }
              }
            }
          ]
        }
      ]
    },
  ]

}

Debug Output

│ Error: AWS SDK Go Service Operation Incomplete
│ 
│   with awscc_lex_bot.demo_lexv2_bot,
│   on main.tf line 39, in resource "awscc_lex_bot" "demo_lexv2_bot":
│   39: resource "awscc_lex_bot" "demo_lexv2_bot" {
│ 
│ Waiting for Cloud Control API service CreateResource operation completion
│ returned: waiter state transitioned to FAILED. StatusMessage: Importing
│ 3bottest3 failed due to [Unable to create or update Slot that extends a
│ builtin intent of type AMAZON.FallbackIntent.]. The import could not be
│ completed.. ErrorCode: InvalidRequest
╵

Note: I've created another issue regarding why I added slots to the fallback intent https://github.com/hashicorp/terraform-provider-awscc/issues/547

Expected Behavior

Deploy the LexV2 bot within a reasonable timeframe (minutes)

Actual Behavior

LexV2 bot with 2 intents, one custom slot type and one slot takes more than an hour to deploy, often resulting in an error at the end, either because the credentials expire, or the error mentioned above.

It seems the deployment takes a long time after the slots attribute is added to the intent. (I've also done tests with slot_types without slots, and it deploys fine)

Steps to Reproduce

  1. terraform apply
hs79hs commented 2 years ago

Have the same issue, we're urgent in our project to implement this, could someone please help? Thanks

When creating a bot without slots, it's fast, less than 30 seconds. Then after adding 1 slot, terraform validate turns to very slow, took several minutes, terraform apply is only showing this after ~10 minutes

awscc_lex_bot.demo_lexv2_bot: Refreshing state... [id=4H7KKR8QAY]
ronilp1 commented 1 year ago

Is there an update on this ticket. No assignees to this ticket still

gevial commented 1 year ago

I had something similar, the deploy time was not hour but still 5 minutes for a simple change or so, and during Refreshing state CPU usage of terraform-awscc-provider went up to 140%... macOS 12.5

phill0555 commented 1 year ago

Having very similar issues. Deploy terraform a lot with no issues. Started using the AWSCC provider to deploy a Lex bot. Facing very long state refresh times and sporadically long deploy times. Any update on this issue? Would love to know if I should just stop using it for now?

Trying to decide whether the project should start using the AWSCC provider for other resource deployments.

hnryjms commented 8 months ago

Same thing here.

I decided to just replace awscc with a regular aws_cloudformation_stack resource and write it all inside a jsonencode() since LexV2 can be deployed that way too, and it's a lot faster at determining the differences.