-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Add Lex intent data source and resource #8917
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
Merged
gdavison
merged 20 commits into
hashicorp:master
from
jzbruno:add_aws_lex_intent_resource
Sep 29, 2020
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8831ae4
Add Lex intent data source and resoruce
jzbruno 2c4e092
Update to address review comments
jzbruno 92137e2
Update to address review linting
jzbruno 2bf99ca
Update to address review comments, move common code into resource of …
jzbruno 0cb3500
Update to address review comments, format docs consistent with other …
jzbruno 33c6440
Update to address review comments, formatting and minor fixes
jzbruno 87684ac
Merge branch 'master' into add_aws_lex_intent_resource
jzbruno 6029848
Fix review comments, compute version and use create_version, remove g…
jzbruno 8bdd566
Add docs for create_version
jzbruno 9c77f70
Merge branch 'master' into add_aws_lex_intent_resource
jzbruno 6229e2a
First batch of updates for review prep
jzbruno cc42ce4
Fix github checks errors
jzbruno df5db5c
Fix terraform validation check
jzbruno 5c812fe
Latest review comments addressed, so many changes ...
jzbruno b282f31
Fix github check errors
jzbruno 7cde524
Fix github check errors lint
jzbruno 20abcd2
Fix github check error remove unused code
jzbruno f451a73
Removes "zero-width space" characters (\u200b)
gdavison d9113d5
Wraps error return
gdavison 1501488
Fixes copypasta
gdavison File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,97 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "regexp" | ||
| "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" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
| ) | ||
|
|
||
| func dataSourceAwsLexIntent() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Read: dataSourceAwsLexIntentRead, | ||
|
|
||
| Schema: map[string]*schema.Schema{ | ||
|
gdavison marked this conversation as resolved.
|
||
| "arn": { | ||
| 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: validation.All( | ||
| validation.StringLenBetween(1, 100), | ||
| validation.StringMatch(regexp.MustCompile(`^([A-Za-z]_?)+$`), ""), | ||
| ), | ||
| }, | ||
| "parent_intent_signature": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "version": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| Default: LexIntentVersionLatest, | ||
| ValidateFunc: validation.All( | ||
| validation.StringLenBetween(1, 64), | ||
| validation.StringMatch(regexp.MustCompile(`\$LATEST|[0-9]+`), ""), | ||
| ), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func dataSourceAwsLexIntentRead(d *schema.ResourceData, meta interface{}) error { | ||
| conn := meta.(*AWSClient).lexmodelconn | ||
|
|
||
| intentName := d.Get("name").(string) | ||
| resp, err := conn.GetIntent(&lexmodelbuildingservice.GetIntentInput{ | ||
| Name: aws.String(intentName), | ||
| Version: aws.String(d.Get("version").(string)), | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf("error getting intent %s: %w", intentName, err) | ||
| } | ||
|
|
||
| arn := arn.ARN{ | ||
| Partition: meta.(*AWSClient).partition, | ||
| Region: meta.(*AWSClient).region, | ||
| Service: "lex", | ||
| AccountID: meta.(*AWSClient).accountid, | ||
| Resource: fmt.Sprintf("intent:%s", d.Get("name").(string)), | ||
| } | ||
| d.Set("arn", arn.String()) | ||
|
|
||
| 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) | ||
| d.Set("parent_intent_signature", resp.ParentIntentSignature) | ||
| d.Set("version", resp.Version) | ||
|
|
||
| d.SetId(intentName) | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or 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,81 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
| ) | ||
|
|
||
| func TestAccDataSourceAwsLexIntent_basic(t *testing.T) { | ||
| rName := acctest.RandStringFromCharSet(8, acctest.CharSetAlpha) | ||
| dataSourceName := "data.aws_lex_intent.test" | ||
| resourceName := "aws_lex_intent.test" | ||
|
|
||
| resource.ParallelTest(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| Providers: testAccProviders, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: composeConfig( | ||
| testAccAwsLexIntentConfig_basic(rName), | ||
| testAccDataSourceAwsLexIntentConfig_basic(), | ||
| ), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
| 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"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func TestAccDataSourceAwsLexIntent_withVersion(t *testing.T) { | ||
| rName := acctest.RandStringFromCharSet(8, acctest.CharSetAlpha) | ||
| dataSourceName := "data.aws_lex_intent.test" | ||
| resourceName := "aws_lex_intent.test" | ||
|
|
||
| resource.ParallelTest(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| Providers: testAccProviders, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: composeConfig( | ||
| testAccAwsLexIntentConfig_createVersion(rName), | ||
| testAccDataSourceAwsLexIntentConfig_withVersion(), | ||
| ), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
| 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"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"), | ||
| ), | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func testAccDataSourceAwsLexIntentConfig_basic() string { | ||
| return ` | ||
| data "aws_lex_intent" "test" { | ||
| name = aws_lex_intent.test.name | ||
| } | ||
| ` | ||
| } | ||
|
|
||
| func testAccDataSourceAwsLexIntentConfig_withVersion() string { | ||
| return ` | ||
| data "aws_lex_intent" "test" { | ||
| name = aws_lex_intent.test.name | ||
| version = "1" | ||
| } | ||
| ` | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -23,15 +23,13 @@ func TestAccDataSourceAwsLexSlotType_basic(t *testing.T) { | |
| ), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "checksum", resourceName, "checksum"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "created_date", resourceName, "created_date"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "enumeration_value.#", resourceName, "enumeration_value.#"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "last_updated_date", resourceName, "last_updated_date"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "value_selection_strategy", resourceName, "value_selection_strategy"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "created_date", resourceName, "created_date"), | ||
| testAccCheckResourceAttrRfc3339(dataSourceName, "created_date"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "last_updated_date", resourceName, "last_updated_date"), | ||
| testAccCheckResourceAttrRfc3339(dataSourceName, "last_updated_date"), | ||
|
Comment on lines
25
to
-34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like that you kept this in alphabetical order :) |
||
| ), | ||
| }, | ||
| }, | ||
|
|
@@ -54,12 +52,12 @@ func TestAccDataSourceAwsLexSlotType_withVersion(t *testing.T) { | |
| ), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| 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"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "value_selection_strategy", resourceName, "value_selection_strategy"), | ||
| resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"), | ||
| testAccCheckResourceAttrRfc3339(dataSourceName, "created_date"), | ||
| testAccCheckResourceAttrRfc3339(dataSourceName, "last_updated_date"), | ||
| ), | ||
| }, | ||
| }, | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.