-
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 #35408 from drewtul/f-mainframe-deployment-resource
AWS Mainframe Modernisation Service Deployment Resource
- Loading branch information
Showing
27 changed files
with
3,922 additions
and
2 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,3 @@ | ||
```release-note:new-resource | ||
aws_m2_environment | ||
``` |
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,3 @@ | ||
```release-note:new-resource | ||
aws_m2_application | ||
``` |
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,3 @@ | ||
```release-note:new-resource | ||
aws_m2_deployment | ||
``` |
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,170 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package types | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/YakDriver/regexache" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/attr/xattr" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
) | ||
|
||
var ( | ||
_ xattr.TypeWithValidate = (*onceAWeekWindowType)(nil) | ||
_ basetypes.StringTypable = (*onceAWeekWindowType)(nil) | ||
_ basetypes.StringValuable = (*OnceAWeekWindow)(nil) | ||
_ basetypes.StringValuableWithSemanticEquals = (*OnceAWeekWindow)(nil) | ||
) | ||
|
||
type onceAWeekWindowType struct { | ||
basetypes.StringType | ||
} | ||
|
||
var ( | ||
OnceAWeekWindowType = onceAWeekWindowType{} | ||
) | ||
|
||
func (t onceAWeekWindowType) Equal(o attr.Type) bool { | ||
other, ok := o.(onceAWeekWindowType) | ||
if !ok { | ||
return false | ||
} | ||
|
||
return t.StringType.Equal(other.StringType) | ||
} | ||
|
||
func (onceAWeekWindowType) String() string { | ||
return "OnceAWeekWindowType" | ||
} | ||
|
||
func (t onceAWeekWindowType) ValueFromString(_ context.Context, in types.String) (basetypes.StringValuable, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
|
||
if in.IsNull() { | ||
return OnceAWeekWindowNull(), diags | ||
} | ||
if in.IsUnknown() { | ||
return OnceAWeekWindowUnknown(), diags | ||
} | ||
|
||
return OnceAWeekWindowValue(in.ValueString()), diags | ||
} | ||
|
||
func (t onceAWeekWindowType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { | ||
attrValue, err := t.StringType.ValueFromTerraform(ctx, in) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stringValue, ok := attrValue.(basetypes.StringValue) | ||
if !ok { | ||
return nil, fmt.Errorf("unexpected value type of %T", attrValue) | ||
} | ||
|
||
stringValuable, diags := t.ValueFromString(ctx, stringValue) | ||
if diags.HasError() { | ||
return nil, fmt.Errorf("unexpected error converting StringValue to StringValuable: %v", diags) | ||
} | ||
|
||
return stringValuable, nil | ||
} | ||
|
||
func (onceAWeekWindowType) ValueType(context.Context) attr.Value { | ||
return OnceAWeekWindow{} | ||
} | ||
|
||
func (t onceAWeekWindowType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
|
||
if !in.IsKnown() || in.IsNull() { | ||
return diags | ||
} | ||
|
||
var value string | ||
err := in.As(&value) | ||
if err != nil { | ||
diags.AddAttributeError( | ||
path, | ||
"OnceAWeekWindowType Validation Error", | ||
ProviderErrorDetailPrefix+fmt.Sprintf("Cannot convert value to string: %s", err), | ||
) | ||
return diags | ||
} | ||
|
||
// Valid time format is "ddd:hh24:mi". | ||
validTimeFormat := "(sun|mon|tue|wed|thu|fri|sat):([0-1][0-9]|2[0-3]):([0-5][0-9])" | ||
validTimeFormatConsolidated := "^(" + validTimeFormat + "-" + validTimeFormat + "|)$" | ||
|
||
if v := strings.ToLower(value); !regexache.MustCompile(validTimeFormatConsolidated).MatchString(v) { | ||
diags.AddAttributeError( | ||
path, | ||
"OnceAWeekWindowType Validation Error", | ||
fmt.Sprintf("Value %q must satisfy the format of \"ddd:hh24:mi-ddd:hh24:mi\".", value), | ||
) | ||
return diags | ||
} | ||
|
||
return diags | ||
} | ||
|
||
type OnceAWeekWindow struct { | ||
basetypes.StringValue | ||
} | ||
|
||
func OnceAWeekWindowNull() OnceAWeekWindow { | ||
return OnceAWeekWindow{StringValue: basetypes.NewStringNull()} | ||
} | ||
|
||
func OnceAWeekWindowUnknown() OnceAWeekWindow { | ||
return OnceAWeekWindow{StringValue: basetypes.NewStringUnknown()} | ||
} | ||
|
||
func OnceAWeekWindowValue(value string) OnceAWeekWindow { | ||
return OnceAWeekWindow{StringValue: basetypes.NewStringValue(value)} | ||
} | ||
|
||
func (v OnceAWeekWindow) Equal(o attr.Value) bool { | ||
other, ok := o.(OnceAWeekWindow) | ||
if !ok { | ||
return false | ||
} | ||
|
||
return v.StringValue.Equal(other.StringValue) | ||
} | ||
|
||
func (OnceAWeekWindow) Type(context.Context) attr.Type { | ||
return OnceAWeekWindowType | ||
} | ||
|
||
func (v OnceAWeekWindow) StringSemanticEquals(ctx context.Context, newValuable basetypes.StringValuable) (bool, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
|
||
newValue, ok := newValuable.(OnceAWeekWindow) | ||
if !ok { | ||
return false, diags | ||
} | ||
|
||
old, d := v.ToStringValue(ctx) | ||
diags.Append(d...) | ||
if diags.HasError() { | ||
return false, diags | ||
} | ||
|
||
new, d := newValue.ToStringValue(ctx) | ||
diags.Append(d...) | ||
if diags.HasError() { | ||
return false, diags | ||
} | ||
|
||
// Case insensitive comparison. | ||
return strings.EqualFold(old.ValueString(), new.ValueString()), diags | ||
} |
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,114 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package types_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/path" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" | ||
) | ||
|
||
func TestOnceAWeekWindowTypeValidate(t *testing.T) { | ||
t.Parallel() | ||
|
||
type testCase struct { | ||
val tftypes.Value | ||
expectError bool | ||
} | ||
tests := map[string]testCase{ | ||
"not a string": { | ||
val: tftypes.NewValue(tftypes.Bool, true), | ||
expectError: true, | ||
}, | ||
"unknown string": { | ||
val: tftypes.NewValue(tftypes.String, tftypes.UnknownValue), | ||
}, | ||
"null string": { | ||
val: tftypes.NewValue(tftypes.String, nil), | ||
}, | ||
"valid string lowercase": { | ||
val: tftypes.NewValue(tftypes.String, "thu:07:44-thu:09:44"), | ||
}, | ||
"valid string uppercase": { | ||
val: tftypes.NewValue(tftypes.String, "THU:07:44-THU:09:44"), | ||
}, | ||
"invalid string": { | ||
val: tftypes.NewValue(tftypes.String, "thu:25:44-zat:09:88"), | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
name, test := name, test | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
diags := fwtypes.OnceAWeekWindowType.Validate(ctx, test.val, path.Root("test")) | ||
|
||
if !diags.HasError() && test.expectError { | ||
t.Fatal("expected error, got no error") | ||
} | ||
|
||
if diags.HasError() && !test.expectError { | ||
t.Fatalf("got unexpected error: %#v", diags) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestOnceAWeekWindowStringSemanticEquals(t *testing.T) { | ||
t.Parallel() | ||
|
||
type testCase struct { | ||
val1, val2 fwtypes.OnceAWeekWindow | ||
equals bool | ||
} | ||
tests := map[string]testCase{ | ||
"both lowercase, equal": { | ||
val1: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"), | ||
val2: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"), | ||
equals: true, | ||
}, | ||
"both uppercase, equal": { | ||
val1: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"), | ||
val2: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"), | ||
equals: true, | ||
}, | ||
"first uppercase, second lowercase, equal": { | ||
val1: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"), | ||
val2: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"), | ||
equals: true, | ||
}, | ||
"first lowercase, second uppercase, equal": { | ||
val1: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"), | ||
val2: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"), | ||
equals: true, | ||
}, | ||
"not equal": { | ||
val1: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"), | ||
val2: fwtypes.OnceAWeekWindowValue("thu:07:44-fri:11:09"), | ||
equals: false, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
name, test := name, test | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
equals, _ := test.val1.StringSemanticEquals(ctx, test.val2) | ||
|
||
if got, want := equals, test.equals; got != want { | ||
t.Errorf("StringSemanticEquals(%q, %q) = %v, want %v", test.val1, test.val2, got, want) | ||
} | ||
}) | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.