-
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 #37039 from Thomas-Franklin/f-backup-restore-testing
[NEW RESOURCE] AWS Backup Restore Testing
- Loading branch information
Showing
15 changed files
with
1,925 additions
and
5 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,7 @@ | ||
```release-note:new-resource | ||
aws_backup_restore_testing_plan | ||
``` | ||
|
||
```release-note:new-resource | ||
aws_backup_restore_testing_selection | ||
``` |
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,41 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package validators | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws/arn" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
type arnValidator struct{} | ||
|
||
func (validator arnValidator) Description(_ context.Context) string { | ||
return "An Amazon Resource Name" | ||
} | ||
|
||
func (validator arnValidator) MarkdownDescription(ctx context.Context) string { | ||
return validator.Description(ctx) | ||
} | ||
|
||
func (validator arnValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { | ||
if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
if !arn.IsARN(request.ConfigValue.ValueString()) { | ||
response.Diagnostics.Append(diag.NewAttributeErrorDiagnostic( | ||
request.Path, | ||
validator.Description(ctx), | ||
"value must be a valid ARN", | ||
)) | ||
return | ||
} | ||
} | ||
|
||
func ARN() validator.String { | ||
return arnValidator{} | ||
} |
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,61 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package validators_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"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 TestARNValidator(t *testing.T) { | ||
t.Parallel() | ||
|
||
type testCase struct { | ||
val types.String | ||
expectError bool | ||
} | ||
|
||
tests := map[string]testCase{ | ||
"unknown String": { | ||
val: types.StringUnknown(), | ||
}, | ||
"null String": { | ||
val: types.StringNull(), | ||
}, | ||
"valid arn": { | ||
val: types.StringValue("arn:aws:iam::aws:policy/CloudWatchReadOnlyAccess"), | ||
}, | ||
"invalid_arn": { | ||
val: types.StringValue("arn"), | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
request := validator.StringRequest{ | ||
Path: path.Root("test"), | ||
PathExpression: path.MatchRoot("test"), | ||
ConfigValue: test.val, | ||
} | ||
response := validator.StringResponse{} | ||
fwvalidators.ARN().ValidateString(context.Background(), request, &response) | ||
|
||
if !response.Diagnostics.HasError() && test.expectError { | ||
t.Fatal("expected error, got no error") | ||
} | ||
|
||
if response.Diagnostics.HasError() && !test.expectError { | ||
t.Fatalf("got unexpected error: %s", response.Diagnostics) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.