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

fix: compare version with integers, handle first page logic #21049

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 20 additions & 9 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 @@ -440,25 +441,32 @@ func resourceAwsLexBotDelete(d *schema.ResourceData, meta interface{}) error {
}

func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetBotVersionsInput) (string, error) {
version := LexBotVersionLatest

version := 0
for {
page, err := conn.GetBotVersions(input)

if err != nil {
return "", err
}

// At least 1 version will always be returned.
if len(page.Bots) == 1 {
// Only test for more than one item in response on the first page
if len(page.Bots) == 1 && input.NextToken == nil {
break
}

for _, bot := range page.Bots {
if *bot.Version == LexBotVersionLatest {
continue
}
if *bot.Version > version {
version = *bot.Version

// Convert the string version to integer for compare
compareVersion, err := strconv.Atoi(*bot.Version)

if err != nil {
return "", err
}

if compareVersion > version {
version = compareVersion
}
}

Expand All @@ -467,8 +475,11 @@ func getLatestLexBotVersion(conn *lexmodelbuildingservice.LexModelBuildingServic
}
input.NextToken = page.NextToken
}

return version, nil
if version > 0 {
returnVersion := strconv.Itoa(version)
return returnVersion, nil
}
return LexBotVersionLatest, nil
}

func flattenLexIntents(intents []*lexmodelbuildingservice.Intent) (flattenedIntents []map[string]interface{}) {
Expand Down
27 changes: 19 additions & 8 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 @@ -609,25 +610,32 @@ var lexStatementResource = &schema.Resource{
}

func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingService, input *lexmodelbuildingservice.GetIntentVersionsInput) (string, error) {
version := LexIntentVersionLatest

version := 0
for {
page, err := conn.GetIntentVersions(input)

if err != nil {
return "", err
}

// At least 1 version will always be returned.
if len(page.Intents) == 1 {
// Only test for more than one item in response on the first page
if len(page.Intents) == 1 && input.NextToken == nil {
break
}

for _, intent := range page.Intents {
if *intent.Version == LexIntentVersionLatest {
continue
}
if *intent.Version > version {
version = *intent.Version
// Convert the string version to integer for compare
compareVersion, err := strconv.Atoi(*intent.Version)

if err != nil {
return "", err
}

if compareVersion > version {
version = compareVersion
}
}

Expand All @@ -636,8 +644,11 @@ func getLatestLexIntentVersion(conn *lexmodelbuildingservice.LexModelBuildingSer
}
input.NextToken = page.NextToken
}

return version, nil
if version > 0 {
returnVersion := strconv.Itoa(version)
return returnVersion, nil
}
return LexBotVersionLatest, nil
}

func flattenLexCodeHook(hook *lexmodelbuildingservice.CodeHook) (flattened []map[string]interface{}) {
Expand Down