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

New Resource: Bedrock Agent Alias #36905

Merged
merged 40 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
759ced3
Added Agent Alias
Apr 7, 2024
690eab6
Added 2 Part Key
Apr 11, 2024
728890c
Merge branch 'f-aws_bedrock_agent' of github.com:meetreks/terraform-p…
drewtul Apr 12, 2024
20f52da
Initial work on alias from @meetreks
drewtul Apr 12, 2024
e3e5377
Merge branch 'f-aws_bedrock_agent' into f-aws_bedrockagent_alias
drewtul Apr 12, 2024
ce07bef
Merge branch 'f-aws_bedrock_agent' into f-aws_bedrockagent_alias
drewtul Apr 12, 2024
37a4358
Tidy up commented code and duplicate copying of values
drewtul Apr 12, 2024
ae3319b
Full Tests OK
Apr 14, 2024
b19e103
Update from @meetreks
drewtul Apr 14, 2024
fef3081
Fix imports
drewtul Apr 14, 2024
0f62b02
Add test for updating routing to new version
drewtul Apr 14, 2024
3a4184f
First pass on docs
drewtul Apr 14, 2024
48916b7
Formatting
drewtul Apr 14, 2024
aa28fd1
Resource name
drewtul Apr 14, 2024
87f51db
Add wait for update, fix test assertions.
drewtul Apr 14, 2024
6474118
Changelog
drewtul Apr 14, 2024
be78dcd
License header
drewtul Apr 14, 2024
d6420e6
Formatting
drewtul Apr 14, 2024
6cf345f
Fix resource name
drewtul Apr 14, 2024
bb8ab95
Fix resource name
drewtul Apr 14, 2024
045760a
Fix double import
drewtul Apr 14, 2024
15bc32e
Actually fix naming correctly
drewtul Apr 14, 2024
14b6a50
Import docs
drewtul Apr 14, 2024
4c41901
Extract updated version to variable
drewtul Apr 15, 2024
7fe7c5f
Add export to avoid re-implementing find for tests
drewtul Apr 15, 2024
f224114
Make the parts a const to quiet lint warning
drewtul Apr 15, 2024
1ab2516
Use const in one more place
drewtul Apr 15, 2024
ba0b336
Merge branch 'f-aws_bedrock_agent' into f-aws_bedrockagent_alias
drewtul Apr 19, 2024
b80efbf
Update wait function to match changes from @ewbankkit in other PRs
drewtul Apr 19, 2024
843f78c
Tidy up to match changes from @ewbankkit in other PRs
drewtul Apr 19, 2024
7429bbd
Adjust resource name
drewtul Apr 19, 2024
2879789
make gen
drewtul Apr 19, 2024
f0cfcb6
Sort test exports
drewtul Apr 19, 2024
32629bd
Merge branch 'main' into HEAD
ewbankkit Apr 19, 2024
d47b038
r/aws_bedrockagent_agent: Tidy up acceptance tests.
ewbankkit Apr 19, 2024
eaa1631
r/aws_bedrockagent_agent: Simplify calls to 'tfresource.SetLastError'.
ewbankkit Apr 19, 2024
2445580
r/aws_bedrockagent_agent: Validate 'agent_name'.
ewbankkit Apr 19, 2024
bcd51e9
r/aws_bedrockagent_agent_alias: Tidy up.
ewbankkit Apr 19, 2024
151b665
r/aws_bedrockagent_agent_alias: Fix up acceptance tests.
ewbankkit Apr 19, 2024
88fcc27
Correct resource name in CHANGELOG.
ewbankkit Apr 19, 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
3 changes: 3 additions & 0 deletions .changelog/36905.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_bedrockagent_agent_alias
```
31 changes: 27 additions & 4 deletions internal/service/bedrockagent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"time"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/bedrockagent"
awstypes "github.com/aws/aws-sdk-go-v2/service/bedrockagent/types"
Expand Down Expand Up @@ -69,6 +70,9 @@ func (r *agentResource) Schema(ctx context.Context, request resource.SchemaReque
"agent_id": framework.IDAttribute(),
"agent_name": schema.StringAttribute{
Required: true,
Validators: []validator.String{
stringvalidator.RegexMatches(regexache.MustCompile(`^([0-9a-zA-Z][_-]?){1,100}$`), "valid characters are a-z, A-Z, 0-9, _ (underscore) and - (hyphen). The name can have up to 100 characters"),
},
},
"agent_resource_role_arn": schema.StringAttribute{
CustomType: fwtypes.ARNType,
Expand Down Expand Up @@ -438,7 +442,7 @@ func waitAgentCreated(ctx context.Context, conn *bedrockagent.Client, id string,
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*awstypes.Agent); ok {
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, func(s string) error { return errors.New(s) })...))
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, errors.New)...))

return output, err
}
Expand All @@ -457,7 +461,7 @@ func waitAgentUpdated(ctx context.Context, conn *bedrockagent.Client, id string,
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*awstypes.Agent); ok {
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, func(s string) error { return errors.New(s) })...))
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, errors.New)...))

return output, err
}
Expand All @@ -476,7 +480,26 @@ func waitAgentPrepared(ctx context.Context, conn *bedrockagent.Client, id string
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*awstypes.Agent); ok {
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, func(s string) error { return errors.New(s) })...))
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, errors.New)...))

return output, err
}

return nil, err
}

func waitAgentVersioned(ctx context.Context, conn *bedrockagent.Client, id string, timeout time.Duration) (*awstypes.Agent, error) {
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(awstypes.AgentStatusVersioning),
Target: enum.Slice(awstypes.AgentStatusPrepared),
Refresh: statusAgent(ctx, conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*awstypes.Agent); ok {
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, errors.New)...))

return output, err
}
Expand All @@ -495,7 +518,7 @@ func waitAgentDeleted(ctx context.Context, conn *bedrockagent.Client, id string,
outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*awstypes.Agent); ok {
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, func(s string) error { return errors.New(s) })...))
tfresource.SetLastError(err, errors.Join(tfslices.ApplyToAll(output.FailureReasons, errors.New)...))

return output, err
}
Expand Down
Loading
Loading