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

Adds tagging tests for bedrock #40305

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .changelog/40305.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_bedrock_provisioned_model_throughput: Properly manages `tags_all` when planning.
```
6 changes: 3 additions & 3 deletions internal/generate/tagstests/resource_test.go.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ plancheck.ExpectKnownValue(resourceName, tfjsonpath.New(names.AttrTagsAll), know
{{ if gt (len .ImportStateID) 0 -}}
ImportStateId: {{ .ImportStateID }},
{{ end -}}
{{ if .HasImportStateIDAttribute -}}
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, {{ .ImportStateIDAttribute }}),
{{ else if gt (len .ImportStateIDFunc) 0 -}}
{{ if gt (len .ImportStateIDFunc) 0 -}}
ImportStateIdFunc: {{ .ImportStateIDFunc }}(resourceName),
{{ else if .HasImportStateIDAttribute -}}
ImportStateIdFunc: acctest.AttrImportStateIdFunc(resourceName, {{ .ImportStateIDAttribute }}),
{{ end -}}
ImportStateVerify: true,
{{ if .HasImportStateIDAttribute -}}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/bedrock/bedrock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestAccBedrock_serial(t *testing.T) {
"CustomModel": {
acctest.CtBasic: testAccCustomModel_basic,
acctest.CtDisappears: testAccCustomModel_disappears,
"tags": testAccCustomModel_tags,
"tags": testAccBedrockCustomModel_tagsSerial,
"kmsKey": testAccCustomModel_kmsKey,
"validationDataConfig": testAccCustomModel_validationDataConfig,
"validationDataConfigWaitForCompletion": testAccCustomModel_validationDataConfigWaitForCompletion,
Expand Down
5 changes: 4 additions & 1 deletion internal/service/bedrock/custom_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource(name="Custom Model")
// @FrameworkResource("aws_bedrock_custom_model", name="Custom Model")
// @Tags(identifierAttribute="job_arn")
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/bedrock;bedrock.GetModelCustomizationJobOutput")
// @Testing(serialize=true)
// @Testing(importIgnore="base_model_identifier")
func newCustomModelResource(context.Context) (resource.ResourceWithConfigure, error) {
r := &customModelResource{}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/bedrock/custom_model_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource(name="Custom Model")
// @FrameworkDataSource("aws_bedrock_custom_model", name="Custom Model")
func newCustomModelDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
return &customModelDataSource{}, nil
}
Expand Down
2,373 changes: 2,373 additions & 0 deletions internal/service/bedrock/custom_model_tags_gen_test.go

Large diffs are not rendered by default.

108 changes: 0 additions & 108 deletions internal/service/bedrock/custom_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,53 +96,6 @@ func testAccCustomModel_disappears(t *testing.T) {
})
}

func testAccCustomModel_tags(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_bedrock_custom_model.test"
var v bedrock.GetModelCustomizationJobOutput

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.BedrockEndpointID) },
ErrorCheck: acctest.ErrorCheck(t, names.BedrockServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckCustomModelDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccCustomModelConfig_tags1(rName, acctest.CtKey1, acctest.CtValue1),
Check: resource.ComposeTestCheckFunc(
testAccCheckCustomModelExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"base_model_identifier"},
},
{
Config: testAccCustomModelConfig_tags2(rName, acctest.CtKey1, acctest.CtValue1Updated, acctest.CtKey2, acctest.CtValue2),
Check: resource.ComposeTestCheckFunc(
testAccCheckCustomModelExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "2"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey1, acctest.CtValue1Updated),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2),
),
},
{
Config: testAccCustomModelConfig_tags1(rName, acctest.CtKey2, acctest.CtValue2),
Check: resource.ComposeTestCheckFunc(
testAccCheckCustomModelExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "1"),
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsKey2, acctest.CtValue2),
),
},
},
})
}

func testAccCustomModel_kmsKey(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -497,67 +450,6 @@ resource "aws_bedrock_custom_model" "test" {
`, rName))
}

