Skip to content

Commit f17e58a

Browse files
authored
Merge pull request #35408 from drewtul/f-mainframe-deployment-resource
AWS Mainframe Modernisation Service Deployment Resource
2 parents b8a194f + b4288be commit f17e58a

27 files changed

+3922
-2
lines changed

.changelog/35311.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
aws_m2_environment
3+
```

.changelog/35399.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
aws_m2_application
3+
```

.changelog/35408.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
aws_m2_deployment
3+
```

internal/framework/flex/auto_expand.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,24 @@ func (expander autoExpander) nestedObjectCollection(ctx context.Context, vFrom f
622622
diags.Append(expander.nestedObjectToSlice(ctx, vFrom, tTo, tElem, vTo)...)
623623
return diags
624624
}
625+
626+
case reflect.Interface:
627+
//
628+
// types.List(OfObject) -> []interface.
629+
//
630+
// Smithy union type handling not yet implemented. Silently skip.
631+
return diags
625632
}
633+
634+
case reflect.Interface:
635+
//
636+
// types.List(OfObject) -> interface.
637+
//
638+
// Smithy union type handling not yet implemented. Silently skip.
639+
return diags
626640
}
627641

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

internal/framework/flex/auto_flatten.go

+8
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ func (flattener autoFlattener) convert(ctx context.Context, vFrom, vTo reflect.V
8989
case reflect.Struct:
9090
diags.Append(flattener.struct_(ctx, vFrom, false, tTo, vTo)...)
9191
return diags
92+
93+
case reflect.Interface:
94+
// Smithy union type handling not yet implemented. Silently skip.
95+
return diags
9296
}
9397

9498
tflog.Info(ctx, "AutoFlex Flatten; incompatible types", map[string]interface{}{
@@ -494,6 +498,10 @@ func (flattener autoFlattener) slice(ctx context.Context, vFrom reflect.Value, t
494498
diags.Append(flattener.sliceOfStructNestedObjectCollection(ctx, vFrom, tTo, vTo)...)
495499
return diags
496500
}
501+
502+
case reflect.Interface:
503+
// Smithy union type handling not yet implemented. Silently skip.
504+
return diags
497505
}
498506

499507
tflog.Info(ctx, "AutoFlex Flatten; incompatible types", map[string]interface{}{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package types
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"strings"
10+
11+
"github.com/YakDriver/regexache"
12+
"github.com/hashicorp/terraform-plugin-framework/attr"
13+
"github.com/hashicorp/terraform-plugin-framework/attr/xattr"
14+
"github.com/hashicorp/terraform-plugin-framework/diag"
15+
"github.com/hashicorp/terraform-plugin-framework/path"
16+
"github.com/hashicorp/terraform-plugin-framework/types"
17+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
18+
"github.com/hashicorp/terraform-plugin-go/tftypes"
19+
)
20+
21+
var (
22+
_ xattr.TypeWithValidate = (*onceAWeekWindowType)(nil)
23+
_ basetypes.StringTypable = (*onceAWeekWindowType)(nil)
24+
_ basetypes.StringValuable = (*OnceAWeekWindow)(nil)
25+
_ basetypes.StringValuableWithSemanticEquals = (*OnceAWeekWindow)(nil)
26+
)
27+
28+
type onceAWeekWindowType struct {
29+
basetypes.StringType
30+
}
31+
32+
var (
33+
OnceAWeekWindowType = onceAWeekWindowType{}
34+
)
35+
36+
func (t onceAWeekWindowType) Equal(o attr.Type) bool {
37+
other, ok := o.(onceAWeekWindowType)
38+
if !ok {
39+
return false
40+
}
41+
42+
return t.StringType.Equal(other.StringType)
43+
}
44+
45+
func (onceAWeekWindowType) String() string {
46+
return "OnceAWeekWindowType"
47+
}
48+
49+
func (t onceAWeekWindowType) ValueFromString(_ context.Context, in types.String) (basetypes.StringValuable, diag.Diagnostics) {
50+
var diags diag.Diagnostics
51+
52+
if in.IsNull() {
53+
return OnceAWeekWindowNull(), diags
54+
}
55+
if in.IsUnknown() {
56+
return OnceAWeekWindowUnknown(), diags
57+
}
58+
59+
return OnceAWeekWindowValue(in.ValueString()), diags
60+
}
61+
62+
func (t onceAWeekWindowType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
63+
attrValue, err := t.StringType.ValueFromTerraform(ctx, in)
64+
if err != nil {
65+
return nil, err
66+
}
67+
68+
stringValue, ok := attrValue.(basetypes.StringValue)
69+
if !ok {
70+
return nil, fmt.Errorf("unexpected value type of %T", attrValue)
71+
}
72+
73+
stringValuable, diags := t.ValueFromString(ctx, stringValue)
74+
if diags.HasError() {
75+
return nil, fmt.Errorf("unexpected error converting StringValue to StringValuable: %v", diags)
76+
}
77+
78+
return stringValuable, nil
79+
}
80+
81+
func (onceAWeekWindowType) ValueType(context.Context) attr.Value {
82+
return OnceAWeekWindow{}
83+
}
84+
85+
func (t onceAWeekWindowType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics {
86+
var diags diag.Diagnostics
87+
88+
if !in.IsKnown() || in.IsNull() {
89+
return diags
90+
}
91+
92+
var value string
93+
err := in.As(&value)
94+
if err != nil {
95+
diags.AddAttributeError(
96+
path,
97+
"OnceAWeekWindowType Validation Error",
98+
ProviderErrorDetailPrefix+fmt.Sprintf("Cannot convert value to string: %s", err),
99+
)
100+
return diags
101+
}
102+
103+
// Valid time format is "ddd:hh24:mi".
104+
validTimeFormat := "(sun|mon|tue|wed|thu|fri|sat):([0-1][0-9]|2[0-3]):([0-5][0-9])"
105+
validTimeFormatConsolidated := "^(" + validTimeFormat + "-" + validTimeFormat + "|)$"
106+
107+
if v := strings.ToLower(value); !regexache.MustCompile(validTimeFormatConsolidated).MatchString(v) {
108+
diags.AddAttributeError(
109+
path,
110+
"OnceAWeekWindowType Validation Error",
111+
fmt.Sprintf("Value %q must satisfy the format of \"ddd:hh24:mi-ddd:hh24:mi\".", value),
112+
)
113+
return diags
114+
}
115+
116+
return diags
117+
}
118+
119+
type OnceAWeekWindow struct {
120+
basetypes.StringValue
121+
}
122+
123+
func OnceAWeekWindowNull() OnceAWeekWindow {
124+
return OnceAWeekWindow{StringValue: basetypes.NewStringNull()}
125+
}
126+
127+
func OnceAWeekWindowUnknown() OnceAWeekWindow {
128+
return OnceAWeekWindow{StringValue: basetypes.NewStringUnknown()}
129+
}
130+
131+
func OnceAWeekWindowValue(value string) OnceAWeekWindow {
132+
return OnceAWeekWindow{StringValue: basetypes.NewStringValue(value)}
133+
}
134+
135+
func (v OnceAWeekWindow) Equal(o attr.Value) bool {
136+
other, ok := o.(OnceAWeekWindow)
137+
if !ok {
138+
return false
139+
}
140+
141+
return v.StringValue.Equal(other.StringValue)
142+
}
143+
144+
func (OnceAWeekWindow) Type(context.Context) attr.Type {
145+
return OnceAWeekWindowType
146+
}
147+
148+
func (v OnceAWeekWindow) StringSemanticEquals(ctx context.Context, newValuable basetypes.StringValuable) (bool, diag.Diagnostics) {
149+
var diags diag.Diagnostics
150+
151+
newValue, ok := newValuable.(OnceAWeekWindow)
152+
if !ok {
153+
return false, diags
154+
}
155+
156+
old, d := v.ToStringValue(ctx)
157+
diags.Append(d...)
158+
if diags.HasError() {
159+
return false, diags
160+
}
161+
162+
new, d := newValue.ToStringValue(ctx)
163+
diags.Append(d...)
164+
if diags.HasError() {
165+
return false, diags
166+
}
167+
168+
// Case insensitive comparison.
169+
return strings.EqualFold(old.ValueString(), new.ValueString()), diags
170+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package types_test
5+
6+
import (
7+
"context"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-framework/path"
11+
"github.com/hashicorp/terraform-plugin-go/tftypes"
12+
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
13+
)
14+
15+
func TestOnceAWeekWindowTypeValidate(t *testing.T) {
16+
t.Parallel()
17+
18+
type testCase struct {
19+
val tftypes.Value
20+
expectError bool
21+
}
22+
tests := map[string]testCase{
23+
"not a string": {
24+
val: tftypes.NewValue(tftypes.Bool, true),
25+
expectError: true,
26+
},
27+
"unknown string": {
28+
val: tftypes.NewValue(tftypes.String, tftypes.UnknownValue),
29+
},
30+
"null string": {
31+
val: tftypes.NewValue(tftypes.String, nil),
32+
},
33+
"valid string lowercase": {
34+
val: tftypes.NewValue(tftypes.String, "thu:07:44-thu:09:44"),
35+
},
36+
"valid string uppercase": {
37+
val: tftypes.NewValue(tftypes.String, "THU:07:44-THU:09:44"),
38+
},
39+
"invalid string": {
40+
val: tftypes.NewValue(tftypes.String, "thu:25:44-zat:09:88"),
41+
expectError: true,
42+
},
43+
}
44+
45+
for name, test := range tests {
46+
name, test := name, test
47+
t.Run(name, func(t *testing.T) {
48+
t.Parallel()
49+
50+
ctx := context.Background()
51+
52+
diags := fwtypes.OnceAWeekWindowType.Validate(ctx, test.val, path.Root("test"))
53+
54+
if !diags.HasError() && test.expectError {
55+
t.Fatal("expected error, got no error")
56+
}
57+
58+
if diags.HasError() && !test.expectError {
59+
t.Fatalf("got unexpected error: %#v", diags)
60+
}
61+
})
62+
}
63+
}
64+
65+
func TestOnceAWeekWindowStringSemanticEquals(t *testing.T) {
66+
t.Parallel()
67+
68+
type testCase struct {
69+
val1, val2 fwtypes.OnceAWeekWindow
70+
equals bool
71+
}
72+
tests := map[string]testCase{
73+
"both lowercase, equal": {
74+
val1: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"),
75+
val2: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"),
76+
equals: true,
77+
},
78+
"both uppercase, equal": {
79+
val1: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"),
80+
val2: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"),
81+
equals: true,
82+
},
83+
"first uppercase, second lowercase, equal": {
84+
val1: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"),
85+
val2: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"),
86+
equals: true,
87+
},
88+
"first lowercase, second uppercase, equal": {
89+
val1: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"),
90+
val2: fwtypes.OnceAWeekWindowValue("THU:07:44-THU:09:44"),
91+
equals: true,
92+
},
93+
"not equal": {
94+
val1: fwtypes.OnceAWeekWindowValue("thu:07:44-thu:09:44"),
95+
val2: fwtypes.OnceAWeekWindowValue("thu:07:44-fri:11:09"),
96+
equals: false,
97+
},
98+
}
99+
100+
for name, test := range tests {
101+
name, test := name, test
102+
t.Run(name, func(t *testing.T) {
103+
t.Parallel()
104+
105+
ctx := context.Background()
106+
107+
equals, _ := test.val1.StringSemanticEquals(ctx, test.val2)
108+
109+
if got, want := equals, test.equals; got != want {
110+
t.Errorf("StringSemanticEquals(%q, %q) = %v, want %v", test.val1, test.val2, got, want)
111+
}
112+
})
113+
}
114+
}
File renamed without changes.

0 commit comments

Comments
 (0)