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

F aws bedrock custom model #34310

Merged
merged 64 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
cdff23e
add support for custom model resource and datasources
skyscrapr Nov 8, 2023
49e4707
better test
skyscrapr Nov 8, 2023
88704f1
add test data
skyscrapr Nov 8, 2023
51ceeb8
terrafmt fixes
skyscrapr Nov 8, 2023
416bf28
add docs
skyscrapr Nov 8, 2023
817063c
make semall fixes
skyscrapr Nov 8, 2023
579d663
linting fixes
skyscrapr Nov 9, 2023
e1b6895
fix custom model resource
skyscrapr Dec 11, 2023
afa16cd
make gen
skyscrapr Dec 11, 2023
561a540
attributes, customization type
AdamTylerLynch Dec 13, 2023
744183a
atrributes arn
AdamTylerLynch Dec 13, 2023
59f38f5
attrtibutes base_model_identifier
AdamTylerLynch Dec 14, 2023
0761606
attribute ordering
AdamTylerLynch Dec 14, 2023
2d5bda2
attributes custom model
AdamTylerLynch Dec 14, 2023
418d5da
attri custom model name
AdamTylerLynch Dec 14, 2023
9dc48cd
schema alignment
AdamTylerLynch Dec 19, 2023
fdddecd
schemas and expand
AdamTylerLynch Dec 21, 2023
9c6b0c9
Merge branch 'main' into HEAD
ewbankkit Jan 28, 2024
a712fc4
d/aws_bedrock_foundation_models: Use AutoFlEx.
ewbankkit Jan 28, 2024
bdbca57
Acceptance test output:
ewbankkit Jan 28, 2024
cf35f53
d/aws_bedrock_custom_models: Use AutoFlEx.
ewbankkit Jan 28, 2024
9e2cd12
d/aws_bedrock_foundation_model: Use AutoFlEx.
ewbankkit Jan 28, 2024
34ebc2b
Acceptance test output:
ewbankkit Jan 28, 2024
9d13c51
d/aws_bedrock_custom_model: Use AutoFlEx.
ewbankkit Jan 28, 2024
72ed7d2
Add CHANGELOG entry.
ewbankkit Jan 28, 2024
6de445a
Add 'MapOfStringType'.
ewbankkit Jan 29, 2024
2a4578a
Add 'framework.validators.S3URI'.
ewbankkit Jan 29, 2024
524f453
r/aws_bedrock_custom_model: Use AutoFlEx.
ewbankkit Jan 29, 2024
4ba5e6c
r/aws_bedrock_custom_model: Ensure everything is ForceNew.
ewbankkit Jan 29, 2024
7bfdb15
r/aws_bedrock_custom_model: Some fixes.
ewbankkit Jan 30, 2024
5b67d64
r/aws_bedrock_custom_models: Use 'fwtypes.Timestamp' for 'creation_ti…
ewbankkit Jan 30, 2024
4c958ff
d/aws_bedrock_custom_model: Use list-of-object for 'Computed blocks',…
ewbankkit Jan 30, 2024
1082c3c
r/aws_bedrock_custom_model: Use list-of-object for 'Computed blocks',…
ewbankkit Jan 30, 2024
89fd2bd
r/aws_bedrock_custom_model: We need to read both the job and the mode…
ewbankkit Jan 30, 2024
a0797ca
r/aws_bedrock_custom_model: Get Read working.
ewbankkit Jan 30, 2024
aa17dce
r/aws_bedrock_custom_model: Start to update documentation to reflect …
ewbankkit Jan 31, 2024
43fe744
Documentation tweaks from Tyler.
ewbankkit Jan 31, 2024
ff6c31f
r/aws_bedrock_custom_model: Update documentation to reflect new behav…
ewbankkit Jan 31, 2024
24b2463
r/aws_bedrock_custom_model: New lifecycle.
ewbankkit Jan 31, 2024
27ab715
r/aws_bedrock_custom_model: Better handling of Stopped jobs.
ewbankkit Jan 31, 2024
d6c6a8f
r/aws_bedrock_custom_model: Tidy up acceptance tests.
ewbankkit Jan 31, 2024
ff0c849
Acceptance test output:
ewbankkit Jan 31, 2024
3971cf9
r/aws_bedrock_custom_model: Further acceptance tests.
ewbankkit Jan 31, 2024
fba2e9c
Acceptance test output:
ewbankkit Jan 31, 2024
2ddfe54
Fix markdown-lint 'MD032/blanks-around-lists Lists should be surround…
ewbankkit Jan 31, 2024
99cec8d
Export 'waitModelCustomizationJobCompleted' for use in acceptance tests.
ewbankkit Feb 1, 2024
53d0a74
'flex.Float32FromFrameworkFloat64' not used.
ewbankkit Feb 1, 2024
f273acc
Merge branch 'main' into HEAD
ewbankkit Feb 1, 2024
c5ffce7
Restore 'flex.StringEnum.StringEnumValue'.
ewbankkit Feb 1, 2024
1d468bb
bedrock: Move stuff around.
ewbankkit Feb 1, 2024
9906cb4
Add 'TestAccBedrockCustomModel_validationDataConfig'.
ewbankkit Feb 1, 2024
ec95a52
Acceptance test output:
ewbankkit Feb 1, 2024
9e9023b
d/aws_bedrock_custom_models: Tidy up.
ewbankkit Feb 1, 2024
2cb1a47
bedrock: Correct IAM permissions in acceptance tests.
ewbankkit Feb 1, 2024
d4fe947
d/aws_bedrock_custom_model: Tidy up.
ewbankkit Feb 1, 2024
c430dc5
Add 'TestAccBedrockCustomModel_kmsKey'.
ewbankkit Feb 1, 2024
79553e1
Acceptance test output:
ewbankkit Feb 1, 2024
b87c529
d/aws_bedrock_custom_model: Read some attributes from the customizati…
ewbankkit Feb 1, 2024
e8b5f39
bedrock: Tweak custom model data source tests.
ewbankkit Feb 1, 2024
f5c1165
testAccCheckCustomModelDestroy: Check for deleted custom model.
ewbankkit Feb 1, 2024
81ddd4a
bedrock: Use 'testing.Short()' guards.
ewbankkit Feb 1, 2024
898f26e
d/aws_bedrock_foundation_models: Fix acceptance tests.
ewbankkit Feb 1, 2024
4c781fb
Fix typo.
ewbankkit Feb 1, 2024
2222c5c
d/aws_bedrock_custom_model: Fix acceptance tests.
ewbankkit Feb 2, 2024
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
11 changes: 11 additions & 0 deletions .changelog/34310.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:new-data-source
aws_bedrock_custom_model
```

```release-note:new-data-source
aws_bedrock_custom_models
```

```release-note:resource
aws_bedrock_custom_model
```
23 changes: 20 additions & 3 deletions internal/framework/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -107,10 +108,26 @@ func (w *WithImportByID) ImportState(ctx context.Context, request resource.Impor
resource.ImportStatePassthroughID(ctx, path.Root(names.AttrID), request, response)
}

// WithNoOpUpdate is intended to be embedded in resources which have no need of an Update method.
type WithNoOpUpdate struct{}
// WithNoUpdate is intended to be embedded in resources which cannot be updated.
type WithNoUpdate struct{}

func (w *WithNoOpUpdate) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) {
func (w *WithNoUpdate) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) {
response.Diagnostics.Append(diag.NewErrorDiagnostic("not supported", "This resource's Update method should not have been called"))
}

// WithNoOpUpdate is intended to be embedded in resources which have no need of a custom Update method.
// For example, resources where only `tags` can be updated and that is handled via transparent tagging.
type WithNoOpUpdate[T any] struct{}

func (w *WithNoOpUpdate[T]) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) {
var t T

response.Diagnostics.Append(request.Plan.Get(ctx, &t)...)
if response.Diagnostics.HasError() {
return
}

response.Diagnostics.Append(response.State.Set(ctx, &t)...)
}

// DataSourceWithConfigure is a structure to be embedded within a DataSource that implements the DataSourceWithConfigure interface.
Expand Down
29 changes: 17 additions & 12 deletions internal/framework/types/mapof.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ import (
)

var (
_ basetypes.MapTypable = MapTypeOf[basetypes.StringValue]{}
_ basetypes.MapTypable = mapTypeOf[basetypes.StringValue]{}
_ basetypes.MapValuable = MapValueOf[basetypes.StringValue]{}
)

// MapTypeOf is the attribute type of a MapValueOf.
type MapTypeOf[T attr.Value] struct {
var (
// MapOfStringType is a custom type used for defining a Map of strings.
MapOfStringType = mapTypeOf[basetypes.StringValue]{basetypes.MapType{ElemType: basetypes.StringType{}}}
)

type mapTypeOf[T attr.Value] struct {
basetypes.MapType
}

func NewMapTypeOf[T attr.Value](ctx context.Context) MapTypeOf[T] {
func NewMapTypeOf[T attr.Value](ctx context.Context) mapTypeOf[T] {
var zero T
return MapTypeOf[T]{basetypes.MapType{ElemType: zero.Type(ctx)}}
return mapTypeOf[T]{basetypes.MapType{ElemType: zero.Type(ctx)}}
}

func (t MapTypeOf[T]) Equal(o attr.Type) bool {
other, ok := o.(MapTypeOf[T])
func (t mapTypeOf[T]) Equal(o attr.Type) bool {
other, ok := o.(mapTypeOf[T])

if !ok {
return false
Expand All @@ -40,18 +44,19 @@ func (t MapTypeOf[T]) Equal(o attr.Type) bool {
return t.MapType.Equal(other.MapType)
}

func (t MapTypeOf[T]) String() string {
func (t mapTypeOf[T]) String() string {
var zero T
return fmt.Sprintf("%T", zero)
}

func (t MapTypeOf[T]) ValueFromMap(ctx context.Context, in basetypes.MapValue) (basetypes.MapValuable, diag.Diagnostics) {
func (t mapTypeOf[T]) ValueFromMap(ctx context.Context, in basetypes.MapValue) (basetypes.MapValuable, diag.Diagnostics) {
var diags diag.Diagnostics
var zero T

if in.IsNull() {
return NewMapValueOfNull[T](ctx), diags
}

if in.IsUnknown() {
return NewMapValueOfUnknown[T](ctx), diags
}
Expand All @@ -73,7 +78,7 @@ func (t MapTypeOf[T]) ValueFromMap(ctx context.Context, in basetypes.MapValue) (
return value, diags
}

func (t MapTypeOf[T]) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
func (t mapTypeOf[T]) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
attrValue, err := t.MapType.ValueFromTerraform(ctx, in)

if err != nil {
Expand All @@ -93,11 +98,11 @@ func (t MapTypeOf[T]) ValueFromTerraform(ctx context.Context, in tftypes.Value)
return mapValuable, nil
}

func (t MapTypeOf[T]) ValueType(ctx context.Context) attr.Value {
func (t mapTypeOf[T]) ValueType(ctx context.Context) attr.Value {
return MapValueOf[T]{}
}

// MapValueOf represents a Terraform Plugin Framework Map value whose elements are of type MapTypeOf.
// MapValueOf represents a Terraform Plugin Framework Map value whose elements are of type mapTypeOf.
type MapValueOf[T attr.Value] struct {
basetypes.MapValue
}
Expand Down
1 change: 1 addition & 0 deletions internal/framework/types/string_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func (v StringEnum[T]) ValueEnum() T {

// StringEnumValue is useful if you have a zero value StringEnum but need a
// way to get a non-zero value such as when flattening.
// It's called via reflection inside AutoFlEx.
func (v StringEnum[T]) StringEnumValue(value string) StringEnum[T] {
return StringEnum[T]{StringValue: basetypes.NewStringValue(value)}
}
48 changes: 48 additions & 0 deletions internal/framework/validators/s3_uri.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package validators

import (
"context"

"github.com/YakDriver/regexache"
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

// s3URIValidator validates that a string Attribute's value is a valid S3 URI.
type s3URIValidator struct{}

func (validator s3URIValidator) Description(_ context.Context) string {
return "value must be a valid S3 URI"
}

func (validator s3URIValidator) MarkdownDescription(ctx context.Context) string {
return validator.Description(ctx)
}

func (validator s3URIValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {
if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() {
return
}

if !regexache.MustCompile(`^s3://[a-z0-9][\.\-a-z0-9]{1,61}[a-z0-9](/.*)?$`).MatchString(request.ConfigValue.ValueString()) {
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
request.Path,
validator.Description(ctx),
request.ConfigValue.ValueString(),
))
return
}
}

