-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21122 from abebars/b-aws_lex-building-state
Added proper status and waiter to Lex Bot. Fixed issues with import tests.
- Loading branch information
Showing
15 changed files
with
377 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
```release-note:bug | ||
aws/resource_aws_lex_bot: Correctly determine `version` attribute | ||
``` | ||
|
||
```release-note:bug | ||
aws/resource_aws_lex_intent: Correctly determine `version` attribute | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:enhancement | ||
resource/aws_lex_bot: Added waiter support to account for `BUILDING` status | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package lex | ||
|
||
const ( | ||
LexBotVersionLatest = "$LATEST" | ||
LexIntentVersionLatest = "$LATEST" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package finder | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/lexmodelbuildingservice" | ||
"github.com/hashicorp/aws-sdk-go-base/tfawserr" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
tflex "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/lex" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" | ||
) | ||
|
||
func BotVersionByName(conn *lexmodelbuildingservice.LexModelBuildingService, name, version string) (*lexmodelbuildingservice.GetBotOutput, error) { | ||
input := &lexmodelbuildingservice.GetBotInput{ | ||
Name: aws.String(name), | ||
VersionOrAlias: aws.String(version), | ||
} | ||
|
||
output, err := conn.GetBot(input) | ||
|
||
if tfawserr.ErrCodeEquals(err, lexmodelbuildingservice.ErrCodeNotFoundException) { | ||
return nil, &resource.NotFoundError{ | ||
LastError: err, | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if output == nil { | ||
return nil, tfresource.NewEmptyResultError(input) | ||
} | ||
|
||
return output, nil | ||
} | ||
|
||
// LatestBotVersionByName returns the latest published version of a bot or $LATEST if the bot has never been published. | ||
// See https://docs.aws.amazon.com/lex/latest/dg/versioning-aliases.html. | ||
func LatestBotVersionByName(conn *lexmodelbuildingservice.LexModelBuildingService, name string) (string, error) { | ||
input := &lexmodelbuildingservice.GetBotVersionsInput{ | ||
Name: aws.String(name), | ||
} | ||
var latestVersion int | ||
|
||
err := conn.GetBotVersionsPages(input, func(page *lexmodelbuildingservice.GetBotVersionsOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, bot := range page.Bots { | ||
version := aws.StringValue(bot.Version) | ||
|
||
if version == tflex.LexBotVersionLatest { | ||
continue | ||
} | ||
|
||
if version, err := strconv.Atoi(version); err != nil { | ||
continue | ||
} else if version > latestVersion { | ||
latestVersion = version | ||
} | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if latestVersion == 0 { | ||
return tflex.LexBotVersionLatest, nil | ||
} | ||
|
||
return strconv.Itoa(latestVersion), nil | ||
} | ||
|
||
// LatestIntentVersionByName returns the latest published version of an intent or $LATEST if the intent has never been published. | ||
// See https://docs.aws.amazon.com/lex/latest/dg/versioning-aliases.html. | ||
func LatestIntentVersionByName(conn *lexmodelbuildingservice.LexModelBuildingService, name string) (string, error) { | ||
input := &lexmodelbuildingservice.GetIntentVersionsInput{ | ||
Name: aws.String(name), | ||
} | ||
var latestVersion int | ||
|
||
err := conn.GetIntentVersionsPages(input, func(page *lexmodelbuildingservice.GetIntentVersionsOutput, lastPage bool) bool { | ||
if page == nil { | ||
return !lastPage | ||
} | ||
|
||
for _, intent := range page.Intents { | ||
version := aws.StringValue(intent.Version) | ||
|
||
if version == tflex.LexIntentVersionLatest { | ||
continue | ||
} | ||
|
||
if version, err := strconv.Atoi(version); err != nil { | ||
continue | ||
} else if version > latestVersion { | ||
latestVersion = version | ||
} | ||
} | ||
|
||
return !lastPage | ||
}) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if latestVersion == 0 { | ||
return tflex.LexIntentVersionLatest, nil | ||
} | ||
|
||
return strconv.Itoa(latestVersion), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.