Skip to content

Commit

Permalink
Merge pull request #35408 from drewtul/f-mainframe-deployment-resource
Browse files Browse the repository at this point in the history
AWS Mainframe Modernisation Service Deployment Resource
  • Loading branch information
ewbankkit authored Mar 25, 2024
2 parents b8a194f + b4288be commit f17e58a
Show file tree
Hide file tree
Showing 27 changed files with 3,922 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/35311.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_m2_environment
```
3 changes: 3 additions & 0 deletions .changelog/35399.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_m2_application
```
3 changes: 3 additions & 0 deletions .changelog/35408.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_m2_deployment
```
16 changes: 15 additions & 1 deletion internal/framework/flex/auto_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,24 @@ func (expander autoExpander) nestedObjectCollection(ctx context.Context, vFrom f
diags.Append(expander.nestedObjectToSlice(ctx, vFrom, tTo, tElem, vTo)...)
return diags
}

case reflect.Interface:
//
// types.List(OfObject) -> []interface.
//
// Smithy union type handling not yet implemented. Silently skip.
return diags
}

case reflect.Interface:
//
// types.List(OfObject) -> interface.
//
// Smithy union type handling not yet implemented. Silently skip.
return diags
}

diags.AddError("Incompatible types", fmt.Sprintf("nestedObject[%s] cannot be expanded to %s", vFrom.Type(ctx).(attr.TypeWithElementType).ElementType(), vTo.Kind()))
diags.AddError("Incompatible types", fmt.Sprintf("nestedObjectCollection[%s] cannot be expanded to %s", vFrom.Type(ctx).(attr.TypeWithElementType).ElementType(), vTo.Kind()))
return diags
}

Expand Down
8 changes: 8 additions & 0 deletions internal/framework/flex/auto_flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (flattener autoFlattener) convert(ctx context.Context, vFrom, vTo reflect.V
case reflect.Struct:
diags.Append(flattener.struct_(ctx, vFrom, false, tTo, vTo)...)
return diags

case reflect.Interface:
// Smithy union type handling not yet implemented. Silently skip.
return diags
}

tflog.Info(ctx, "AutoFlex Flatten; incompatible types", map[string]interface{}{
Expand Down Expand Up @@ -494,6 +498,10 @@ func (flattener autoFlattener) slice(ctx context.Context, vFrom reflect.Value, t
diags.Append(flattener.sliceOfStructNestedObjectCollection(ctx, vFrom, tTo, vTo)...)
return diags
}

case reflect.Interface:
// Smithy union type handling not yet implemented. Silently skip.
return diags
}

tflog.Info(ctx, "AutoFlex Flatten; incompatible types", map[string]interface{}{
Expand Down
170 changes: 170 additions & 0 deletions internal/framework/types/once_a_week_window.go
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
}
114 changes: 114 additions & 0 deletions internal/framework/types/once_a_week_window_test.go
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.
Loading

0 comments on commit f17e58a

Please sign in to comment.