// S3URI returns a string validator which ensures that any configured
// attribute value:
//
// - Is a string, which represents a valid S3 URI (s3://bucket[/key]).
//
// Null (unconfigured) and unknown (known after apply) values are skipped.
func S3URI() validator.String {
return s3URIValidator{}
}
77 changes: 77 additions & 0 deletions internal/framework/validators/s3_uri_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package validators_test

import (
"context"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators"
)

func TestS3URIValidator(t *testing.T) {
t.Parallel()

type testCase struct {
val types.String
expectedDiagnostics diag.Diagnostics
}
tests := map[string]testCase{
"unknown String": {
val: types.StringUnknown(),
},
"null String": {
val: types.StringNull(),
},
"invalid String": {
val: types.StringValue("test-value"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid S3 URI, got: test-value`,
),
},
},
"valid S3 URI": {
val: types.StringValue("s3://bucket/path/to/key"),
},
"invalid characters": {
val: types.StringValue("s3://asbcdefg--#/key"),
expectedDiagnostics: diag.Diagnostics{
diag.NewAttributeErrorDiagnostic(
path.Root("test"),
"Invalid Attribute Value",
`Attribute test value must be a valid S3 URI, got: s3://asbcdefg--#/key`,
),
},
},
}

for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
t.Parallel()

ctx := context.Background()

request := validator.StringRequest{
Path: path.Root("test"),
PathExpression: path.MatchRoot("test"),
ConfigValue: test.val,
}
response := validator.StringResponse{}
fwvalidators.S3URI().ValidateString(ctx, request, &response)

if diff := cmp.Diff(response.Diagnostics, test.expectedDiagnostics); diff != "" {
t.Errorf("unexpected diagnostics difference: %s", diff)
}
})
}
}
12 changes: 12 additions & 0 deletions internal/service/bedrock/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package bedrock

import (
"time"
)

const (
propagationTimeout = 2 * time.Minute
)
Loading
Loading