-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34310 from skyscrapr/f-aws_bedrock_custom_model
F aws bedrock custom model
- Loading branch information
Showing
28 changed files
with
2,499 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.