-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 #34521 from markoskandylis/f-securitylake-data-lake
F securitylake data lake
- Loading branch information
Showing
15 changed files
with
1,797 additions
and
3 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 | ||
resource/aws_securitylake_data_lake | ||
``` |
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
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,142 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package types | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag" | ||
) | ||
|
||
// setTypeOf is the attribute type of a SetValueOf. | ||
type setTypeOf[T attr.Value] struct { | ||
basetypes.SetType | ||
} | ||
|
||
var ( | ||
SetOfStringType = setTypeOf[basetypes.StringValue]{basetypes.SetType{ElemType: basetypes.StringType{}}} | ||
) | ||
|
||
var ( | ||
_ basetypes.SetTypable = (*setTypeOf[basetypes.StringValue])(nil) | ||
_ basetypes.SetValuable = (*SetValueOf[basetypes.StringValue])(nil) | ||
) | ||
|
||
func newAttrTypeOf[T attr.Value](ctx context.Context) attr.Type { | ||
var zero T | ||
return zero.Type(ctx) | ||
} | ||
|
||
func NewSetTypeOf[T attr.Value](ctx context.Context) setTypeOf[T] { | ||
return setTypeOf[T]{basetypes.SetType{ElemType: newAttrTypeOf[T](ctx)}} | ||
} | ||
|
||
func (t setTypeOf[T]) Equal(o attr.Type) bool { | ||
other, ok := o.(setTypeOf[T]) | ||
|
||
if !ok { | ||
return false | ||
} | ||
|
||
return t.SetType.Equal(other.SetType) | ||
} | ||
|
||
func (t setTypeOf[T]) String() string { | ||
var zero T | ||
return fmt.Sprintf("SetTypeOf[%T]", zero) | ||
} | ||
|
||
func (t setTypeOf[T]) ValueFromSet(ctx context.Context, in basetypes.SetValue) (basetypes.SetValuable, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
|
||
if in.IsNull() { | ||
return NewSetValueOfNull[T](ctx), diags | ||
} | ||
if in.IsUnknown() { | ||
return NewSetValueOfUnknown[T](ctx), diags | ||
} | ||
|
||
setValue, d := basetypes.NewSetValue(newAttrTypeOf[T](ctx), in.Elements()) | ||
diags.Append(d...) | ||
if diags.HasError() { | ||
return NewSetValueOfUnknown[T](ctx), diags | ||
} | ||
|
||
value := SetValueOf[T]{ | ||
SetValue: setValue, | ||
} | ||
|
||
return value, diags | ||
} | ||
|
||
func (t setTypeOf[T]) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { | ||
attrValue, err := t.SetType.ValueFromTerraform(ctx, in) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
setValue, ok := attrValue.(basetypes.SetValue) | ||
|
||
if !ok { | ||
return nil, fmt.Errorf("unexpected value type of %T", attrValue) | ||
} | ||
|
||
setValuable, diags := t.ValueFromSet(ctx, setValue) | ||
|
||
if diags.HasError() { | ||
return nil, fmt.Errorf("unexpected error converting SetValue to SetValuable: %v", diags) | ||
} | ||
|
||
return setValuable, nil | ||
} | ||
|
||
func (t setTypeOf[T]) ValueType(ctx context.Context) attr.Value { | ||
return SetValueOf[T]{} | ||
} | ||
|
||
// SetValueOf represents a Terraform Plugin Framework Set value whose elements are of type `T`. | ||
type SetValueOf[T attr.Value] struct { | ||
basetypes.SetValue | ||
} | ||
|
||
func (v SetValueOf[T]) Equal(o attr.Value) bool { | ||
other, ok := o.(SetValueOf[T]) | ||
|
||
if !ok { | ||
return false | ||
} | ||
|
||
return v.SetValue.Equal(other.SetValue) | ||
} | ||
|
||
func (v SetValueOf[T]) Type(ctx context.Context) attr.Type { | ||
return NewSetTypeOf[T](ctx) | ||
} | ||
|
||
func NewSetValueOfNull[T attr.Value](ctx context.Context) SetValueOf[T] { | ||
return SetValueOf[T]{SetValue: basetypes.NewSetNull(newAttrTypeOf[T](ctx))} | ||
} | ||
|
||
func NewSetValueOfUnknown[T attr.Value](ctx context.Context) SetValueOf[T] { | ||
return SetValueOf[T]{SetValue: basetypes.NewSetUnknown(newAttrTypeOf[T](ctx))} | ||
} | ||
|
||
func NewSetValueOf[T attr.Value](ctx context.Context, elements []attr.Value) (SetValueOf[T], diag.Diagnostics) { | ||
v, diags := basetypes.NewSetValue(newAttrTypeOf[T](ctx), elements) | ||
if diags.HasError() { | ||
return NewSetValueOfUnknown[T](ctx), diags | ||
} | ||
|
||
return SetValueOf[T]{SetValue: v}, diags | ||
} | ||
|
||
func NewSetValueOfMust[T attr.Value](ctx context.Context, elements []attr.Value) SetValueOf[T] { | ||
return fwdiag.Must(NewSetValueOf[T](ctx, elements)) | ||
} |
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,57 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package types_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/terraform-plugin-framework/attr" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" | ||
) | ||
|
||
func TestSetOfStringFromTerraform(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
tests := map[string]struct { | ||
val tftypes.Value | ||
expected attr.Value | ||
}{ | ||
"values": { | ||
val: tftypes.NewValue(tftypes.Set{ | ||
ElementType: tftypes.String, | ||
}, []tftypes.Value{ | ||
tftypes.NewValue(tftypes.String, "red"), | ||
tftypes.NewValue(tftypes.String, "blue"), | ||
tftypes.NewValue(tftypes.String, "green"), | ||
}), | ||
expected: fwtypes.NewSetValueOfMust[types.String](ctx, []attr.Value{ | ||
types.StringValue("red"), | ||
types.StringValue("blue"), | ||
types.StringValue("green"), | ||
}), | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
name, test := name, test | ||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
val, err := fwtypes.SetOfStringType.ValueFromTerraform(ctx, test.val) | ||
|
||
if err != nil { | ||
t.Fatalf("got unexpected error: %s", err) | ||
} | ||
|
||
if diff := cmp.Diff(val, test.expected); diff != "" { | ||
t.Errorf("unexpected diff (+wanted, -got): %s", diff) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.