diff --git a/aws/resource_aws_lex_bot.go b/aws/resource_aws_lex_bot.go index 828da35e1f0e..4d15747d15d0 100644 --- a/aws/resource_aws_lex_bot.go +++ b/aws/resource_aws_lex_bot.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "regexp" + "strconv" "time" "github.com/aws/aws-sdk-go/aws" @@ -440,8 +441,9 @@ func resourceAwsLexBotDelete(d *schema.ResourceData, meta interface{}) error { } func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetBotVersionsInput) (string, error) { - version := LexBotVersionLatest + version := 0 + var botVersion int for { page, err := conn.GetBotVersions(input) if err != nil { @@ -457,8 +459,15 @@ func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingServic if *bot.Version == LexBotVersionLatest { continue } - if *bot.Version > version { - version = *bot.Version + + botVersion, err = strconv.Atoi(*bot.Version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Bot: %s", *bot.Version) + continue + } + + if botVersion > version { + version = botVersion } } @@ -468,7 +477,7 @@ func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingServic input.NextToken = page.NextToken } - return version, nil + return strconv.Itoa(version), nil } func flattenLexIntents(intents []*lexmodelbuildingservice.Intent) (flattenedIntents []map[string]interface{}) { diff --git a/aws/resource_aws_lex_intent.go b/aws/resource_aws_lex_intent.go index 767d3c787563..d1fdbdc159d5 100644 --- a/aws/resource_aws_lex_intent.go +++ b/aws/resource_aws_lex_intent.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "regexp" + "strconv" "time" "github.com/aws/aws-sdk-go/aws" @@ -609,8 +610,9 @@ var lexStatementResource = &schema.Resource{ } func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetIntentVersionsInput) (string, error) { - version := LexIntentVersionLatest + version := 0 + var intentVersion int for { page, err := conn.GetIntentVersions(input) if err != nil { @@ -626,8 +628,15 @@ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingSer if *intent.Version == LexIntentVersionLatest { continue } - if *intent.Version > version { - version = *intent.Version + + intentVersion, err = strconv.Atoi(*intent.Version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Intent: %s", *intent.Version) + continue + } + + if intentVersion > version { + version = intentVersion } } @@ -637,7 +646,7 @@ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingSer input.NextToken = page.NextToken } - return version, nil + return strconv.Itoa(version), nil } func flattenLexCodeHook(hook *lexmodelbuildingservice.CodeHook) (flattened []map[string]interface{}) {