Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e706c1

Browse files
authored
Merge pull request #34521 from markoskandylis/f-securitylake-data-lake
F securitylake data lake
2 parents 017bbcd + 69a092d commit 7e706c1

15 files changed

Lines changed: 1797 additions & 3 deletions

File tree

.changelog/34521.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
resource/aws_securitylake_data_lake
3+
```

internal/create/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ func ProblemStandardMessage(service, action, resource, id string, gotError error
4141
}
4242

4343
if gotError == nil {
44+
if id == "" {
45+
return fmt.Sprintf("%s %s %s", action, hf, resource)
46+
}
4447
return fmt.Sprintf("%s %s %s (%s)", action, hf, resource, id)
4548
}
4649

50+
if id == "" {
51+
return fmt.Sprintf("%s %s %s: %s", action, hf, resource, gotError)
52+
}
4753
return fmt.Sprintf("%s %s %s (%s): %s", action, hf, resource, id, gotError)
4854
}
4955

internal/framework/types/list_nested_objectof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func nestedObjectTypeNewObjectSlice[T any](_ context.Context, len, cap int) ([]*
142142
return make([]*T, len, cap), diags
143143
}
144144

145-
// ListNestedObjectValueOf represents a Terraform Plugin Framework List value whose elements are of type ObjectTypeOf.
145+
// ListNestedObjectValueOf represents a Terraform Plugin Framework List value whose elements are of type `ObjectTypeOf[T]`.
146146
type ListNestedObjectValueOf[T any] struct {
147147
basetypes.ListValue
148148
}

internal/framework/types/set_nested_objectof.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (t setNestedObjectTypeOf[T]) ValueFromObjectSlice(ctx context.Context, slic
130130
return nil, diags
131131
}
132132

133-
// SetNestedObjectValueOf represents a Terraform Plugin Framework Set value whose elements are of type ObjectTypeOf.
133+
// SetNestedObjectValueOf represents a Terraform Plugin Framework Set value whose elements are of type `ObjectTypeOf[T]`.
134134
type SetNestedObjectValueOf[T any] struct {
135135
basetypes.SetValue
136136
}

internal/framework/types/setof.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package types
5+
6+
import (
7+
"context"
8+
"fmt"
9+
10+
"github.com/hashicorp/terraform-plugin-framework/attr"
11+
"github.com/hashicorp/terraform-plugin-framework/diag"
12+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
13+
"github.com/hashicorp/terraform-plugin-go/tftypes"
14+
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
15+
)
16+
17+
// setTypeOf is the attribute type of a SetValueOf.
18+
type setTypeOf[T attr.Value] struct {
19+
basetypes.SetType
20+
}
21+
22+
var (
23+
SetOfStringType = setTypeOf[basetypes.StringValue]{basetypes.SetType{ElemType: basetypes.StringType{}}}
24+
)
25+
26+
var (
27+
_ basetypes.SetTypable = (*setTypeOf[basetypes.StringValue])(nil)
28+
_ basetypes.SetValuable = (*SetValueOf[basetypes.StringValue])(nil)
29+
)
30+
31+
func newAttrTypeOf[T attr.Value](ctx context.Context) attr.Type {
32+
var zero T
33+
return zero.Type(ctx)
34+
}
35+
36+
func NewSetTypeOf[T attr.Value](ctx context.Context) setTypeOf[T] {
37+
return setTypeOf[T]{basetypes.SetType{ElemType: newAttrTypeOf[T](ctx)}}
38+
}
39+
40+
func (t setTypeOf[T]) Equal(o attr.Type) bool {
41+
other, ok := o.(setTypeOf[T])
42+
43+
if !ok {
44+
return false
45+
}
46+
47+
return t.SetType.Equal(other.SetType)
48+
}
49+
50+
func (t setTypeOf[T]) String() string {
51+
var zero T
52+
return fmt.Sprintf("SetTypeOf[%T]", zero)
53+
}
54+
55+
func (t setTypeOf[T]) ValueFromSet(ctx context.Context, in basetypes.SetValue) (basetypes.SetValuable, diag.Diagnostics) {
56+
var diags diag.Diagnostics
57+
58+
if in.IsNull() {
59+
return NewSetValueOfNull[T](ctx), diags
60+
}
61+
if in.IsUnknown() {
62+
return NewSetValueOfUnknown[T](ctx), diags
63+
}
64+
65+
setValue, d := basetypes.NewSetValue(newAttrTypeOf[T](ctx), in.Elements())
66+
diags.Append(d...)
67+
if diags.HasError() {
68+
return NewSetValueOfUnknown[T](ctx), diags
69+
}
70+
71+
value := SetValueOf[T]{
72+
SetValue: setValue,
73+
}
74+
75+
return value, diags
76+
}
77+
78+
func (t setTypeOf[T]) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
79+
attrValue, err := t.SetType.ValueFromTerraform(ctx, in)
80+
81+
if err != nil {
82+
return nil, err
83+
}
84+
85+
setValue, ok := attrValue.(basetypes.SetValue)
86+
87+
if !ok {
88+
return nil, fmt.Errorf("unexpected value type of %T", attrValue)
89+
}
90+
91+
setValuable, diags := t.ValueFromSet(ctx, setValue)
92+
93+
if diags.HasError() {
94+
return nil, fmt.Errorf("unexpected error converting SetValue to SetValuable: %v", diags)
95+
}
96+
97+
return setValuable, nil
98+
}
99+
100+
func (t setTypeOf[T]) ValueType(ctx context.Context) attr.Value {
101+
return SetValueOf[T]{}
102+
}
103+
104+
// SetValueOf represents a Terraform Plugin Framework Set value whose elements are of type `T`.
105+
type SetValueOf[T attr.Value] struct {
106+
basetypes.SetValue
107+
}
108+
109+
func (v SetValueOf[T]) Equal(o attr.Value) bool {
110+
other, ok := o.(SetValueOf[T])
111+
112+
if !ok {
113+
return false
114+
}
115+
116+
return v.SetValue.Equal(other.SetValue)
117+
}
118+
119+
func (v SetValueOf[T]) Type(ctx context.Context) attr.Type {
120+
return NewSetTypeOf[T](ctx)
121+
}
122+
123+
func NewSetValueOfNull[T attr.Value](ctx context.Context) SetValueOf[T] {
124+
return SetValueOf[T]{SetValue: basetypes.NewSetNull(newAttrTypeOf[T](ctx))}
125+
}
126+
127+
func NewSetValueOfUnknown[T attr.Value](ctx context.Context) SetValueOf[T] {
128+
return SetValueOf[T]{SetValue: basetypes.NewSetUnknown(newAttrTypeOf[T](ctx))}
129+
}
130+
131+
func NewSetValueOf[T attr.Value](ctx context.Context, elements []attr.Value) (SetValueOf[T], diag.Diagnostics) {
132+
v, diags := basetypes.NewSetValue(newAttrTypeOf[T](ctx), elements)
133+
if diags.HasError() {
134+
return NewSetValueOfUnknown[T](ctx), diags
135+
}
136+
137+
return SetValueOf[T]{SetValue: v}, diags
138+
}
139+
140+
func NewSetValueOfMust[T attr.Value](ctx context.Context, elements []attr.Value) SetValueOf[T] {
141+
return fwdiag.Must(NewSetValueOf[T](ctx, elements))
142+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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/google/go-cmp/cmp"
11+
"github.com/hashicorp/terraform-plugin-framework/attr"
12+
"github.com/hashicorp/terraform-plugin-framework/types"
13+
"github.com/hashicorp/terraform-plugin-go/tftypes"
14+
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
15+
)
16+
17+
func TestSetOfStringFromTerraform(t *testing.T) {
18+
t.Parallel()
19+
20+
ctx := context.Background()
21+
tests := map[string]struct {
22+
val tftypes.Value
23+
expected attr.Value
24+
}{
25+
"values": {
26+
val: tftypes.NewValue(tftypes.Set{
27+
ElementType: tftypes.String,
28+
}, []tftypes.Value{
29+
tftypes.NewValue(tftypes.String, "red"),
30+
tftypes.NewValue(tftypes.String, "blue"),
31+
tftypes.NewValue(tftypes.String, "green"),
32+
}),
33+
expected: fwtypes.NewSetValueOfMust[types.String](ctx, []attr.Value{
34+
types.StringValue("red"),
35+
types.StringValue("blue"),
36+
types.StringValue("green"),
37+
}),
38+
},
39+
}
40+
41+
for name, test := range tests {
42+
name, test := name, test
43+
t.Run(name, func(t *testing.T) {
44+
t.Parallel()
45+
46+
val, err := fwtypes.SetOfStringType.ValueFromTerraform(ctx, test.val)
47+
48+
if err != nil {
49+
t.Fatalf("got unexpected error: %s", err)
50+
}
51+
52+
if diff := cmp.Diff(val, test.expected); diff != "" {
53+
t.Errorf("unexpected diff (+wanted, -got): %s", diff)
54+
}
55+
})
56+
}
57+
}

0 commit comments

Comments
 (0)