Skip to content

Commit

Permalink
Merge pull request #37039 from Thomas-Franklin/f-backup-restore-testing
Browse files Browse the repository at this point in the history
[NEW RESOURCE] AWS Backup Restore Testing
  • Loading branch information
ewbankkit authored Oct 4, 2024
2 parents df28ac9 + 14eaa5d commit e795bef
Show file tree
Hide file tree
Showing 15 changed files with 1,925 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changelog/37039.txt
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
```
4 changes: 4 additions & 0 deletions internal/framework/types/mapof.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ type MapValueOf[T attr.Value] struct {
basetypes.MapValue
}

type (
MapOfString = MapValueOf[basetypes.StringValue]
)

func (v MapValueOf[T]) Equal(o attr.Value) bool {
other, ok := o.(MapValueOf[T])

Expand Down
9 changes: 9 additions & 0 deletions internal/framework/types/setof.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ type setTypeOf[T attr.Value] struct {
}

var (
// SetOfStringType is a custom type used for defining a Set of strings.
SetOfStringType = setTypeOf[basetypes.StringValue]{basetypes.SetType{ElemType: basetypes.StringType{}}}

// SetOfARNType is a custom type used for defining a Set of ARNs.
SetOfARNType = setTypeOf[ARN]{basetypes.SetType{ElemType: ARNType}}
)

func NewSetTypeOf[T attr.Value](ctx context.Context) setTypeOf[T] {
Expand Down Expand Up @@ -97,6 +101,11 @@ type SetValueOf[T attr.Value] struct {
basetypes.SetValue
}

type (
SetOfString = SetValueOf[basetypes.StringValue]
SetOfARN = SetValueOf[ARN]
)

func (v SetValueOf[T]) Equal(o attr.Value) bool {
other, ok := o.(SetValueOf[T])

Expand Down
41 changes: 41 additions & 0 deletions internal/framework/validators/arn.go
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{}
}
61 changes: 61 additions & 0 deletions internal/framework/validators/arn_test.go
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)
}
})
}
}
4 changes: 4 additions & 0 deletions internal/service/backup/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var (
ResourcePlan = resourcePlan
ResourceRegionSettings = resourceRegionSettings
ResourceReportPlan = resourceReportPlan
ResourceRestoreTestingPlan = newRestoreTestingPlanResource
ResourceRestoreTestingSelection = newRestoreTestingSelectionResource
ResourceSelection = resourceSelection
ResourceVault = resourceVault
ResourceVaultLockConfiguration = resourceVaultLockConfiguration
Expand All @@ -24,6 +26,8 @@ var (
FindPlanByID = findPlanByID
FindRegionSettings = findRegionSettings
FindReportPlanByName = findReportPlanByName
FindRestoreTestingPlanByName = findRestoreTestingPlanByName
FindRestoreTestingSelectionByTwoPartKey = findRestoreTestingSelectionByTwoPartKey
FindSelectionByTwoPartKey = findSelectionByTwoPartKey
FindVaultAccessPolicyByName = findVaultAccessPolicyByName
FindVaultNotificationsByName = findVaultNotificationsByName
Expand Down
2 changes: 1 addition & 1 deletion internal/service/backup/logically_air_gapped_vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ type logicallyAirGappedVaultResourceModel struct {
ID types.String `tfsdk:"id"`
MaxRetentionDays types.Int64 `tfsdk:"max_retention_days"`
MinRetentionDays types.Int64 `tfsdk:"min_retention_days"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
Tags tftags.Map `tfsdk:"tags"`
TagsAll tftags.Map `tfsdk:"tags_all"`
Timeouts timeouts.Value `tfsdk:"timeouts"`
}

func findLogicallyAirGappedBackupVaultByName(ctx context.Context, conn *backup.Client, name string) (*backup.DescribeBackupVaultOutput, error) { // nosemgrep:ci.backup-in-func-name
Expand Down
Loading

0 comments on commit e795bef

Please sign in to comment.