-
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 branch 'add_aws_lex_bot_alias', pull request #8919
- Loading branch information
Showing
15 changed files
with
1,339 additions
and
73 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
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,89 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/arn" | ||
"github.com/aws/aws-sdk-go/service/lexmodelbuildingservice" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAwsLexBotAlias() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsLexBotAliasRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"bot_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateLexBotName, | ||
}, | ||
"bot_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"checksum": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"created_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"last_updated_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateLexBotAliasName, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsLexBotAliasRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).lexmodelconn | ||
|
||
botName := d.Get("bot_name").(string) | ||
botAliasName := d.Get("name").(string) | ||
d.SetId(fmt.Sprintf("%s:%s", botName, botAliasName)) | ||
|
||
resp, err := conn.GetBotAlias(&lexmodelbuildingservice.GetBotAliasInput{ | ||
BotName: aws.String(botName), | ||
Name: aws.String(botAliasName), | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error reading Lex bot alias (%s): %w", d.Id(), err) | ||
} | ||
|
||
arn := arn.ARN{ | ||
Partition: meta.(*AWSClient).partition, | ||
Region: meta.(*AWSClient).region, | ||
Service: "lex", | ||
AccountID: meta.(*AWSClient).accountid, | ||
Resource: fmt.Sprintf("bot:%s", d.Id()), | ||
} | ||
d.Set("arn", arn.String()) | ||
|
||
d.Set("bot_name", resp.BotName) | ||
d.Set("bot_version", resp.BotVersion) | ||
d.Set("checksum", resp.Checksum) | ||
d.Set("created_date", resp.CreatedDate.Format(time.RFC3339)) | ||
d.Set("description", resp.Description) | ||
d.Set("last_updated_date", resp.LastUpdatedDate.Format(time.RFC3339)) | ||
d.Set("name", resp.Name) | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func testAccDataSourceAwsLexBotAlias_basic(t *testing.T) { | ||
rName := acctest.RandStringFromCharSet(8, acctest.CharSetAlpha) | ||
dataSourceName := "data.aws_lex_bot_alias.test" | ||
resourceName := "aws_lex_bot_alias.test" | ||
|
||
// If this test runs in parallel with other Lex Bot tests, it loses its description | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: composeConfig( | ||
testAccAwsLexBotConfig_intent(rName), | ||
testAccAwsLexBotConfig_createVersion(rName), | ||
testAccAwsLexBotAliasConfig_basic(rName), | ||
testAccDataSourceAwsLexBotAliasConfig_basic(), | ||
), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "bot_name", resourceName, "bot_name"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "bot_version", resourceName, "bot_version"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "checksum", resourceName, "checksum"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "created_date", resourceName, "created_date"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "last_updated_date", resourceName, "last_updated_date"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsLexBotAliasConfig_basic() string { | ||
return ` | ||
data "aws_lex_bot_alias" "test" { | ||
name = aws_lex_bot_alias.test.name | ||
bot_name = aws_lex_bot.test.name | ||
} | ||
` | ||
} |
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
Oops, something went wrong.