From 4bc2807637ede8cc4d813bff195cd95740e2d941 Mon Sep 17 00:00:00 2001 From: Brent Woodruff Date: Fri, 30 Jul 2021 17:47:21 -0400 Subject: [PATCH 1/3] numeric comparisons for versions --- aws/resource_aws_lex_bot.go | 19 +++++++++++++++++-- aws/resource_aws_lex_intent.go | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/aws/resource_aws_lex_bot.go b/aws/resource_aws_lex_bot.go index 828da35e1f0..0d99cac4018 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" @@ -442,6 +443,7 @@ func resourceAwsLexBotDelete(d *schema.ResourceData, meta interface{}) error { func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetBotVersionsInput) (string, error) { version := LexBotVersionLatest + var currentVersion, botVersion int for { page, err := conn.GetBotVersions(input) if err != nil { @@ -457,8 +459,21 @@ func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingServic if *bot.Version == LexBotVersionLatest { continue } - if *bot.Version > version { - version = *bot.Version + + currentVersion, err = strconv.Atoi(version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Bot: %s", version) + continue + } + + botVersion, err = strconv.Atoi(*bot.Version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Bot: %s", *bot.Version) + continue + } + + if botVersion > currentVersion { + version = strconv.Itoa(botVersion) } } diff --git a/aws/resource_aws_lex_intent.go b/aws/resource_aws_lex_intent.go index 767d3c78756..558b968aeb8 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" @@ -611,6 +612,7 @@ var lexStatementResource = &schema.Resource{ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetIntentVersionsInput) (string, error) { version := LexIntentVersionLatest + var currentVersion, intentVersion int for { page, err := conn.GetIntentVersions(input) if err != nil { @@ -626,8 +628,21 @@ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingSer if *intent.Version == LexIntentVersionLatest { continue } - if *intent.Version > version { - version = *intent.Version + + currentVersion, err = strconv.Atoi(version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Intent: %s", version) + continue + } + + intentVersion, err = strconv.Atoi(*intent.Version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Intent: %s", *intent.Version) + continue + } + + if intentVersion > currentVersion { + version = strconv.Itoa(intentVersion) } } From c4d955ce03c3ce92c334db870a69b73511ae5076 Mon Sep 17 00:00:00 2001 From: Brent Woodruff Date: Fri, 30 Jul 2021 17:57:46 -0400 Subject: [PATCH 2/3] formatting --- aws/resource_aws_lex_bot.go | 24 ++++++++++++------------ aws/resource_aws_lex_intent.go | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/aws/resource_aws_lex_bot.go b/aws/resource_aws_lex_bot.go index 0d99cac4018..172efca3137 100644 --- a/aws/resource_aws_lex_bot.go +++ b/aws/resource_aws_lex_bot.go @@ -443,7 +443,7 @@ func resourceAwsLexBotDelete(d *schema.ResourceData, meta interface{}) error { func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetBotVersionsInput) (string, error) { version := LexBotVersionLatest - var currentVersion, botVersion int + var currentVersion, botVersion int for { page, err := conn.GetBotVersions(input) if err != nil { @@ -460,17 +460,17 @@ func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingServic continue } - currentVersion, err = strconv.Atoi(version) - if err != nil { - log.Printf("[DEBUG] invalid version for Lex Bot: %s", version) - continue - } - - botVersion, err = strconv.Atoi(*bot.Version) - if err != nil { - log.Printf("[DEBUG] invalid version for Lex Bot: %s", *bot.Version) - continue - } + currentVersion, err = strconv.Atoi(version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Bot: %s", version) + continue + } + + botVersion, err = strconv.Atoi(*bot.Version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Bot: %s", *bot.Version) + continue + } if botVersion > currentVersion { version = strconv.Itoa(botVersion) diff --git a/aws/resource_aws_lex_intent.go b/aws/resource_aws_lex_intent.go index 558b968aeb8..acf7d6fafbc 100644 --- a/aws/resource_aws_lex_intent.go +++ b/aws/resource_aws_lex_intent.go @@ -612,7 +612,7 @@ var lexStatementResource = &schema.Resource{ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetIntentVersionsInput) (string, error) { version := LexIntentVersionLatest - var currentVersion, intentVersion int + var currentVersion, intentVersion int for { page, err := conn.GetIntentVersions(input) if err != nil { @@ -629,17 +629,17 @@ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingSer continue } - currentVersion, err = strconv.Atoi(version) - if err != nil { - log.Printf("[DEBUG] invalid version for Lex Intent: %s", version) - continue - } - - intentVersion, err = strconv.Atoi(*intent.Version) - if err != nil { - log.Printf("[DEBUG] invalid version for Lex Intent: %s", *intent.Version) - continue - } + currentVersion, err = strconv.Atoi(version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Intent: %s", version) + continue + } + + intentVersion, err = strconv.Atoi(*intent.Version) + if err != nil { + log.Printf("[DEBUG] invalid version for Lex Intent: %s", *intent.Version) + continue + } if intentVersion > currentVersion { version = strconv.Itoa(intentVersion) From ba8bcb4678f1683ff2405a55699670a6731cb71a Mon Sep 17 00:00:00 2001 From: Brent Woodruff Date: Mon, 2 Aug 2021 12:58:10 -0400 Subject: [PATCH 3/3] make get latest version return latest version --- aws/resource_aws_lex_bot.go | 16 +++++----------- aws/resource_aws_lex_intent.go | 16 +++++----------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/aws/resource_aws_lex_bot.go b/aws/resource_aws_lex_bot.go index 172efca3137..4d15747d15d 100644 --- a/aws/resource_aws_lex_bot.go +++ b/aws/resource_aws_lex_bot.go @@ -441,9 +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 currentVersion, botVersion int + var botVersion int for { page, err := conn.GetBotVersions(input) if err != nil { @@ -460,20 +460,14 @@ func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingServic continue } - currentVersion, err = strconv.Atoi(version) - if err != nil { - log.Printf("[DEBUG] invalid version for Lex Bot: %s", version) - continue - } - botVersion, err = strconv.Atoi(*bot.Version) if err != nil { log.Printf("[DEBUG] invalid version for Lex Bot: %s", *bot.Version) continue } - if botVersion > currentVersion { - version = strconv.Itoa(botVersion) + if botVersion > version { + version = botVersion } } @@ -483,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 acf7d6fafbc..d1fdbdc159d 100644 --- a/aws/resource_aws_lex_intent.go +++ b/aws/resource_aws_lex_intent.go @@ -610,9 +610,9 @@ var lexStatementResource = &schema.Resource{ } func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetIntentVersionsInput) (string, error) { - version := LexIntentVersionLatest + version := 0 - var currentVersion, intentVersion int + var intentVersion int for { page, err := conn.GetIntentVersions(input) if err != nil { @@ -629,20 +629,14 @@ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingSer continue } - currentVersion, err = strconv.Atoi(version) - if err != nil { - log.Printf("[DEBUG] invalid version for Lex Intent: %s", version) - continue - } - intentVersion, err = strconv.Atoi(*intent.Version) if err != nil { log.Printf("[DEBUG] invalid version for Lex Intent: %s", *intent.Version) continue } - if intentVersion > currentVersion { - version = strconv.Itoa(intentVersion) + if intentVersion > version { + version = intentVersion } } @@ -652,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{}) {