From 6bf4934d8523a7d6cb326c63e8c21f0d62d4b3a9 Mon Sep 17 00:00:00 2001 From: SkyScrapr Date: Tue, 7 Nov 2023 10:11:24 +1300 Subject: [PATCH] F aws bedrock foundation model datasource (#34148) * move bedrock to v2 * make gen * add dependencies * add aws_bedrock_foundation_models datasource * add new datasource aws_bedrock_foundation_model * make gen * add docs * add docs * linting fixes * chore: changelog * d/aws_bedrock_foundation_models: awstypes alias * d/aws_bedrock: add name to resource annotations * d/aws_bedrock: tidy skaff comments * d/aws_bedrock_foundation_models: alphabetize attributes * d/aws_bedrock_foundation_model: alphabetize attributes * d/aws_bedrock_foundation_models(doc): tidy * d/aws_bedrock_foundation_model(doc): tidy * d/aws_bedrock_foundation_model(doc): markdownlint * d/aws_bedrock_foundation_model: custom string type conversion helper * d/aws_bedrock_foundation_models: add filters on ListFoundationModels * d/aws_bedrock_foundation_models: simplify flatten func * d/aws_bedrock_foundation_models(test): add tests with filters * chore: fix moved function after merge * d/aws_bedrock_foundation_models(doc): document id attribute * d/aws_bedrock: use diags constructor funcs --------- Co-authored-by: Jared Baker --- .changelog/34148.txt | 6 + go.mod | 1 + go.sum | 2 + internal/conns/awsclient_gen.go | 6 +- .../bedrock/foundation_model_data_source.go | 137 ++++++++++++ .../foundation_model_data_source_test.go | 39 ++++ .../bedrock/foundation_models_data_source.go | 198 ++++++++++++++++++ .../foundation_models_data_source_test.go | 115 ++++++++++ .../service/bedrock/service_package_gen.go | 28 ++- names/names_data.csv | 2 +- .../d/bedrock_foundation_model.html.markdown | 42 ++++ .../d/bedrock_foundation_models.html.markdown | 55 +++++ 12 files changed, 619 insertions(+), 12 deletions(-) create mode 100644 .changelog/34148.txt create mode 100644 internal/service/bedrock/foundation_model_data_source.go create mode 100644 internal/service/bedrock/foundation_model_data_source_test.go create mode 100644 internal/service/bedrock/foundation_models_data_source.go create mode 100644 internal/service/bedrock/foundation_models_data_source_test.go create mode 100644 website/docs/d/bedrock_foundation_model.html.markdown create mode 100644 website/docs/d/bedrock_foundation_models.html.markdown diff --git a/.changelog/34148.txt b/.changelog/34148.txt new file mode 100644 index 00000000000..acbb2700a60 --- /dev/null +++ b/.changelog/34148.txt @@ -0,0 +1,6 @@ +```release-note:new-data-source +aws_bedrock_foundation_model +``` +```release-note:new-data-source +aws_bedrock_foundation_models +``` diff --git a/go.mod b/go.mod index 4584ff580c9..16cdf20089c 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/appconfig v1.25.0 github.com/aws/aws-sdk-go-v2/service/athena v1.34.0 github.com/aws/aws-sdk-go-v2/service/auditmanager v1.29.0 + github.com/aws/aws-sdk-go-v2/service/bedrock v1.3.0 github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.6.0 github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.14.0 github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.26.0 diff --git a/go.sum b/go.sum index fdc6c79cd0d..2e88bde9a0d 100644 --- a/go.sum +++ b/go.sum @@ -59,6 +59,8 @@ github.com/aws/aws-sdk-go-v2/service/athena v1.34.0 h1:wZaywaONfHerySRsAFWhA1Myo github.com/aws/aws-sdk-go-v2/service/athena v1.34.0/go.mod h1:WSRHaccpHc65b4OP63dElo5nLuMUoGhoDDzYr5tP5/k= github.com/aws/aws-sdk-go-v2/service/auditmanager v1.29.0 h1:CIG6h8XkwGaS9/k4z+B72Rzh9KdlyrD/HzbidUD/C9U= github.com/aws/aws-sdk-go-v2/service/auditmanager v1.29.0/go.mod h1:xXtiggqGVD59WdBNclsih1qfeeXPOasMzpBKfj7k+wE= +github.com/aws/aws-sdk-go-v2/service/bedrock v1.3.0 h1:RTPbj0iKv6FSecxR+vH3V944Wt4mufsGuUd+tZy1M8Y= +github.com/aws/aws-sdk-go-v2/service/bedrock v1.3.0/go.mod h1:TSSHBioEPEx4wRuWyT5nFdRPjHXiNdixNr1wyNIC61s= github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.6.0 h1:CVezvdO+/Aa1S+lQpNqe1nHnn4a9QPxr5LVKMGYUDmo= github.com/aws/aws-sdk-go-v2/service/cleanrooms v1.6.0/go.mod h1:Zi1s46alfbcte2MyRLdlxuv5+Z6YKJ+ODPggBnSZWhc= github.com/aws/aws-sdk-go-v2/service/cloudcontrol v1.14.0 h1:OkgbfNtZKs8cqCOA8cZrw1GLYR9/ghlRDnKkdzADo+E= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 6860b7ac80a..1b3ed9020ed 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -10,6 +10,7 @@ import ( appconfig_sdkv2 "github.com/aws/aws-sdk-go-v2/service/appconfig" athena_sdkv2 "github.com/aws/aws-sdk-go-v2/service/athena" auditmanager_sdkv2 "github.com/aws/aws-sdk-go-v2/service/auditmanager" + bedrock_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrock" cleanrooms_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cleanrooms" cloudcontrol_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" cloudwatchlogs_sdkv2 "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs" @@ -88,7 +89,6 @@ import ( autoscalingplans_sdkv1 "github.com/aws/aws-sdk-go/service/autoscalingplans" backup_sdkv1 "github.com/aws/aws-sdk-go/service/backup" batch_sdkv1 "github.com/aws/aws-sdk-go/service/batch" - bedrock_sdkv1 "github.com/aws/aws-sdk-go/service/bedrock" budgets_sdkv1 "github.com/aws/aws-sdk-go/service/budgets" chime_sdkv1 "github.com/aws/aws-sdk-go/service/chime" chimesdkmediapipelines_sdkv1 "github.com/aws/aws-sdk-go/service/chimesdkmediapipelines" @@ -319,8 +319,8 @@ func (c *AWSClient) BatchConn(ctx context.Context) *batch_sdkv1.Batch { return errs.Must(conn[*batch_sdkv1.Batch](ctx, c, names.Batch)) } -func (c *AWSClient) BedrockConn(ctx context.Context) *bedrock_sdkv1.Bedrock { - return errs.Must(conn[*bedrock_sdkv1.Bedrock](ctx, c, names.Bedrock)) +func (c *AWSClient) BedrockClient(ctx context.Context) *bedrock_sdkv2.Client { + return errs.Must(client[*bedrock_sdkv2.Client](ctx, c, names.Bedrock)) } func (c *AWSClient) BudgetsConn(ctx context.Context) *budgets_sdkv1.Budgets { diff --git a/internal/service/bedrock/foundation_model_data_source.go b/internal/service/bedrock/foundation_model_data_source.go new file mode 100644 index 00000000000..d6e4169dfc8 --- /dev/null +++ b/internal/service/bedrock/foundation_model_data_source.go @@ -0,0 +1,137 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package bedrock + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/service/bedrock" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + "github.com/hashicorp/terraform-provider-aws/names" +) + +const DSNameFoundationModel = "Foundation Model Data Source" + +// @FrameworkDataSource(name="Foundation Model") +func newDataSourceFoundationModel(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceFoundationModel{}, nil +} + +type dataSourceFoundationModel struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceFoundationModel) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { + response.TypeName = "aws_bedrock_foundation_model" +} + +func (d *dataSourceFoundationModel) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "customizations_supported": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "id": schema.StringAttribute{ + Computed: true, + }, + "inference_types_supported": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "input_modalities": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "model_arn": schema.StringAttribute{ + Computed: true, + }, + "model_id": schema.StringAttribute{ + Required: true, + }, + "model_name": schema.StringAttribute{ + Computed: true, + }, + "output_modalities": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "provider_name": schema.StringAttribute{ + Computed: true, + }, + "response_streaming_supported": schema.BoolAttribute{ + Computed: true, + }, + }, + } +} + +func (d *dataSourceFoundationModel) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { + conn := d.Meta().BedrockClient(ctx) + + var data foundationModel + response.Diagnostics.Append(request.Config.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + + input := &bedrock.GetFoundationModelInput{ + ModelIdentifier: data.ModelID.ValueStringPointer(), + } + model, err := conn.GetFoundationModel(ctx, input) + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.Bedrock, create.ErrActionReading, DSNameFoundationModel, data.ModelID.String(), err), + err.Error(), + ) + return + } + + data.refreshFromOutput(ctx, model) + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +type foundationModel struct { + CustomizationsSupported types.Set `tfsdk:"customizations_supported"` + ID types.String `tfsdk:"id"` + InferenceTypesSupported types.Set `tfsdk:"inference_types_supported"` + InputModalities types.Set `tfsdk:"input_modalities"` + ModelArn types.String `tfsdk:"model_arn"` + ModelID types.String `tfsdk:"model_id"` + ModelName types.String `tfsdk:"model_name"` + OutputModalities types.Set `tfsdk:"output_modalities"` + ProviderName types.String `tfsdk:"provider_name"` + ResponseStreamingSupported types.Bool `tfsdk:"response_streaming_supported"` +} + +func (data *foundationModel) refreshFromOutput(ctx context.Context, model *bedrock.GetFoundationModelOutput) { + if model == nil { + return + } + + data.ID = flex.StringToFramework(ctx, model.ModelDetails.ModelId) + data.ModelArn = flex.StringToFramework(ctx, model.ModelDetails.ModelArn) + data.ModelID = flex.StringToFramework(ctx, model.ModelDetails.ModelId) + data.ModelName = flex.StringToFramework(ctx, model.ModelDetails.ModelName) + data.ProviderName = flex.StringToFramework(ctx, model.ModelDetails.ProviderName) + data.CustomizationsSupported = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.ModelDetails.CustomizationsSupported)) + data.InferenceTypesSupported = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.ModelDetails.InferenceTypesSupported)) + data.InputModalities = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.ModelDetails.InputModalities)) + data.OutputModalities = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.ModelDetails.OutputModalities)) + data.ResponseStreamingSupported = flex.BoolToFramework(ctx, model.ModelDetails.ResponseStreamingSupported) +} + +// toStringSlice converts a slice of custom string types to a slice of strings +func toStringSlice[T ~string](values []T) []string { + var out []string + for _, v := range values { + out = append(out, string(v)) + } + return out +} diff --git a/internal/service/bedrock/foundation_model_data_source_test.go b/internal/service/bedrock/foundation_model_data_source_test.go new file mode 100644 index 00000000000..13eabe82efa --- /dev/null +++ b/internal/service/bedrock/foundation_model_data_source_test.go @@ -0,0 +1,39 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package bedrock_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +func TestAccBedrockFoundationModelDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccFoundationModelDataSourceConfig_basic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.aws_bedrock_foundation_model.test", "id"), + resource.TestCheckResourceAttrSet("data.aws_bedrock_foundation_model.test", "model_id"), + ), + }, + }, + }) +} + +func testAccFoundationModelDataSourceConfig_basic() string { + return ` +data "aws_bedrock_foundation_models" "test" {} + +data "aws_bedrock_foundation_model" "test" { + model_id = data.aws_bedrock_foundation_models.test.model_summaries[0].model_id +} +` +} diff --git a/internal/service/bedrock/foundation_models_data_source.go b/internal/service/bedrock/foundation_models_data_source.go new file mode 100644 index 00000000000..f457c2fb893 --- /dev/null +++ b/internal/service/bedrock/foundation_models_data_source.go @@ -0,0 +1,198 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package bedrock + +import ( + "context" + + "github.com/YakDriver/regexache" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/bedrock" + awstypes "github.com/aws/aws-sdk-go-v2/service/bedrock/types" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-provider-aws/internal/create" + "github.com/hashicorp/terraform-provider-aws/internal/framework" + "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" + fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" + "github.com/hashicorp/terraform-provider-aws/names" +) + +const DSNameFoundationModels = "Foundation Models Data Source" + +// @FrameworkDataSource(name="Foundation Models") +func newDataSourceFoundationModels(context.Context) (datasource.DataSourceWithConfigure, error) { + return &dataSourceFoundationModels{}, nil +} + +type dataSourceFoundationModels struct { + framework.DataSourceWithConfigure +} + +func (d *dataSourceFoundationModels) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { + response.TypeName = "aws_bedrock_foundation_models" +} + +func (d *dataSourceFoundationModels) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "by_customization_type": schema.StringAttribute{ + Optional: true, + }, + "by_inference_type": schema.StringAttribute{ + Optional: true, + }, + "by_output_modality": schema.StringAttribute{ + Optional: true, + }, + "by_provider": schema.StringAttribute{ + Optional: true, + Validators: []validator.String{ + stringvalidator.RegexMatches(regexache.MustCompile(`^[a-z0-9-]{1,63}$`), ""), + }, + }, + "id": schema.StringAttribute{ + Computed: true, + }, + }, + Blocks: map[string]schema.Block{ + "model_summaries": schema.ListNestedBlock{ + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "customizations_supported": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "inference_types_supported": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "input_modalities": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "model_arn": schema.StringAttribute{ + Computed: true, + }, + "model_id": schema.StringAttribute{ + Computed: true, + }, + "model_name": schema.StringAttribute{ + Computed: true, + }, + "output_modalities": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, + }, + "provider_name": schema.StringAttribute{ + Computed: true, + }, + "response_streaming_supported": schema.BoolAttribute{ + Computed: true, + }, + }, + }, + }, + }, + } +} + +func (d *dataSourceFoundationModels) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { + conn := d.Meta().BedrockClient(ctx) + + var data foundationModels + response.Diagnostics.Append(request.Config.Get(ctx, &data)...) + if response.Diagnostics.HasError() { + return + } + data.ID = types.StringValue(d.Meta().Region) + + input := &bedrock.ListFoundationModelsInput{} + if !data.ByCustomizationType.IsNull() { + input.ByCustomizationType = awstypes.ModelCustomization(data.ByCustomizationType.ValueString()) + } + if !data.ByInferenceType.IsNull() { + input.ByInferenceType = awstypes.InferenceType(data.ByInferenceType.ValueString()) + } + if !data.ByOutputModality.IsNull() { + input.ByOutputModality = awstypes.ModelModality(data.ByOutputModality.ValueString()) + } + if !data.ByProvider.IsNull() { + input.ByProvider = aws.String(data.ByProvider.ValueString()) + } + + models, err := conn.ListFoundationModels(ctx, input) + if err != nil { + response.Diagnostics.AddError( + create.ProblemStandardMessage(names.Bedrock, create.ErrActionReading, DSNameFoundationModels, data.ID.String(), err), + err.Error(), + ) + return + } + + data.ModelSummaries = flattenFoundationModelSummaries(ctx, models.ModelSummaries) + + response.Diagnostics.Append(response.State.Set(ctx, &data)...) +} + +type foundationModels struct { + ByCustomizationType types.String `tfsdk:"by_customization_type"` + ByInferenceType types.String `tfsdk:"by_inference_type"` + ByOutputModality types.String `tfsdk:"by_output_modality"` + ByProvider types.String `tfsdk:"by_provider"` + ID types.String `tfsdk:"id"` + ModelSummaries types.List `tfsdk:"model_summaries"` +} + +type foundationModelSummary struct { + CustomizationsSupported types.Set `tfsdk:"customizations_supported"` + InferenceTypesSupported types.Set `tfsdk:"inference_types_supported"` + InputModalities types.Set `tfsdk:"input_modalities"` + ModelID types.String `tfsdk:"model_id"` + ModelArn types.String `tfsdk:"model_arn"` + ModelName types.String `tfsdk:"model_name"` + OutputModalities types.Set `tfsdk:"output_modalities"` + ProviderName types.String `tfsdk:"provider_name"` + ResponseStreamingSupported types.Bool `tfsdk:"response_streaming_supported"` +} + +func flattenFoundationModelSummaries(ctx context.Context, models []awstypes.FoundationModelSummary) types.List { + attributeTypes := fwtypes.AttributeTypesMust[foundationModelSummary](ctx) + + // HACK: Reflection used above to build the attributeTypes cannot determine the ElemType + attributeTypes["customizations_supported"] = types.SetType{ElemType: types.StringType} + attributeTypes["inference_types_supported"] = types.SetType{ElemType: types.StringType} + attributeTypes["input_modalities"] = types.SetType{ElemType: types.StringType} + attributeTypes["output_modalities"] = types.SetType{ElemType: types.StringType} + + elemType := types.ObjectType{AttrTypes: attributeTypes} + + if models == nil { + return types.ListNull(elemType) + } + + attrs := make([]attr.Value, 0, len(models)) + for _, model := range models { + attr := map[string]attr.Value{} + attr["model_arn"] = flex.StringToFramework(ctx, model.ModelArn) + attr["model_id"] = flex.StringToFramework(ctx, model.ModelId) + attr["model_name"] = flex.StringToFramework(ctx, model.ModelName) + attr["provider_name"] = flex.StringToFramework(ctx, model.ProviderName) + + attr["customizations_supported"] = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.CustomizationsSupported)) + attr["inference_types_supported"] = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.InferenceTypesSupported)) + attr["input_modalities"] = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.InputModalities)) + attr["output_modalities"] = flex.FlattenFrameworkStringValueSet(ctx, toStringSlice(model.OutputModalities)) + attr["response_streaming_supported"] = flex.BoolToFramework(ctx, model.ResponseStreamingSupported) + + val := types.ObjectValueMust(attributeTypes, attr) + attrs = append(attrs, val) + } + + return types.ListValueMust(elemType, attrs) +} diff --git a/internal/service/bedrock/foundation_models_data_source_test.go b/internal/service/bedrock/foundation_models_data_source_test.go new file mode 100644 index 00000000000..e3e4bbba763 --- /dev/null +++ b/internal/service/bedrock/foundation_models_data_source_test.go @@ -0,0 +1,115 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package bedrock_test + +import ( + "fmt" + "testing" + + "github.com/aws/aws-sdk-go-v2/service/bedrock/types" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +func TestAccBedrockFoundationModelsDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccFoundationModelsDataSourceConfig_basic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.aws_bedrock_foundation_models.test", "id"), + acctest.CheckResourceAttrGreaterThanValue("data.aws_bedrock_foundation_models.test", "model_summaries.#", 0), + ), + }, + }, + }) +} + +func TestAccBedrockFoundationModelsDataSource_byCustomizationType(t *testing.T) { + ctx := acctest.Context(t) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccFoundationModelsDataSourceConfig_byCustomizationType(string(types.ModelCustomizationFineTuning)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.aws_bedrock_foundation_models.test", "id"), + acctest.CheckResourceAttrGreaterThanValue("data.aws_bedrock_foundation_models.test", "model_summaries.#", 0), + ), + }, + }, + }) +} + +func TestAccBedrockFoundationModelsDataSource_byInferenceType(t *testing.T) { + ctx := acctest.Context(t) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccFoundationModelsDataSourceConfig_byInferenceType(string(types.InferenceTypeOnDemand)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.aws_bedrock_foundation_models.test", "id"), + acctest.CheckResourceAttrGreaterThanValue("data.aws_bedrock_foundation_models.test", "model_summaries.#", 0), + ), + }, + }, + }) +} + +func TestAccBedrockFoundationModelsDataSource_byOutputModality(t *testing.T) { + ctx := acctest.Context(t) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccFoundationModelsDataSourceConfig_byOutputModality(string(types.ModelModalityText)), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.aws_bedrock_foundation_models.test", "id"), + acctest.CheckResourceAttrGreaterThanValue("data.aws_bedrock_foundation_models.test", "model_summaries.#", 0), + ), + }, + }, + }) +} + +func testAccFoundationModelsDataSourceConfig_basic() string { + return ` +data "aws_bedrock_foundation_models" "test" {} +` +} + +func testAccFoundationModelsDataSourceConfig_byCustomizationType(customizationType string) string { + return fmt.Sprintf(` +data "aws_bedrock_foundation_models" "test" { + by_customization_type = %[1]q +} +`, customizationType) +} + +func testAccFoundationModelsDataSourceConfig_byInferenceType(inferenceType string) string { + return fmt.Sprintf(` +data "aws_bedrock_foundation_models" "test" { + by_inference_type = %[1]q +} +`, inferenceType) +} + +func testAccFoundationModelsDataSourceConfig_byOutputModality(outputModality string) string { + return fmt.Sprintf(` +data "aws_bedrock_foundation_models" "test" { + by_output_modality = %[1]q +} +`, outputModality) +} diff --git a/internal/service/bedrock/service_package_gen.go b/internal/service/bedrock/service_package_gen.go index dbf67558ffb..ea62447bffb 100644 --- a/internal/service/bedrock/service_package_gen.go +++ b/internal/service/bedrock/service_package_gen.go @@ -5,9 +5,8 @@ package bedrock import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - bedrock_sdkv1 "github.com/aws/aws-sdk-go/service/bedrock" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + bedrock_sdkv2 "github.com/aws/aws-sdk-go-v2/service/bedrock" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -16,7 +15,16 @@ import ( type servicePackage struct{} func (p *servicePackage) FrameworkDataSources(ctx context.Context) []*types.ServicePackageFrameworkDataSource { - return []*types.ServicePackageFrameworkDataSource{} + return []*types.ServicePackageFrameworkDataSource{ + { + Factory: newDataSourceFoundationModel, + Name: "Foundation Model", + }, + { + Factory: newDataSourceFoundationModels, + Name: "Foundation Models", + }, + } } func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.ServicePackageFrameworkResource { @@ -35,11 +43,15 @@ func (p *servicePackage) ServicePackageName() string { return names.Bedrock } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*bedrock_sdkv1.Bedrock, error) { - sess := config["session"].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*bedrock_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return bedrock_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return bedrock_sdkv2.NewFromConfig(cfg, func(o *bedrock_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/names/names_data.csv b/names/names_data.csv index 5146313f855..f5e5e6d7787 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -34,7 +34,7 @@ autoscaling-plans,autoscalingplans,autoscalingplans,autoscalingplans,,autoscalin backup,backup,backup,backup,,backup,,,Backup,Backup,,1,,,aws_backup_,,backup_,Backup,AWS,,,,,, backup-gateway,backupgateway,backupgateway,backupgateway,,backupgateway,,,BackupGateway,BackupGateway,,1,,,aws_backupgateway_,,backupgateway_,Backup Gateway,AWS,,x,,,, batch,batch,batch,batch,,batch,,,Batch,Batch,,1,,,aws_batch_,,batch_,Batch,AWS,,,,,, -bedrock,bedrock,bedrock,,,bedrock,,,Bedrock,Bedrock,,1,,,aws_bedrock_,,bedrock_,Amazon Bedrock,Amazon,,,,,, +bedrock,bedrock,bedrock,bedrock,,bedrock,,,Bedrock,Bedrock,,,2,,aws_bedrock_,,bedrock_,Amazon Bedrock,Amazon,,,,,, billingconductor,billingconductor,billingconductor,,,billingconductor,,,BillingConductor,BillingConductor,,1,,,aws_billingconductor_,,billingconductor_,Billing Conductor,AWS,,x,,,, braket,braket,braket,braket,,braket,,,Braket,Braket,,1,,,aws_braket_,,braket_,Braket,Amazon,,x,,,, ce,ce,costexplorer,costexplorer,,ce,,costexplorer,CE,CostExplorer,,1,,,aws_ce_,,ce_,CE (Cost Explorer),AWS,,,,,, diff --git a/website/docs/d/bedrock_foundation_model.html.markdown b/website/docs/d/bedrock_foundation_model.html.markdown new file mode 100644 index 00000000000..9d830af415a --- /dev/null +++ b/website/docs/d/bedrock_foundation_model.html.markdown @@ -0,0 +1,42 @@ +--- +subcategory: "Amazon Bedrock" +layout: "aws" +page_title: "AWS: aws_bedrock_foundation_model" +description: |- + Terraform data source for managing an AWS Bedrock Foundation Model. +--- + +# Data Source: aws_bedrock_foundation_model + +Terraform data source for managing an AWS Bedrock Foundation Model. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_bedrock_foundation_models" "test" {} + +data "aws_bedrock_foundation_model" "test" { + model_id = data.aws_bedrock_foundation_models.test.model_summaries[0].model_id +} +``` + +## Argument Reference + +The following argument are required: + +* `model_id` – (Required) Model identifier. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `customizations_supported` - Customizations that the model supports. +* `inference_types_supported` - Inference types that the model supports. +* `input_modalities` - Input modalities that the model supports. +* `model_arn` - Model ARN. +* `model_name` - Model name. +* `output_modalities` - Output modalities that the model supports. +* `provider_name` - Model provider name. +* `response_streaming_supported` - Indicates whether the model supports streaming. diff --git a/website/docs/d/bedrock_foundation_models.html.markdown b/website/docs/d/bedrock_foundation_models.html.markdown new file mode 100644 index 00000000000..3a7c27daa41 --- /dev/null +++ b/website/docs/d/bedrock_foundation_models.html.markdown @@ -0,0 +1,55 @@ +--- +subcategory: "Amazon Bedrock" +layout: "aws" +page_title: "AWS: aws_bedrock_foundation_models" +description: |- + Terraform data source for managing AWS Bedrock Foundation Models. +--- + +# Data Source: aws_bedrock_foundation_models + +Terraform data source for managing AWS Bedrock Foundation Models. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_bedrock_foundation_models" "test" {} +``` + +### Filter by Inference Type + +```terraform +data "aws_bedrock_foundation_models" "test" { + by_inference_type = "ON_DEMAND" +} +``` + +## Argument Reference + +The following arguments are optional: + +* `by_customization_type` - (Optional) Customization type to filter on. Valid values are `FINE_TUNING`. +* `by_inference_type` - (Optional) Inference type to filter on. Valid values are `ON_DEMAND` and `PROVISIONED`. +* `by_output_modality` - (Optional) Output modality to filter on. Valid values are `TEXT`, `IMAGE`, and `EMBEDDING`. +* `by_provider` - (Optional) Model provider to filter on. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `id` - AWS region. +* `model_summaries` - List of model summary objects. See [`model_summaries`](#model_summaries). + +### `model_summaries` + +* `customizations_supported` - Customizations that the model supports. +* `inference_types_supported` - Inference types that the model supports. +* `input_modalities` - Input modalities that the model supports. +* `model_arn` - Model ARN. +* `model_id` - Model identifier. +* `model_name` - Model name. +* `output_modalities` - Output modalities that the model supports. +* `provider_name` - Model provider name. +* `response_streaming_supported` - Indicates whether the model supports streaming.