Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numeric comparisons for versions #20383

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions aws/resource_aws_lex_bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"regexp"
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down
19 changes: 17 additions & 2 deletions aws/resource_aws_lex_intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"regexp"
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down