func testAccCustomModelConfig_tags1(rName, tagKey1, tagValue1 string) string {
return acctest.ConfigCompose(testAccCustomModelConfig_base(rName), fmt.Sprintf(`
resource "aws_bedrock_custom_model" "test" {
custom_model_name = %[1]q
job_name = %[1]q
base_model_identifier = data.aws_bedrock_foundation_model.test.model_arn
role_arn = aws_iam_role.test.arn

hyperparameters = {
"epochCount" = "1"
"batchSize" = "1"
"learningRate" = "0.005"
"learningRateWarmupSteps" = "0"
}

output_data_config {
s3_uri = "s3://${aws_s3_bucket.output.id}/data/"
}

training_data_config {
s3_uri = "s3://${aws_s3_bucket.training.id}/data/train.jsonl"
}

tags = {
%[2]q = %[3]q
}
}
`, rName, tagKey1, tagValue1))
}

func testAccCustomModelConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string {
return acctest.ConfigCompose(testAccCustomModelConfig_base(rName), fmt.Sprintf(`
resource "aws_bedrock_custom_model" "test" {
custom_model_name = %[1]q
job_name = %[1]q
base_model_identifier = data.aws_bedrock_foundation_model.test.model_arn
role_arn = aws_iam_role.test.arn

hyperparameters = {
"epochCount" = "1"
"batchSize" = "1"
"learningRate" = "0.005"
"learningRateWarmupSteps" = "0"
}

output_data_config {
s3_uri = "s3://${aws_s3_bucket.output.id}/data/"
}

training_data_config {
s3_uri = "s3://${aws_s3_bucket.training.id}/data/train.jsonl"
}

tags = {
%[2]q = %[3]q
%[4]q = %[5]q
}
}
`, rName, tagKey1, tagValue1, tagKey2, tagValue2))
}

func testAccCustomModelConfig_kmsKey(rName string) string {
return acctest.ConfigCompose(testAccCustomModelConfig_base(rName), fmt.Sprintf(`
resource "aws_kms_key" "test" {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/bedrock/custom_models_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource(name="Custom Models")
// @FrameworkDataSource("aws_bedrock_custom_models", name="Custom Models")
func newCustomModelsDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
return &customModelsDataSource{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/bedrock/foundation_model_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource(name="Foundation Model")
// @FrameworkDataSource("aws_bedrock_foundation_model", name="Foundation Model")
func newFoundationModelDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
return &foundationModelDataSource{}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource(name="Foundation Models")
// @FrameworkDataSource("aws_bedrock_foundation_models", name="Foundation Models")
func newFoundationModelsDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
return &foundationModelsDataSource{}, nil
}
Expand Down
1 change: 1 addition & 0 deletions internal/service/bedrock/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

//go:generate go run ../../generate/servicepackage/main.go
//go:generate go run ../../generate/tags/main.go -ServiceTagsSlice -ListTags -ListTagsInIDElem=ResourceARN -UpdateTags -TagInIDElem=ResourceARN
//go:generate go run ../../generate/tagstests/main.go
// ONLY generate directives and package declaration! Do not add anything else to this file.

package bedrock
5 changes: 4 additions & 1 deletion internal/service/bedrock/guardrail.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkResource(name="Guardrail")
// @FrameworkResource("aws_bedrock_guardrail", name="Guardrail")
// @Tags(identifierAttribute="guardrail_arn")
// @Testing(existsType="github.com/aws/aws-sdk-go-v2/service/bedrock;bedrock.GetGuardrailOutput")
// @Testing(importStateIdFunc="testAccGuardrailImportStateIDFunc")
// @Testing(importStateIdAttribute="guardrail_id")
func newResourceGuardrail(_ context.Context) (resource.ResourceWithConfigure, error) {
r := &resourceGuardrail{}

Expand Down
Loading
Loading