From 98f65f77e2241c55ce4f8c69dec422ce75328476 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 5 Jul 2022 12:55:51 -0500 Subject: [PATCH 01/13] add Transcribe language model r/aws_transcribe_language_model: add CRUD operations r/aws_transcribe_language_model: update tests r/aws_transcribe_language_model: fmt errors r/aws_transcribe_language_model: update docs --- .ci/.semgrep-service-name0.yml | 3 + .ci/.semgrep-service-name1.yml | 51 +++ .ci/.semgrep-service-name2.yml | 36 ++ .ci/.semgrep-service-name3.yml | 4 + go.mod | 2 +- go.sum | 5 + internal/provider/provider.go | 1 + internal/service/transcribe/language_model.go | 335 ++++++++++++++++++ .../service/transcribe/language_model_test.go | 213 +++++++++++ internal/service/transcribe/tags_gen.go | 8 + .../r/transcribe_language_model.html.markdown | 105 ++++++ 11 files changed, 762 insertions(+), 1 deletion(-) create mode 100644 internal/service/transcribe/language_model.go create mode 100644 internal/service/transcribe/language_model_test.go create mode 100644 website/docs/r/transcribe_language_model.html.markdown diff --git a/.ci/.semgrep-service-name0.yml b/.ci/.semgrep-service-name0.yml index 5c859afa1c9..3a184314c98 100644 --- a/.ci/.semgrep-service-name0.yml +++ b/.ci/.semgrep-service-name0.yml @@ -2940,6 +2940,7 @@ rules: patterns: - pattern-regex: "(?i)ConfigService" severity: WARNING +<<<<<<< HEAD:.ci/.semgrep-service-name0.yml - id: configservice-in-var-name languages: - go @@ -2985,3 +2986,5 @@ rules: - pattern-not-regex: "^TestAccConnect" - pattern-regex: ^TestAcc.* severity: WARNING +======= +>>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name0.yml diff --git a/.ci/.semgrep-service-name1.yml b/.ci/.semgrep-service-name1.yml index a1df360e29d..5e863a24569 100644 --- a/.ci/.semgrep-service-name1.yml +++ b/.ci/.semgrep-service-name1.yml @@ -1,5 +1,53 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: +<<<<<<< HEAD:.ci/.semgrep-service-name1.yml +======= + - id: configservice-in-var-name + languages: + - go + message: Do not use "ConfigService" in var name inside configservice package + paths: + include: + - internal/service/configservice + patterns: + - pattern: var $NAME = ... + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)ConfigService" + severity: WARNING + - id: connect-in-func-name + languages: + - go + message: Do not use "Connect" in func name inside connect package + paths: + include: + - internal/service/connect + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Connect" + - pattern-not-regex: .*uickConnect.* + - pattern-not-regex: ^TestAcc.* + severity: WARNING + - id: connect-in-test-name + languages: + - go + message: Include "Connect" in test name + paths: + include: + - internal/service/connect/*_test.go + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-not-regex: "^TestAccConnect" + - pattern-regex: ^TestAcc.* + severity: WARNING +>>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name1.yml - id: connect-in-const-name languages: - go @@ -2957,6 +3005,7 @@ rules: patterns: - pattern-regex: "(?i)ImageBuilder" severity: WARNING +<<<<<<< HEAD:.ci/.semgrep-service-name1.yml - id: inspector-in-func-name languages: - go @@ -2987,3 +3036,5 @@ rules: - pattern-not-regex: "^TestAccInspector" - pattern-regex: ^TestAcc.* severity: WARNING +======= +>>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name1.yml diff --git a/.ci/.semgrep-service-name2.yml b/.ci/.semgrep-service-name2.yml index fea9f26de7d..8c98e4a2539 100644 --- a/.ci/.semgrep-service-name2.yml +++ b/.ci/.semgrep-service-name2.yml @@ -1,5 +1,38 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: +<<<<<<< HEAD:.ci/.semgrep-service-name2.yml +======= + - id: inspector-in-func-name + languages: + - go + message: Do not use "Inspector" in func name inside inspector package + paths: + include: + - internal/service/inspector + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-regex: "(?i)Inspector" + - pattern-not-regex: ^TestAcc.* + severity: WARNING + - id: inspector-in-test-name + languages: + - go + message: Include "Inspector" in test name + paths: + include: + - internal/service/inspector/*_test.go + patterns: + - pattern: func $NAME( ... ) { ... } + - metavariable-pattern: + metavariable: $NAME + patterns: + - pattern-not-regex: "^TestAccInspector" + - pattern-regex: ^TestAcc.* + severity: WARNING +>>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name2.yml - id: inspector-in-const-name languages: - go @@ -2910,6 +2943,7 @@ rules: patterns: - pattern-regex: "(?i)RDS" severity: WARNING +<<<<<<< HEAD:.ci/.semgrep-service-name2.yml - id: rds-in-var-name languages: - go @@ -2982,3 +3016,5 @@ rules: patterns: - pattern-regex: "(?i)Redshift" severity: WARNING +======= +>>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name2.yml diff --git a/.ci/.semgrep-service-name3.yml b/.ci/.semgrep-service-name3.yml index f953bae758f..5576f9b9452 100644 --- a/.ci/.semgrep-service-name3.yml +++ b/.ci/.semgrep-service-name3.yml @@ -1,5 +1,6 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: +<<<<<<< HEAD:.ci/.semgrep-service-name3.yml - id: redshiftdata-in-func-name languages: - go @@ -45,6 +46,9 @@ rules: - pattern-regex: "(?i)RedshiftData" severity: WARNING - id: redshiftdata-in-var-name +======= + - id: rds-in-var-name +>>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name3.yml languages: - go message: Do not use "RedshiftData" in var name inside redshiftdata package diff --git a/go.mod b/go.mod index 7e5a95fd636..46f1e20bad6 100644 --- a/go.mod +++ b/go.mod @@ -93,4 +93,4 @@ require ( google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect google.golang.org/grpc v1.48.0 // indirect google.golang.org/protobuf v1.28.0 // indirect -) +) \ No newline at end of file diff --git a/go.sum b/go.sum index 39a88f49343..e1ee935a65d 100644 --- a/go.sum +++ b/go.sum @@ -56,8 +56,13 @@ github.com/aws/aws-sdk-go-v2/service/sso v1.11.4 h1:Uw5wBybFQ1UeA9ts0Y07gbv0ncZn github.com/aws/aws-sdk-go-v2/service/sso v1.11.4/go.mod h1:cPDwJwsP4Kff9mldCXAmddjJL6JGQqtA3Mzer2zyr88= github.com/aws/aws-sdk-go-v2/service/sts v1.16.4 h1:+xtV90n3abQmgzk1pS++FdxZTrPEDgQng6e4/56WR2A= github.com/aws/aws-sdk-go-v2/service/sts v1.16.4/go.mod h1:lfSYenAXtavyX2A1LsViglqlG9eEFYxNryTZS5rn3QE= +<<<<<<< HEAD github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.3 h1:JLL1VVt8JuktbSa26rjxizyZxF2iYWg4cuaBhk/1JBs= github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.3/go.mod h1:ojx+dJuqQFFX0EApdKHRPLvQvhmGKj+b0evbL7Uu19U= +======= +github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.2 h1:VsukhCyWr7HzhNArTgHMVofraVXkBMIYE2FtrsxfYw8= +github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.2/go.mod h1:HQI0HFDMT3ToqRJgsjG4nbu+39NiW63foozPr+lKzmI= +>>>>>>> b1d89910e6 (add Transcribe language model) github.com/aws/smithy-go v1.11.2/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM= github.com/aws/smithy-go v1.12.0 h1:gXpeZel/jPoWQ7OEmLIgCUnhkFftqNfwWUwAHSlp1v0= github.com/aws/smithy-go v1.12.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 04c065e59d8..c3c7ccd5056 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -2052,6 +2052,7 @@ func Provider() *schema.Provider { "aws_timestreamwrite_database": timestreamwrite.ResourceDatabase(), "aws_timestreamwrite_table": timestreamwrite.ResourceTable(), + "aws_transcribe_language_model": transcribe.ResourceLanguageModel(), "aws_transcribe_medical_vocabulary": transcribe.ResourceMedicalVocabulary(), "aws_transcribe_vocabulary": transcribe.ResourceVocabulary(), "aws_transcribe_vocabulary_filter": transcribe.ResourceVocabularyFilter(), diff --git a/internal/service/transcribe/language_model.go b/internal/service/transcribe/language_model.go new file mode 100644 index 00000000000..ce72a310b5b --- /dev/null +++ b/internal/service/transcribe/language_model.go @@ -0,0 +1,335 @@ +package transcribe + +import ( + "context" + "errors" + "fmt" + "log" + "time" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/transcribe" + "github.com/aws/aws-sdk-go-v2/service/transcribe/types" + "github.com/aws/aws-sdk-go/aws/arn" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/internal/verify" +) + +func ResourceLanguageModel() *schema.Resource { + return &schema.Resource{ + CreateWithoutTimeout: resourceLanguageModelCreate, + ReadWithoutTimeout: resourceLanguageModelRead, + UpdateWithoutTimeout: resourceLanguageModelUpdate, + DeleteWithoutTimeout: resourceLanguageModelDelete, + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(90 * time.Minute), + Delete: schema.DefaultTimeout(90 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "base_model_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(baseModelNamesSlice(types.BaseModelName("").Values()), false), + }, + "input_data_config": { + Type: schema.TypeList, + Required: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "data_access_role_arn": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: verify.ValidARN, + }, + "s3_uri": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "tuning_data_s3_uri": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Computed: true, + }, + }, + }, + }, + "language_code": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice(languageCodeSlice(types.LanguageCode("").Values()), false), + }, + "model_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "tags": tftags.TagsSchema(), + "tags_all": tftags.TagsSchemaComputed(), + }, + + CustomizeDiff: verify.SetTagsDiff, + } +} + +func resourceLanguageModelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).TranscribeConn + + in := &transcribe.CreateLanguageModelInput{ + BaseModelName: types.BaseModelName(d.Get("base_model_name").(string)), + LanguageCode: types.CLMLanguageCode(d.Get("language_code").(string)), + ModelName: aws.String(d.Get("model_name").(string)), + } + + if v, ok := d.GetOk("input_data_config"); ok && len(v.([]interface{})) > 0 { + in.InputDataConfig = expandInputDataConfig(v.([]interface{})) + } + + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{}))) + + if len(tags) > 0 { + in.Tags = Tags(tags.IgnoreAWS()) + } + + out, err := conn.CreateLanguageModel(ctx, in) + if err != nil { + return diag.Errorf("creating Amazon Transcribe LanguageModel (%s): %s", d.Get("model_name").(string), err) + } + + d.SetId(aws.ToString(out.ModelName)) + + if _, err := waitLanguageModelCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { + return diag.Errorf("waiting for Amazon Transcribe LanguageModel (%s) create: %s", d.Id(), err) + } + + return resourceLanguageModelRead(ctx, d, meta) +} + +func resourceLanguageModelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).TranscribeConn + + out, err := FindLanguageModelByName(ctx, conn, d.Id()) + + if !d.IsNewResource() && tfresource.NotFound(err) { + log.Printf("[WARN] Transcribe LanguageModel (%s) not found, removing from state", d.Id()) + d.SetId("") + return nil + } + + if err != nil { + return diag.Errorf("reading Transcribe LanguageModel (%s): %s", d.Id(), err) + } + + arn := arn.ARN{ + Partition: meta.(*conns.AWSClient).Partition, + Service: "transcribe", + Region: meta.(*conns.AWSClient).Region, + Resource: fmt.Sprintf("/language-model/%s", d.Id()), + }.String() + + d.Set("arn", arn) + d.Set("base_model_name", out.BaseModelName) + d.Set("language_code", out.LanguageCode) + d.Set("model_name", out.ModelName) + + if err := d.Set("input_data_config", flattenInputDataConfig(out.InputDataConfig)); err != nil { + return diag.Errorf("setting input data config: %s", err) + } + + tags, err := ListTags(ctx, conn, arn) + if err != nil { + return diag.Errorf("listing tags for Transcribe LanguageModel (%s): %s", d.Id(), err) + } + + defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig + ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig + tags = tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig) + + //lintignore:AWSR002 + if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + return diag.Errorf("setting tags: %s", err) + } + + if err := d.Set("tags_all", tags.Map()); err != nil { + return diag.Errorf("setting tags_all: %s", err) + } + + return nil +} + +func resourceLanguageModelUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).TranscribeConn + + if d.HasChange("tags_all") { + o, n := d.GetChange("tags_all") + + if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { + return diag.Errorf("error updating Transcribe LanguageModel (%s) tags: %s", d.Get("db_snapshot_arn").(string), err) + } + } + + return resourceLanguageModelRead(ctx, d, meta) +} + +func resourceLanguageModelDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + conn := meta.(*conns.AWSClient).TranscribeConn + + log.Printf("[INFO] Deleting Transcribe LanguageModel %s", d.Id()) + + _, err := conn.DeleteLanguageModel(ctx, &transcribe.DeleteLanguageModelInput{ + ModelName: aws.String(d.Id()), + }) + + var resourceNotFoundException *types.NotFoundException + if errors.As(err, &resourceNotFoundException) { + return nil + } + + if err != nil { + return diag.Errorf("deleting Transcribe LanguageModel (%s): %s", d.Id(), err) + } + + return nil +} + +func waitLanguageModelCreated(ctx context.Context, conn *transcribe.Client, id string, timeout time.Duration) (*types.LanguageModel, error) { + stateConf := &resource.StateChangeConf{ + Pending: modelStatus(types.ModelStatusInProgress), + Target: modelStatus(types.ModelStatusCompleted), + Refresh: statusLanguageModel(ctx, conn, id), + Timeout: timeout, + NotFoundChecks: 20, + ContinuousTargetOccurence: 2, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + if out, ok := outputRaw.(*types.LanguageModel); ok { + return out, err + } + + return nil, err +} + +func statusLanguageModel(ctx context.Context, conn *transcribe.Client, name string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + out, err := FindLanguageModelByName(ctx, conn, name) + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return out, string(out.ModelStatus), nil + } +} + +func FindLanguageModelByName(ctx context.Context, conn *transcribe.Client, id string) (*types.LanguageModel, error) { + in := &transcribe.DescribeLanguageModelInput{ + ModelName: aws.String(id), + } + + out, err := conn.DescribeLanguageModel(ctx, in) + + var resourceNotFoundException *types.NotFoundException + if errors.As(err, &resourceNotFoundException) { + return nil, &resource.NotFoundError{ + LastError: err, + LastRequest: in, + } + } + + if err != nil { + return nil, err + } + + if out == nil || out.LanguageModel == nil { + return nil, tfresource.NewEmptyResultError(in) + } + + return out.LanguageModel, nil +} + +func flattenInputDataConfig(apiObjects *types.InputDataConfig) []interface{} { + if apiObjects == nil { + return nil + } + + m := map[string]interface{}{ + "data_access_role_arn": apiObjects.DataAccessRoleArn, + "s3_uri": apiObjects.S3Uri, + "tuning_data_s3_uri": apiObjects.TuningDataS3Uri, + } + + return []interface{}{m} +} + +func expandInputDataConfig(tfList []interface{}) *types.InputDataConfig { + if len(tfList) == 0 || tfList[0] == nil { + return nil + } + + s := &types.InputDataConfig{} + + i := tfList[0].(map[string]interface{}) + + if val, ok := i["data_access_role_arn"]; ok { + s.DataAccessRoleArn = aws.String(val.(string)) + } + + if val, ok := i["s3_uri"]; ok { + s.S3Uri = aws.String(val.(string)) + } + + if val, ok := i["tuning_data_s3_uri"]; ok && val != "" { + s.TuningDataS3Uri = aws.String(val.(string)) + } + + return s +} + +func modelStatus(in ...types.ModelStatus) []string { + var s []string + + for _, v := range in { + s = append(s, string(v)) + } + + return s +} + +func baseModelNamesSlice(in []types.BaseModelName) (out []string) { + for _, v := range in { + out = append(out, string(v)) + } + + return +} + +func languageCodeSlice(in []types.LanguageCode) (out []string) { + for _, v := range in { + out = append(out, string(v)) + } + + return +} diff --git a/internal/service/transcribe/language_model_test.go b/internal/service/transcribe/language_model_test.go new file mode 100644 index 00000000000..99de303ebc8 --- /dev/null +++ b/internal/service/transcribe/language_model_test.go @@ -0,0 +1,213 @@ +package transcribe_test + +import ( + "context" + "fmt" + "testing" + + "github.com/aws/aws-sdk-go-v2/service/transcribe" + "github.com/aws/aws-sdk-go-v2/service/transcribe/types" + sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + tftranscribe "github.com/hashicorp/terraform-provider-aws/internal/service/transcribe" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" +) + +func TestAccTranscribeLanguageModel_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var languageModel types.LanguageModel + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_transcribe_language_model.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(names.TranscribeEndpointID, t) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), + ProviderFactories: acctest.ProviderFactories, + CheckDestroy: testAccCheckLanguageModelDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLanguageModelConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLanguageModelExists(resourceName, &languageModel), + resource.TestCheckResourceAttr(resourceName, "base_model_name", "NarrowBand"), + resource.TestCheckResourceAttr(resourceName, "language_code", "\"en-US\""), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccTranscribeLanguageModel_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var languageModel types.LanguageModel + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_transcribe_language_model.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(names.TranscribeEndpointID, t) + testAccPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), + ProviderFactories: acctest.ProviderFactories, + CheckDestroy: testAccCheckLanguageModelDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLanguageModelConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckLanguageModelExists(resourceName, &languageModel), + acctest.CheckResourceDisappears(acctest.Provider, tftranscribe.ResourceLanguageModel(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + +func testAccCheckLanguageModelDestroy(s *terraform.State) error { + conn := acctest.Provider.Meta().(*conns.AWSClient).TranscribeConn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_transcribe_language_model" { + continue + } + + _, err := tftranscribe.FindLanguageModelByName(context.Background(), conn, rs.Primary.ID) + + if tfresource.NotFound(err) { + continue + } + + if err != nil { + return err + } + } + + return nil +} + +func testAccCheckLanguageModelExists(name string, languageModel *types.LanguageModel) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Transcribe LanguageModel is set") + } + + conn := acctest.Provider.Meta().(*conns.AWSClient).TranscribeConn + resp, err := tftranscribe.FindLanguageModelByName(context.Background(), conn, rs.Primary.ID) + + if err != nil { + return fmt.Errorf("Error describing Transcribe LanguageModel: %s", err.Error()) + } + + *languageModel = *resp + + return nil + } +} + +func testAccPreCheck(t *testing.T) { + conn := acctest.Provider.Meta().(*conns.AWSClient).TranscribeConn + + input := &transcribe.ListLanguageModelsInput{} + + _, err := conn.ListLanguageModels(context.Background(), input) + + if acctest.PreCheckSkipError(err) { + t.Skipf("skipping acceptance testing: %s", err) + } + + if err != nil { + t.Fatalf("unexpected PreCheck error: %s", err) + } +} + +func testAccLanguageModelBaseConfig(rName string) string { + return fmt.Sprintf(` +data "aws_iam_policy_document" "test" { + statement { + actions = ["sts:AssumeRole"] + + principals { + type = "Service" + identifiers = ["transcribe.amazonaws.com"] + } + } +} + +resource "aws_iam_role" "example" { + name = %[1]q + assume_role_policy = data.aws_iam_policy_document.test.json +} + +resource "aws_iam_role_policy" "test_policy" { + name = %[1]q + role = aws_iam_role.test.id + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = [ + "s3:GetObject", + "s3:ListBucket", + ] + Effect = "Allow" + Resource = ["*"] + }, + ] + }) +} + +resource "aws_s3_bucket" "test" { + bucket = %[1]q + force_destroy = true +} +`, rName) +} + +func testAccLanguageModelConfig_basic(rName string) string { + return acctest.ConfigCompose( + testAccLanguageModelBaseConfig(rName), + fmt.Sprintf(` +resource "aws_transcribe_language_model" "test" { + model_name = %[1]q + base_model_name = "NarrowBand" + + input_data_config { + data_access_role_arn = aws_iam_role.test.arn + s3_uri = "s3://${aws_s3_bucket.test.id}/transcribe/" + } + + language_code = "en-US" + + tags = { + ENVIRONMENT = "development" + } +} +`, rName)) +} diff --git a/internal/service/transcribe/tags_gen.go b/internal/service/transcribe/tags_gen.go index 3ec79650296..9c00d2dace3 100644 --- a/internal/service/transcribe/tags_gen.go +++ b/internal/service/transcribe/tags_gen.go @@ -73,7 +73,11 @@ func UpdateTags(ctx context.Context, conn *transcribe.Client, identifier string, _, err := conn.UntagResource(ctx, input) if err != nil { +<<<<<<< HEAD return fmt.Errorf("untagging resource (%s): %w", identifier, err) +======= + return fmt.Errorf("error untagging resource (%s): %w", identifier, err) +>>>>>>> b1d89910e6 (add Transcribe language model) } } @@ -86,7 +90,11 @@ func UpdateTags(ctx context.Context, conn *transcribe.Client, identifier string, _, err := conn.TagResource(ctx, input) if err != nil { +<<<<<<< HEAD return fmt.Errorf("tagging resource (%s): %w", identifier, err) +======= + return fmt.Errorf("error tagging resource (%s): %w", identifier, err) +>>>>>>> b1d89910e6 (add Transcribe language model) } } diff --git a/website/docs/r/transcribe_language_model.html.markdown b/website/docs/r/transcribe_language_model.html.markdown new file mode 100644 index 00000000000..20c32dd726c --- /dev/null +++ b/website/docs/r/transcribe_language_model.html.markdown @@ -0,0 +1,105 @@ +--- +subcategory: "Transcribe" +layout: "aws" +page_title: "AWS: aws_transcribe_language_model" +description: |- + Terraform resource for managing an AWS Transcribe LanguageModel. +--- + +# Resource: aws_transcribe_language_model + +Terraform resource for managing an AWS Transcribe LanguageModel. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_iam_policy_document" "example" { + statement { + actions = ["sts:AssumeRole"] + + principals { + type = "Service" + identifiers = ["transcribe.amazonaws.com"] + } + } +} + +resource "aws_iam_role" "example" { + name = "example" + assume_role_policy = data.aws_iam_policy_document.example.json +} + +resource "aws_iam_role_policy" "test_policy" { + name = "example" + role = aws_iam_role.example.id + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = [ + "s3:GetObject", + "s3:ListBucket", + ] + Effect = "Allow" + Resource = ["*"] + }, + ] + }) +} + +resource "aws_s3_bucket" "example" { + bucket = "example-transcribe" + force_destroy = true +} + +resource "aws_transcribe_language_model" "example" { + model_name = "example" + base_model_name = "NarrowBand" + + input_data_config { + data_access_role_arn = aws_iam_role.example.arn + s3_uri = "s3://${aws_s3_bucket.example.id}/transcribe/" + } + + language_code = "en-US" + + tags = { + ENVIRONMENT = "development" + } +} +``` + +## Argument Reference + +The following arguments are required: + +* `example_arg` - (Required) Concise argument description. + +The following arguments are optional: + +* `optional_arg` - (Optional) Concise argument description. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `arn` - ARN of the LanguageModel. +* `example_attribute` - Concise description. + +## Timeouts + +`aws_transcribe_language_model` provides the following [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options: + +* `create` - (Optional, Default: `90m`) +* `delete` - (Optional, Default: `90m`) + +## Import + +Transcribe LanguageModel can be imported using the `model_name`, e.g., + +``` +$ terraform import aws_transcribe_language_model.example rft-8012925589 +``` From d9e6a8f5d12c8961db0cb82b0852879b2f833faf Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 26 Jul 2022 11:53:31 -0500 Subject: [PATCH 02/13] cleanup --- internal/service/transcribe/const.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 internal/service/transcribe/const.go diff --git a/internal/service/transcribe/const.go b/internal/service/transcribe/const.go new file mode 100644 index 00000000000..00b214d62c8 --- /dev/null +++ b/internal/service/transcribe/const.go @@ -0,0 +1,7 @@ +package transcribe + +import "time" + +const ( + propagationTimeout = 2 * time.Minute +) From 00ccdb1c899f15bb7acc0c05bf6eebfef83633d2 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 26 Jul 2022 12:07:33 -0500 Subject: [PATCH 03/13] update to main --- .ci/.semgrep-service-name0.yml | 3 -- .ci/.semgrep-service-name1.yml | 51 ------------------------- .ci/.semgrep-service-name2.yml | 36 ----------------- .ci/.semgrep-service-name3.yml | 4 -- go.sum | 7 +--- internal/service/transcribe/tags_gen.go | 8 ---- 6 files changed, 1 insertion(+), 108 deletions(-) diff --git a/.ci/.semgrep-service-name0.yml b/.ci/.semgrep-service-name0.yml index 3a184314c98..5c859afa1c9 100644 --- a/.ci/.semgrep-service-name0.yml +++ b/.ci/.semgrep-service-name0.yml @@ -2940,7 +2940,6 @@ rules: patterns: - pattern-regex: "(?i)ConfigService" severity: WARNING -<<<<<<< HEAD:.ci/.semgrep-service-name0.yml - id: configservice-in-var-name languages: - go @@ -2986,5 +2985,3 @@ rules: - pattern-not-regex: "^TestAccConnect" - pattern-regex: ^TestAcc.* severity: WARNING -======= ->>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name0.yml diff --git a/.ci/.semgrep-service-name1.yml b/.ci/.semgrep-service-name1.yml index 5e863a24569..a1df360e29d 100644 --- a/.ci/.semgrep-service-name1.yml +++ b/.ci/.semgrep-service-name1.yml @@ -1,53 +1,5 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: -<<<<<<< HEAD:.ci/.semgrep-service-name1.yml -======= - - id: configservice-in-var-name - languages: - - go - message: Do not use "ConfigService" in var name inside configservice package - paths: - include: - - internal/service/configservice - patterns: - - pattern: var $NAME = ... - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)ConfigService" - severity: WARNING - - id: connect-in-func-name - languages: - - go - message: Do not use "Connect" in func name inside connect package - paths: - include: - - internal/service/connect - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Connect" - - pattern-not-regex: .*uickConnect.* - - pattern-not-regex: ^TestAcc.* - severity: WARNING - - id: connect-in-test-name - languages: - - go - message: Include "Connect" in test name - paths: - include: - - internal/service/connect/*_test.go - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-not-regex: "^TestAccConnect" - - pattern-regex: ^TestAcc.* - severity: WARNING ->>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name1.yml - id: connect-in-const-name languages: - go @@ -3005,7 +2957,6 @@ rules: patterns: - pattern-regex: "(?i)ImageBuilder" severity: WARNING -<<<<<<< HEAD:.ci/.semgrep-service-name1.yml - id: inspector-in-func-name languages: - go @@ -3036,5 +2987,3 @@ rules: - pattern-not-regex: "^TestAccInspector" - pattern-regex: ^TestAcc.* severity: WARNING -======= ->>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name1.yml diff --git a/.ci/.semgrep-service-name2.yml b/.ci/.semgrep-service-name2.yml index 8c98e4a2539..fea9f26de7d 100644 --- a/.ci/.semgrep-service-name2.yml +++ b/.ci/.semgrep-service-name2.yml @@ -1,38 +1,5 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: -<<<<<<< HEAD:.ci/.semgrep-service-name2.yml -======= - - id: inspector-in-func-name - languages: - - go - message: Do not use "Inspector" in func name inside inspector package - paths: - include: - - internal/service/inspector - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-regex: "(?i)Inspector" - - pattern-not-regex: ^TestAcc.* - severity: WARNING - - id: inspector-in-test-name - languages: - - go - message: Include "Inspector" in test name - paths: - include: - - internal/service/inspector/*_test.go - patterns: - - pattern: func $NAME( ... ) { ... } - - metavariable-pattern: - metavariable: $NAME - patterns: - - pattern-not-regex: "^TestAccInspector" - - pattern-regex: ^TestAcc.* - severity: WARNING ->>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name2.yml - id: inspector-in-const-name languages: - go @@ -2943,7 +2910,6 @@ rules: patterns: - pattern-regex: "(?i)RDS" severity: WARNING -<<<<<<< HEAD:.ci/.semgrep-service-name2.yml - id: rds-in-var-name languages: - go @@ -3016,5 +2982,3 @@ rules: patterns: - pattern-regex: "(?i)Redshift" severity: WARNING -======= ->>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name2.yml diff --git a/.ci/.semgrep-service-name3.yml b/.ci/.semgrep-service-name3.yml index 5576f9b9452..f953bae758f 100644 --- a/.ci/.semgrep-service-name3.yml +++ b/.ci/.semgrep-service-name3.yml @@ -1,6 +1,5 @@ # Generated by internal/generate/servicesemgrep/main.go; DO NOT EDIT. rules: -<<<<<<< HEAD:.ci/.semgrep-service-name3.yml - id: redshiftdata-in-func-name languages: - go @@ -46,9 +45,6 @@ rules: - pattern-regex: "(?i)RedshiftData" severity: WARNING - id: redshiftdata-in-var-name -======= - - id: rds-in-var-name ->>>>>>> b1d89910e6 (add Transcribe language model):.semgrep-service-name3.yml languages: - go message: Do not use "RedshiftData" in var name inside redshiftdata package diff --git a/go.sum b/go.sum index e1ee935a65d..07bdf451027 100644 --- a/go.sum +++ b/go.sum @@ -56,13 +56,8 @@ github.com/aws/aws-sdk-go-v2/service/sso v1.11.4 h1:Uw5wBybFQ1UeA9ts0Y07gbv0ncZn github.com/aws/aws-sdk-go-v2/service/sso v1.11.4/go.mod h1:cPDwJwsP4Kff9mldCXAmddjJL6JGQqtA3Mzer2zyr88= github.com/aws/aws-sdk-go-v2/service/sts v1.16.4 h1:+xtV90n3abQmgzk1pS++FdxZTrPEDgQng6e4/56WR2A= github.com/aws/aws-sdk-go-v2/service/sts v1.16.4/go.mod h1:lfSYenAXtavyX2A1LsViglqlG9eEFYxNryTZS5rn3QE= -<<<<<<< HEAD github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.3 h1:JLL1VVt8JuktbSa26rjxizyZxF2iYWg4cuaBhk/1JBs= github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.3/go.mod h1:ojx+dJuqQFFX0EApdKHRPLvQvhmGKj+b0evbL7Uu19U= -======= -github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.2 h1:VsukhCyWr7HzhNArTgHMVofraVXkBMIYE2FtrsxfYw8= -github.com/aws/aws-sdk-go-v2/service/transcribe v1.20.2/go.mod h1:HQI0HFDMT3ToqRJgsjG4nbu+39NiW63foozPr+lKzmI= ->>>>>>> b1d89910e6 (add Transcribe language model) github.com/aws/smithy-go v1.11.2/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM= github.com/aws/smithy-go v1.12.0 h1:gXpeZel/jPoWQ7OEmLIgCUnhkFftqNfwWUwAHSlp1v0= github.com/aws/smithy-go v1.12.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= @@ -421,4 +416,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= \ No newline at end of file diff --git a/internal/service/transcribe/tags_gen.go b/internal/service/transcribe/tags_gen.go index 9c00d2dace3..3ec79650296 100644 --- a/internal/service/transcribe/tags_gen.go +++ b/internal/service/transcribe/tags_gen.go @@ -73,11 +73,7 @@ func UpdateTags(ctx context.Context, conn *transcribe.Client, identifier string, _, err := conn.UntagResource(ctx, input) if err != nil { -<<<<<<< HEAD return fmt.Errorf("untagging resource (%s): %w", identifier, err) -======= - return fmt.Errorf("error untagging resource (%s): %w", identifier, err) ->>>>>>> b1d89910e6 (add Transcribe language model) } } @@ -90,11 +86,7 @@ func UpdateTags(ctx context.Context, conn *transcribe.Client, identifier string, _, err := conn.TagResource(ctx, input) if err != nil { -<<<<<<< HEAD return fmt.Errorf("tagging resource (%s): %w", identifier, err) -======= - return fmt.Errorf("error tagging resource (%s): %w", identifier, err) ->>>>>>> b1d89910e6 (add Transcribe language model) } } From 029a7f650978da2c949ab0a80cc6e219681a3613 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 26 Jul 2022 12:13:05 -0500 Subject: [PATCH 04/13] ff --- go.mod | 2 +- go.sum | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 46f1e20bad6..7e5a95fd636 100644 --- a/go.mod +++ b/go.mod @@ -93,4 +93,4 @@ require ( google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect google.golang.org/grpc v1.48.0 // indirect google.golang.org/protobuf v1.28.0 // indirect -) \ No newline at end of file +) diff --git a/go.sum b/go.sum index 07bdf451027..39a88f49343 100644 --- a/go.sum +++ b/go.sum @@ -416,4 +416,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= \ No newline at end of file +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= From 4685b16b81bdeda1158e6f1f51bab9b32c1c7483 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 26 Jul 2022 12:51:22 -0500 Subject: [PATCH 05/13] r/aws_transcribe_language_model: update tests --- internal/service/transcribe/language_model_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/service/transcribe/language_model_test.go b/internal/service/transcribe/language_model_test.go index 99de303ebc8..d41e50da18a 100644 --- a/internal/service/transcribe/language_model_test.go +++ b/internal/service/transcribe/language_model_test.go @@ -32,9 +32,9 @@ func TestAccTranscribeLanguageModel_basic(t *testing.T) { acctest.PreCheckPartitionHasService(names.TranscribeEndpointID, t) testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), - ProviderFactories: acctest.ProviderFactories, - CheckDestroy: testAccCheckLanguageModelDestroy, + ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckLanguageModelDestroy, Steps: []resource.TestStep{ { Config: testAccLanguageModelConfig_basic(rName), @@ -68,9 +68,9 @@ func TestAccTranscribeLanguageModel_disappears(t *testing.T) { acctest.PreCheckPartitionHasService(names.TranscribeEndpointID, t) testAccPreCheck(t) }, - ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), - ProviderFactories: acctest.ProviderFactories, - CheckDestroy: testAccCheckLanguageModelDestroy, + ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckLanguageModelDestroy, Steps: []resource.TestStep{ { Config: testAccLanguageModelConfig_basic(rName), From 0ec298ecb8aaa450f761e2c00768153b6d86ac7a Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 28 Jul 2022 09:57:40 -0500 Subject: [PATCH 06/13] r/aws_transcribe_language_model: wait for IAM propagation --- internal/service/transcribe/const.go | 7 --- internal/service/transcribe/language_model.go | 45 ++++++++++++++----- 2 files changed, 35 insertions(+), 17 deletions(-) delete mode 100644 internal/service/transcribe/const.go diff --git a/internal/service/transcribe/const.go b/internal/service/transcribe/const.go deleted file mode 100644 index 00b214d62c8..00000000000 --- a/internal/service/transcribe/const.go +++ /dev/null @@ -1,7 +0,0 @@ -package transcribe - -import "time" - -const ( - propagationTimeout = 2 * time.Minute -) diff --git a/internal/service/transcribe/language_model.go b/internal/service/transcribe/language_model.go index ce72a310b5b..f3f4a171cdb 100644 --- a/internal/service/transcribe/language_model.go +++ b/internal/service/transcribe/language_model.go @@ -8,17 +8,20 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/transcribe" "github.com/aws/aws-sdk-go-v2/service/transcribe/types" - "github.com/aws/aws-sdk-go/aws/arn" + "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" + "github.com/hashicorp/terraform-provider-aws/names" ) func ResourceLanguageModel() *schema.Resource { @@ -90,6 +93,12 @@ func ResourceLanguageModel() *schema.Resource { } } +const ( + ResNameLanguageModel = "Language Model" + + propagationTimeout = 2 * time.Minute +) + func resourceLanguageModelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { conn := meta.(*conns.AWSClient).TranscribeConn @@ -110,15 +119,30 @@ func resourceLanguageModelCreate(ctx context.Context, d *schema.ResourceData, me in.Tags = Tags(tags.IgnoreAWS()) } - out, err := conn.CreateLanguageModel(ctx, in) + outputRaw, err := tfresource.RetryWhen(propagationTimeout, + func() (interface{}, error) { + return conn.CreateLanguageModel(ctx, in) + }, + func(err error) (bool, error) { + var bre *types.BadRequestException + if errors.Is(err, bre) { + e := err.(*types.BadRequestException) + if tfawserr.ErrMessageContains(err, e.ErrorCode(), e.ErrorMessage()) { + return true, err + } + } + return false, err + }, + ) + if err != nil { - return diag.Errorf("creating Amazon Transcribe LanguageModel (%s): %s", d.Get("model_name").(string), err) + return names.DiagError(names.Transcribe, names.ErrActionCreating, ResNameLanguageModel, d.Get("model_name").(string), err) } - d.SetId(aws.ToString(out.ModelName)) + d.SetId(aws.ToString(outputRaw.(*transcribe.CreateLanguageModelOutput).ModelName)) if _, err := waitLanguageModelCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return diag.Errorf("waiting for Amazon Transcribe LanguageModel (%s) create: %s", d.Id(), err) + return names.DiagError(names.Transcribe, names.ErrActionWaitingForCreation, ResNameVocabularyFilter, d.Get("model_name").(string), err) } return resourceLanguageModelRead(ctx, d, meta) @@ -140,10 +164,11 @@ func resourceLanguageModelRead(ctx context.Context, d *schema.ResourceData, meta } arn := arn.ARN{ + AccountID: meta.(*conns.AWSClient).AccountID, Partition: meta.(*conns.AWSClient).Partition, Service: "transcribe", Region: meta.(*conns.AWSClient).Region, - Resource: fmt.Sprintf("/language-model/%s", d.Id()), + Resource: fmt.Sprintf("language-model/%s", d.Id()), }.String() d.Set("arn", arn) @@ -213,8 +238,8 @@ func resourceLanguageModelDelete(ctx context.Context, d *schema.ResourceData, me func waitLanguageModelCreated(ctx context.Context, conn *transcribe.Client, id string, timeout time.Duration) (*types.LanguageModel, error) { stateConf := &resource.StateChangeConf{ - Pending: modelStatus(types.ModelStatusInProgress), - Target: modelStatus(types.ModelStatusCompleted), + Pending: []string{}, + Target: enum.Slice(types.ModelStatusInProgress), Refresh: statusLanguageModel(ctx, conn, id), Timeout: timeout, NotFoundChecks: 20, @@ -251,8 +276,8 @@ func FindLanguageModelByName(ctx context.Context, conn *transcribe.Client, id st out, err := conn.DescribeLanguageModel(ctx, in) - var resourceNotFoundException *types.NotFoundException - if errors.As(err, &resourceNotFoundException) { + var bre *types.BadRequestException + if errors.As(err, &bre) { return nil, &resource.NotFoundError{ LastError: err, LastRequest: in, From ea08dccc70ad73945906bfd9c4b09e01da30d61a Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Thu, 28 Jul 2022 10:07:47 -0500 Subject: [PATCH 07/13] r/aws_transcribe_language_model: wait for IAM propagation --- internal/service/transcribe/language_model.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/internal/service/transcribe/language_model.go b/internal/service/transcribe/language_model.go index f3f4a171cdb..ba1ff315860 100644 --- a/internal/service/transcribe/language_model.go +++ b/internal/service/transcribe/language_model.go @@ -5,13 +5,13 @@ import ( "errors" "fmt" "log" + "strings" "time" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go-v2/service/transcribe" "github.com/aws/aws-sdk-go-v2/service/transcribe/types" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -125,11 +125,8 @@ func resourceLanguageModelCreate(ctx context.Context, d *schema.ResourceData, me }, func(err error) (bool, error) { var bre *types.BadRequestException - if errors.Is(err, bre) { - e := err.(*types.BadRequestException) - if tfawserr.ErrMessageContains(err, e.ErrorCode(), e.ErrorMessage()) { - return true, err - } + if errors.As(err, &bre) { + return strings.Contains(bre.ErrorMessage(), "Make sure that you have read permission"), err } return false, err }, From 1648864cc221876bcfdff7eb46ab4a0ec50747d1 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Mon, 1 Aug 2022 11:31:42 -0500 Subject: [PATCH 08/13] r/aws_transcribe_language_model: change error responses to use names package --- internal/service/transcribe/language_model.go | 38 +++++++++---------- .../service/transcribe/language_model_test.go | 3 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/internal/service/transcribe/language_model.go b/internal/service/transcribe/language_model.go index ba1ff315860..9bd32d1db17 100644 --- a/internal/service/transcribe/language_model.go +++ b/internal/service/transcribe/language_model.go @@ -42,10 +42,10 @@ func ResourceLanguageModel() *schema.Resource { Schema: map[string]*schema.Schema{ "base_model_name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(baseModelNamesSlice(types.BaseModelName("").Values()), false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[types.BaseModelName](), }, "input_data_config": { Type: schema.TypeList, @@ -55,10 +55,10 @@ func ResourceLanguageModel() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "data_access_role_arn": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: verify.ValidARN, + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: validation.ToDiagFunc(verify.ValidARN), }, "s3_uri": { Type: schema.TypeString, @@ -75,10 +75,10 @@ func ResourceLanguageModel() *schema.Resource { }, }, "language_code": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(languageCodeSlice(types.LanguageCode("").Values()), false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[types.LanguageCode](), }, "model_name": { Type: schema.TypeString, @@ -157,7 +157,7 @@ func resourceLanguageModelRead(ctx context.Context, d *schema.ResourceData, meta } if err != nil { - return diag.Errorf("reading Transcribe LanguageModel (%s): %s", d.Id(), err) + return names.DiagError(names.Transcribe, names.ErrActionReading, ResNameLanguageModel, d.Id(), err) } arn := arn.ARN{ @@ -174,12 +174,12 @@ func resourceLanguageModelRead(ctx context.Context, d *schema.ResourceData, meta d.Set("model_name", out.ModelName) if err := d.Set("input_data_config", flattenInputDataConfig(out.InputDataConfig)); err != nil { - return diag.Errorf("setting input data config: %s", err) + return names.DiagError(names.Transcribe, names.ErrActionSetting, ResNameLanguageModel, d.Id(), err) } tags, err := ListTags(ctx, conn, arn) if err != nil { - return diag.Errorf("listing tags for Transcribe LanguageModel (%s): %s", d.Id(), err) + return names.DiagError(names.Transcribe, names.ErrActionReading, ResNameLanguageModel, d.Id(), err) } defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig @@ -188,11 +188,11 @@ func resourceLanguageModelRead(ctx context.Context, d *schema.ResourceData, meta //lintignore:AWSR002 if err := d.Set("tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { - return diag.Errorf("setting tags: %s", err) + return names.DiagError(names.Transcribe, names.ErrActionSetting, ResNameLanguageModel, d.Id(), err) } if err := d.Set("tags_all", tags.Map()); err != nil { - return diag.Errorf("setting tags_all: %s", err) + return names.DiagError(names.Transcribe, names.ErrActionSetting, ResNameLanguageModel, d.Id(), err) } return nil @@ -205,7 +205,7 @@ func resourceLanguageModelUpdate(ctx context.Context, d *schema.ResourceData, me o, n := d.GetChange("tags_all") if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil { - return diag.Errorf("error updating Transcribe LanguageModel (%s) tags: %s", d.Get("db_snapshot_arn").(string), err) + return names.DiagError(names.Transcribe, names.ErrActionUpdating, ResNameLanguageModel, d.Id(), err) } } @@ -227,7 +227,7 @@ func resourceLanguageModelDelete(ctx context.Context, d *schema.ResourceData, me } if err != nil { - return diag.Errorf("deleting Transcribe LanguageModel (%s): %s", d.Id(), err) + return names.DiagError(names.Transcribe, names.ErrActionDeleting, ResNameLanguageModel, d.Id(), err) } return nil diff --git a/internal/service/transcribe/language_model_test.go b/internal/service/transcribe/language_model_test.go index d41e50da18a..5d457d7743c 100644 --- a/internal/service/transcribe/language_model_test.go +++ b/internal/service/transcribe/language_model_test.go @@ -40,8 +40,9 @@ func TestAccTranscribeLanguageModel_basic(t *testing.T) { Config: testAccLanguageModelConfig_basic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckLanguageModelExists(resourceName, &languageModel), + resource.TestCheckResourceAttrSet(resourceName, "arn"), resource.TestCheckResourceAttr(resourceName, "base_model_name", "NarrowBand"), - resource.TestCheckResourceAttr(resourceName, "language_code", "\"en-US\""), + resource.TestCheckResourceAttr(resourceName, "language_code", "en-US"), ), }, { From a32dff445930344d6372e58ae7c94905499776cc Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Mon, 1 Aug 2022 11:51:59 -0500 Subject: [PATCH 09/13] r/aws_transcribe_language_model: remove unused funcs --- internal/service/transcribe/language_model.go | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/internal/service/transcribe/language_model.go b/internal/service/transcribe/language_model.go index 9bd32d1db17..8ee97904ea1 100644 --- a/internal/service/transcribe/language_model.go +++ b/internal/service/transcribe/language_model.go @@ -329,29 +329,3 @@ func expandInputDataConfig(tfList []interface{}) *types.InputDataConfig { return s } - -func modelStatus(in ...types.ModelStatus) []string { - var s []string - - for _, v := range in { - s = append(s, string(v)) - } - - return s -} - -func baseModelNamesSlice(in []types.BaseModelName) (out []string) { - for _, v := range in { - out = append(out, string(v)) - } - - return -} - -func languageCodeSlice(in []types.LanguageCode) (out []string) { - for _, v := range in { - out = append(out, string(v)) - } - - return -} From 989d9409a2eac421b7fdf7deb8d5f2fb9a2145eb Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 2 Aug 2022 18:00:33 -0500 Subject: [PATCH 10/13] r/aws_transcribe_language_model: add tests --- internal/service/transcribe/language_model.go | 16 ++- .../service/transcribe/language_model_test.go | 109 +++++++++++++++++- internal/service/transcribe/sweep.go | 59 ++++++++++ .../test-fixtures/language_model_test1.txt | 11 ++ .../r/transcribe_language_model.html.markdown | 29 ++++- 5 files changed, 208 insertions(+), 16 deletions(-) create mode 100644 internal/service/transcribe/test-fixtures/language_model_test1.txt diff --git a/internal/service/transcribe/language_model.go b/internal/service/transcribe/language_model.go index 8ee97904ea1..a2513be415d 100644 --- a/internal/service/transcribe/language_model.go +++ b/internal/service/transcribe/language_model.go @@ -36,11 +36,14 @@ func ResourceLanguageModel() *schema.Resource { }, Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(90 * time.Minute), - Delete: schema.DefaultTimeout(90 * time.Minute), + Create: schema.DefaultTimeout(600 * time.Minute), }, Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, "base_model_name": { Type: schema.TypeString, Required: true, @@ -235,8 +238,8 @@ func resourceLanguageModelDelete(ctx context.Context, d *schema.ResourceData, me func waitLanguageModelCreated(ctx context.Context, conn *transcribe.Client, id string, timeout time.Duration) (*types.LanguageModel, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{}, - Target: enum.Slice(types.ModelStatusInProgress), + Pending: enum.Slice(types.ModelStatusInProgress), + Target: enum.Slice(types.ModelStatusCompleted), Refresh: statusLanguageModel(ctx, conn, id), Timeout: timeout, NotFoundChecks: 20, @@ -300,7 +303,10 @@ func flattenInputDataConfig(apiObjects *types.InputDataConfig) []interface{} { m := map[string]interface{}{ "data_access_role_arn": apiObjects.DataAccessRoleArn, "s3_uri": apiObjects.S3Uri, - "tuning_data_s3_uri": apiObjects.TuningDataS3Uri, + } + + if aws.ToString(apiObjects.TuningDataS3Uri) != "" { + m["tuning_data_s3_uri"] = apiObjects.TuningDataS3Uri } return []interface{}{m} diff --git a/internal/service/transcribe/language_model_test.go b/internal/service/transcribe/language_model_test.go index 5d457d7743c..bccdbccdd19 100644 --- a/internal/service/transcribe/language_model_test.go +++ b/internal/service/transcribe/language_model_test.go @@ -30,7 +30,7 @@ func TestAccTranscribeLanguageModel_basic(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckPartitionHasService(names.TranscribeEndpointID, t) - testAccPreCheck(t) + testAccLanguageModelsPreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -54,6 +54,54 @@ func TestAccTranscribeLanguageModel_basic(t *testing.T) { }) } +func TestAccTranscribeLanguageModel_updateTags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + var languageModel types.LanguageModel + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_transcribe_language_model.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(t) + acctest.PreCheckPartitionHasService(names.TranscribeEndpointID, t) + testAccLanguageModelsPreCheck(t) + }, + ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckLanguageModelDestroy, + Steps: []resource.TestStep{ + { + Config: testAccLanguageModelConfig_tags1(rName, "key1", "value1"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLanguageModelExists(resourceName, &languageModel), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + ), + }, + { + Config: testAccLanguageModelConfig_tags2(rName, "key1", "value1", "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLanguageModelExists(resourceName, &languageModel), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + { + Config: testAccLanguageModelConfig_tags1(rName, "key2", "value2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckLanguageModelExists(resourceName, &languageModel), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.key2", "value2"), + ), + }, + }, + }) +} + func TestAccTranscribeLanguageModel_disappears(t *testing.T) { if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -67,7 +115,7 @@ func TestAccTranscribeLanguageModel_disappears(t *testing.T) { PreCheck: func() { acctest.PreCheck(t) acctest.PreCheckPartitionHasService(names.TranscribeEndpointID, t) - testAccPreCheck(t) + testAccLanguageModelsPreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, names.TranscribeEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, @@ -131,7 +179,7 @@ func testAccCheckLanguageModelExists(name string, languageModel *types.LanguageM } } -func testAccPreCheck(t *testing.T) { +func testAccLanguageModelsPreCheck(t *testing.T) { conn := acctest.Provider.Meta().(*conns.AWSClient).TranscribeConn input := &transcribe.ListLanguageModelsInput{} @@ -160,7 +208,7 @@ data "aws_iam_policy_document" "test" { } } -resource "aws_iam_role" "example" { +resource "aws_iam_role" "test" { name = %[1]q assume_role_policy = data.aws_iam_policy_document.test.json } @@ -188,6 +236,12 @@ resource "aws_s3_bucket" "test" { bucket = %[1]q force_destroy = true } + +resource "aws_s3_object" "object" { + bucket = aws_s3_bucket.test.id + key = "transcribe/test1.txt" + source = "test-fixtures/language_model_test1.txt" +} `, rName) } @@ -207,8 +261,53 @@ resource "aws_transcribe_language_model" "test" { language_code = "en-US" tags = { - ENVIRONMENT = "development" + tag1 = "value1" } } `, rName)) } + +func testAccLanguageModelConfig_tags1(rName, key1, value1 string) string { + return acctest.ConfigCompose( + testAccLanguageModelBaseConfig(rName), + fmt.Sprintf(` +resource "aws_transcribe_language_model" "test" { + model_name = %[1]q + base_model_name = "NarrowBand" + + input_data_config { + data_access_role_arn = aws_iam_role.test.arn + s3_uri = "s3://${aws_s3_bucket.test.id}/transcribe/" + } + + language_code = "en-US" + + tags = { + %[2]q = %[3]q + } +} +`, rName, key1, value1)) +} + +func testAccLanguageModelConfig_tags2(rName, key1, value1, key2, value2 string) string { + return acctest.ConfigCompose( + testAccLanguageModelBaseConfig(rName), + fmt.Sprintf(` +resource "aws_transcribe_language_model" "test" { + model_name = %[1]q + base_model_name = "NarrowBand" + + input_data_config { + data_access_role_arn = aws_iam_role.test.arn + s3_uri = "s3://${aws_s3_bucket.test.id}/transcribe/" + } + + language_code = "en-US" + + tags = { + %[2]q = %[3]q + %[4]q = %[5]q + } +} +`, rName, key1, value1, key2, value2)) +} diff --git a/internal/service/transcribe/sweep.go b/internal/service/transcribe/sweep.go index e695d8e0111..38c782a502c 100644 --- a/internal/service/transcribe/sweep.go +++ b/internal/service/transcribe/sweep.go @@ -17,6 +17,15 @@ import ( ) func init() { + resource.AddTestSweepers("aws_transcribe_language_models", &resource.Sweeper{ + Name: "aws_transcribe_language_models", + F: sweepLanguageModels, + Dependencies: []string{ + "aws_s3_bucket", + "aws_iam_role", + }, + }) + resource.AddTestSweepers("aws_transcribe_medical_vocabulary", &resource.Sweeper{ Name: "aws_transcribe_medical_vocabulary", F: sweepMedicalVocabularies, @@ -42,6 +51,56 @@ func init() { }) } +func sweepLanguageModels(region string) error { + client, err := sweep.SharedRegionalSweepClient(region) + if err != nil { + fmt.Errorf("error getting client: %s", err) + } + + ctx := context.Background() + conn := client.(*conns.AWSClient).TranscribeConn + sweepResources := make([]*sweep.SweepResource, 0) + in := &transcribe.ListLanguageModelsInput{} + var errs *multierror.Error + + pages := transcribe.NewListLanguageModelsPaginator(conn, in) + + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if sweep.SkipSweepError(err) { + log.Println("[WARN] Skipping Transcribe Language Models sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error retrieving Transcribe Language Models: %w", err) + } + + for _, model := range page.Models { + name := aws.ToString(model.ModelName) + log.Printf("[INFO] Deleting Transcribe Language Model: %s", name) + + r := ResourceLanguageModel() + d := r.Data(nil) + d.SetId(name) + + sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) + } + } + + if err := sweep.SweepOrchestrator(sweepResources); err != nil { + errs = multierror.Append(errs, fmt.Errorf("error sweeping Transcribe Language Models for %s: %w", region, err)) + } + + if sweep.SkipSweepError(err) { + log.Printf("[WARN] Skipping Transcribe Language Models sweep for %s: %s", region, errs) + return nil + } + + return errs.ErrorOrNil() +} + func sweepMedicalVocabularies(region string) error { client, err := sweep.SharedRegionalSweepClient(region) if err != nil { diff --git a/internal/service/transcribe/test-fixtures/language_model_test1.txt b/internal/service/transcribe/test-fixtures/language_model_test1.txt new file mode 100644 index 00000000000..f03f1b5ed9c --- /dev/null +++ b/internal/service/transcribe/test-fixtures/language_model_test1.txt @@ -0,0 +1,11 @@ +The PS5 will feature a custom eight-core AMD Zen 2 CPU clocked at 3.5GHz (variable frequency) and a custom GPU based on AMD’s RDNA 2 architecture hardware that promises 10.28 teraflops and 36 compute units clocked at 2.23GHz (also variable frequency). + +It’ll also have 16GB of GDDR6 RAM and a custom 825GB SSD that Sony has previously promised will offer super-fast loading times in gameplay, via Eurogamer. + +One of the biggest technical updates in the PS5 was already announced last year: a switch to SSD storage for the console’s main hard drive, which Sony says will result in dramatically faster load times. + +A previous demo showed Spider-Man loading levels in less than a second on the PS5, compared to the roughly eight seconds it took on a PS4.PlayStation hardware lead Mark Cerny dove into some of the details about those SSD goals at the announcement. + +Where it took a PS4 around 20 seconds to load a single gigabyte of data, the goal with the PS5’s SSD was to enable loading + +five gigabytes of data in a single second. diff --git a/website/docs/r/transcribe_language_model.html.markdown b/website/docs/r/transcribe_language_model.html.markdown index 20c32dd726c..375db28a56c 100644 --- a/website/docs/r/transcribe_language_model.html.markdown +++ b/website/docs/r/transcribe_language_model.html.markdown @@ -10,6 +10,8 @@ description: |- Terraform resource for managing an AWS Transcribe LanguageModel. +-> This resource can take a significant amount of time to provision. See Language Model [FAQ](https://aws.amazon.com/transcribe/faqs/) for more details. + ## Example Usage ### Basic Usage @@ -55,6 +57,12 @@ resource "aws_s3_bucket" "example" { force_destroy = true } +resource "aws_s3_object" "object" { + bucket = aws_s3_bucket.example.id + key = "transcribe/test1.txt" + source = "test1.txt" +} + resource "aws_transcribe_language_model" "example" { model_name = "example" base_model_name = "NarrowBand" @@ -76,30 +84,39 @@ resource "aws_transcribe_language_model" "example" { The following arguments are required: -* `example_arg` - (Required) Concise argument description. +* `base_model_name` - (Required) Name of reference base model +* `input_data_config` - (Required) The input data config for the LanguageModel. See [Input Data Config](#input-data-config) for more details. +* `language_code` - (Required) The language code you selected for your vocabulary filter. Refer to the [supported languages](https://docs.aws.amazon.com/transcribe/latest/dg/supported-languages.html) page for accepted codes. +* `model_name` - (Required) The model name. + +### Input Data Config + +* `data_access_role_arn` - (Required) IAM role with access to S3 bucket. +* `s3_uri` - (Required) S3 URI where training data is located. +* `tuning_data_s3_uri` - (Optional) S3 URI where tuning data is located. + The following arguments are optional: -* `optional_arg` - (Optional) Concise argument description. +* `tags` - (Optional) A map of tags to assign to the LanguageModel. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attributes Reference In addition to all arguments above, the following attributes are exported: +* `id` - LanguageModel name. * `arn` - ARN of the LanguageModel. -* `example_attribute` - Concise description. ## Timeouts `aws_transcribe_language_model` provides the following [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options: -* `create` - (Optional, Default: `90m`) -* `delete` - (Optional, Default: `90m`) +* `create` - (Optional, Default: `600m`) ## Import Transcribe LanguageModel can be imported using the `model_name`, e.g., ``` -$ terraform import aws_transcribe_language_model.example rft-8012925589 +$ terraform import aws_transcribe_language_model.example example-name ``` From f168f28001e098d3f1bb706cf191d377ebfe3ee8 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 2 Aug 2022 18:15:17 -0500 Subject: [PATCH 11/13] r/aws_transcribe_language_model: updates to docs --- internal/service/transcribe/language_model.go | 2 +- internal/service/transcribe/sweep.go | 4 ++-- website/docs/r/transcribe_language_model.html.markdown | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/service/transcribe/language_model.go b/internal/service/transcribe/language_model.go index a2513be415d..5ce03e10292 100644 --- a/internal/service/transcribe/language_model.go +++ b/internal/service/transcribe/language_model.go @@ -142,7 +142,7 @@ func resourceLanguageModelCreate(ctx context.Context, d *schema.ResourceData, me d.SetId(aws.ToString(outputRaw.(*transcribe.CreateLanguageModelOutput).ModelName)) if _, err := waitLanguageModelCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { - return names.DiagError(names.Transcribe, names.ErrActionWaitingForCreation, ResNameVocabularyFilter, d.Get("model_name").(string), err) + return names.DiagError(names.Transcribe, names.ErrActionWaitingForCreation, ResNameLanguageModel, d.Get("model_name").(string), err) } return resourceLanguageModelRead(ctx, d, meta) diff --git a/internal/service/transcribe/sweep.go b/internal/service/transcribe/sweep.go index 38c782a502c..e19fb74a16f 100644 --- a/internal/service/transcribe/sweep.go +++ b/internal/service/transcribe/sweep.go @@ -17,8 +17,8 @@ import ( ) func init() { - resource.AddTestSweepers("aws_transcribe_language_models", &resource.Sweeper{ - Name: "aws_transcribe_language_models", + resource.AddTestSweepers("aws_transcribe_language_model", &resource.Sweeper{ + Name: "aws_transcribe_language_model", F: sweepLanguageModels, Dependencies: []string{ "aws_s3_bucket", diff --git a/website/docs/r/transcribe_language_model.html.markdown b/website/docs/r/transcribe_language_model.html.markdown index 375db28a56c..a87730f3c8e 100644 --- a/website/docs/r/transcribe_language_model.html.markdown +++ b/website/docs/r/transcribe_language_model.html.markdown @@ -84,9 +84,9 @@ resource "aws_transcribe_language_model" "example" { The following arguments are required: -* `base_model_name` - (Required) Name of reference base model +* `base_model_name` - (Required) Name of reference base model. * `input_data_config` - (Required) The input data config for the LanguageModel. See [Input Data Config](#input-data-config) for more details. -* `language_code` - (Required) The language code you selected for your vocabulary filter. Refer to the [supported languages](https://docs.aws.amazon.com/transcribe/latest/dg/supported-languages.html) page for accepted codes. +* `language_code` - (Required) The language code you selected for your language model. Refer to the [supported languages](https://docs.aws.amazon.com/transcribe/latest/dg/supported-languages.html) page for accepted codes. * `model_name` - (Required) The model name. ### Input Data Config From c6d83e4c67d95dd9db2316b86a9e031cfab99f3c Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 2 Aug 2022 18:18:52 -0500 Subject: [PATCH 12/13] add CHANGELOG entry for #25698 --- .changelog/25698.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/25698.txt diff --git a/.changelog/25698.txt b/.changelog/25698.txt new file mode 100644 index 00000000000..b83c7c521fb --- /dev/null +++ b/.changelog/25698.txt @@ -0,0 +1,3 @@ +```release-note:new-resource + aws_transcribe_language_model +``` \ No newline at end of file From 4710d773166a3e429db0a53348802ca7c803150e Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 2 Aug 2022 18:22:10 -0500 Subject: [PATCH 13/13] docs --- website/docs/r/transcribe_language_model.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/transcribe_language_model.html.markdown b/website/docs/r/transcribe_language_model.html.markdown index a87730f3c8e..664350bfcf0 100644 --- a/website/docs/r/transcribe_language_model.html.markdown +++ b/website/docs/r/transcribe_language_model.html.markdown @@ -10,7 +10,7 @@ description: |- Terraform resource for managing an AWS Transcribe LanguageModel. --> This resource can take a significant amount of time to provision. See Language Model [FAQ](https://aws.amazon.com/transcribe/faqs/) for more details. +-> This resource can take a significant amount of time to provision. See Language Model [FAQ](https://aws.amazon.com/transcribe/faqs/) for more details. ## Example Usage