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

Add Lex intent data source and resource #8917

Merged
merged 20 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
83 changes: 83 additions & 0 deletions aws/data_source_aws_lex_intent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package aws

import (
"fmt"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
"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{
jzbruno marked this conversation as resolved.
Show resolved Hide resolved
gdavison marked this conversation as resolved.
Show resolved Hide resolved
"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: %s", intentName, err)
jzbruno marked this conversation as resolved.
Show resolved Hide resolved
}

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
}
51 changes: 51 additions & 0 deletions aws/data_source_aws_lex_intent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package aws

import (
"fmt"
"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) {
resourceName := "aws_lex_intent.test"
dataSourceName := "data." + resourceName
testID := acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testDataSourceAwsLexIntentConfig, testID),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "checksum", resourceName, "checksum"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
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"),
jzbruno marked this conversation as resolved.
Show resolved Hide resolved
),
},
},
})
}

const testDataSourceAwsLexIntentConfig = `
resource "aws_lex_intent" "test" {
description = "Intent to order a bouquet of flowers for pick up"

fulfillment_activity {
type = "ReturnIntent"
}

name = "test_intent_%s"
}

data "aws_lex_intent" "test" {
name = aws_lex_intent.test.name
}
`
2 changes: 2 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func Provider() *schema.Provider {
"aws_lambda_layer_version": dataSourceAwsLambdaLayerVersion(),
"aws_launch_configuration": dataSourceAwsLaunchConfiguration(),
"aws_launch_template": dataSourceAwsLaunchTemplate(),
"aws_lex_intent": dataSourceAwsLexIntent(),
"aws_lex_slot_type": dataSourceAwsLexSlotType(),
"aws_mq_broker": dataSourceAwsMqBroker(),
"aws_msk_cluster": dataSourceAwsMskCluster(),
Expand Down Expand Up @@ -699,6 +700,7 @@ func Provider() *schema.Provider {
"aws_lambda_provisioned_concurrency_config": resourceAwsLambdaProvisionedConcurrencyConfig(),
"aws_launch_configuration": resourceAwsLaunchConfiguration(),
"aws_launch_template": resourceAwsLaunchTemplate(),
"aws_lex_intent": resourceAwsLexIntent(),
"aws_lex_slot_type": resourceAwsLexSlotType(),
"aws_licensemanager_association": resourceAwsLicenseManagerAssociation(),
"aws_licensemanager_license_configuration": resourceAwsLicenseManagerLicenseConfiguration(),
Expand Down
Loading