Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexv2models/intent: New resource #34891

Merged
merged 37 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a90e212
lexv2models: New resource intent
YakDriver Oct 24, 2023
f4b84e0
tidy after clean
YakDriver Oct 26, 2023
1de62a0
lex: Additional testing
YakDriver Oct 26, 2023
481483e
lex: Additional work on intent
YakDriver Dec 4, 2023
9f892e9
lex/intent: Work in autoflex expand
YakDriver Dec 7, 2023
18f9e03
lex: Add intent work
YakDriver Dec 8, 2023
57c5e96
lex/intent: Add tests
YakDriver Dec 12, 2023
f944306
lexv2models: More Intent
YakDriver Dec 12, 2023
d500e78
lex/intent: More working bits
YakDriver Dec 13, 2023
d01355f
lex/intent: Imports
YakDriver Dec 13, 2023
bb64526
lex/intent: Work on prompt spec
YakDriver Dec 13, 2023
ca30061
lex/intent: Additional bits
YakDriver Dec 15, 2023
105c7b1
lex/intent: More bits
YakDriver Dec 20, 2023
c8cb20a
lex/intent/tests: Get unit tests working
YakDriver Dec 20, 2023
f8609a3
lex/intent: Additional bits
YakDriver Jan 8, 2024
107e6c8
add validators
Dec 21, 2023
45ec402
lex/intent: Fix additional bits
YakDriver Jan 9, 2024
99a8425
lex/intent: Add docs
YakDriver Jan 10, 2024
d436c12
lex/intent: Fix confirmation setting
YakDriver Jan 11, 2024
98bddea
lex/intent: Fix slot priority
YakDriver Jan 11, 2024
a116000
lex/intent: Fix additional bits
YakDriver Jan 12, 2024
0a44623
lex/intent: Work on confirmation_setting
YakDriver Jan 12, 2024
4808eb3
lex/intent: Add documentation about default config
YakDriver Jan 12, 2024
feb83db
flex: Fix MapOf
YakDriver Jan 16, 2024
3bc1f73
lex/intent: Update docs
YakDriver Jan 17, 2024
946bdef
lex/intent: Fix schema
YakDriver Jan 17, 2024
883537d
lex/intent: Add tests
YakDriver Jan 17, 2024
8862766
lex/intent: Fix lint docs
YakDriver Jan 17, 2024
ccc8d19
lex/intent: Fix lint docs
YakDriver Jan 17, 2024
bfeca73
lex/intent: Fix tests
YakDriver Jan 17, 2024
2eeb107
lex/intent: Fix tests
YakDriver Jan 17, 2024
96a09cc
lex/intent: Add to and fix docs
YakDriver Jan 17, 2024
9cdb715
lex/intent: Use regexache
YakDriver Jan 17, 2024
567a3e4
lex/intent: Use schema building block
YakDriver Jan 17, 2024
e6edbe6
lex/intent: Remove punch list
YakDriver Jan 17, 2024
c608771
makefile: Clean up go versions
YakDriver Jan 17, 2024
226b8df
Add changelog
YakDriver Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/34891.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_lexv2models_intent
```
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ cleango: ## Clean up Go cache
echo "Killing gopls process $$proc" ; \
kill -9 $$proc ; \
done ; \
go clean -modcache -testcache -cache ; \
$(GO_VER) clean -modcache -testcache -cache ; \

clean: cleango build tools ## Clean up Go cache and re-install tools
$(GO_VER) mod tidy

copyright: ## Run copywrite (generate source code headers)
@copywrite headers
Expand Down
6 changes: 3 additions & 3 deletions internal/framework/flex/auto_expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func TestExpandGeneric(t *testing.T) {
{
TestName: "map string",
Source: &TestFlexTF11{
FieldInner: fwtypes.NewMapValueOf(ctx, map[string]basetypes.StringValue{
FieldInner: fwtypes.NewMapValueOfMust[types.String](ctx, map[string]attr.Value{
"x": types.StringValue("y"),
}),
},
Expand Down Expand Up @@ -537,7 +537,7 @@ func TestExpandGeneric(t *testing.T) {
TestName: "nested string map",
Source: &TestFlexTF14{
FieldOuter: fwtypes.NewListNestedObjectValueOfPtr(ctx, &TestFlexTF11{
FieldInner: fwtypes.NewMapValueOf(ctx, map[string]basetypes.StringValue{
FieldInner: fwtypes.NewMapValueOfMust[basetypes.StringValue](ctx, map[string]attr.Value{
"x": types.StringValue("y"),
}),
}),
Expand Down Expand Up @@ -744,7 +744,7 @@ func TestExpandGeneric(t *testing.T) {
},
}),
}),
SessionAttributes: fwtypes.NewMapValueOf(ctx, map[string]basetypes.StringValue{
SessionAttributes: fwtypes.NewMapValueOfMust[basetypes.StringValue](ctx, map[string]attr.Value{
"x": basetypes.NewStringValue("y"),
}),
},
Expand Down
10 changes: 5 additions & 5 deletions internal/framework/flex/auto_flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ func TestFlatten(t *testing.T) {
types.StringValue("a"),
types.StringValue("b"),
}),
Field5: fwtypes.NewMapValueOf[types.String](ctx, map[string]basetypes.StringValue{
Field5: fwtypes.NewMapValueOfMust[types.String](ctx, map[string]attr.Value{
"A": types.StringValue("a"),
"B": types.StringValue("b"),
}),
Field6: fwtypes.NewMapValueOf[types.String](ctx, map[string]basetypes.StringValue{
Field6: fwtypes.NewMapValueOfMust[types.String](ctx, map[string]attr.Value{
"A": types.StringValue("a"),
"B": types.StringValue("b"),
}),
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestFlattenGeneric(t *testing.T) {
},
Target: &TestFlexTF11{},
WantTarget: &TestFlexTF11{
FieldInner: fwtypes.NewMapValueOf(ctx, map[string]basetypes.StringValue{
FieldInner: fwtypes.NewMapValueOfMust[basetypes.StringValue](ctx, map[string]attr.Value{
"x": types.StringValue("y"),
}),
},
Expand Down Expand Up @@ -719,7 +719,7 @@ func TestFlattenGeneric(t *testing.T) {
Target: &TestFlexTF14{},
WantTarget: &TestFlexTF14{
FieldOuter: fwtypes.NewListNestedObjectValueOfPtr(ctx, &TestFlexTF11{
FieldInner: fwtypes.NewMapValueOf(ctx, map[string]basetypes.StringValue{
FieldInner: fwtypes.NewMapValueOfMust[basetypes.StringValue](ctx, map[string]attr.Value{
"x": types.StringValue("y"),
}),
}),
Expand Down Expand Up @@ -895,7 +895,7 @@ func TestFlattenGeneric(t *testing.T) {
},
}),
}),
SessionAttributes: fwtypes.NewMapValueOf(ctx, map[string]basetypes.StringValue{
SessionAttributes: fwtypes.NewMapValueOfMust[basetypes.StringValue](ctx, map[string]attr.Value{
"x": basetypes.NewStringValue("y"),
}),
},
Expand Down
64 changes: 31 additions & 33 deletions internal/framework/types/mapof.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ package types
import (
"context"
"fmt"
"reflect"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
)

var _ basetypes.MapTypable = MapTypeOf[struct{}]{}
var (
_ basetypes.MapTypable = MapTypeOf[basetypes.StringValue]{}
_ basetypes.MapValuable = MapValueOf[basetypes.StringValue]{}
)

// MapTypeOf is the attribute type of a MapValueOf.
type MapTypeOf[T any] struct {
type MapTypeOf[T attr.Value] struct {
basetypes.MapType
}

func NewMapTypeOf[T any](ctx context.Context) MapTypeOf[T] {
return MapTypeOf[T]{basetypes.MapType{ElemType: ElementTypeMust[T](ctx)}}
func NewMapTypeOf[T attr.Value](ctx context.Context) MapTypeOf[T] {
var zero T
return MapTypeOf[T]{basetypes.MapType{ElemType: zero.Type(ctx)}}
}

func (t MapTypeOf[T]) Equal(o attr.Type) bool {
Expand All @@ -38,11 +41,13 @@ func (t MapTypeOf[T]) Equal(o attr.Type) bool {
}

func (t MapTypeOf[T]) String() string {
return "types.MapTypeOf[" + t.ElementType().String() + "]"
var zero T
return fmt.Sprintf("%T", zero)
}

func (t MapTypeOf[T]) ValueFromMap(ctx context.Context, in basetypes.MapValue) (basetypes.MapValuable, diag.Diagnostics) {
var diags diag.Diagnostics
var zero T

if in.IsNull() {
return NewMapValueOfNull[T](ctx), diags
Expand All @@ -55,10 +60,10 @@ func (t MapTypeOf[T]) ValueFromMap(ctx context.Context, in basetypes.MapValue) (
// internal organs of framework and autoflex only to discover the
// first argument in this call should be an element type not the map
// type.
mapValue, d := basetypes.NewMapValue(t.ElementType(), in.Elements())
mapValue, d := basetypes.NewMapValue(zero.Type(ctx), in.Elements())
diags.Append(d...)
if diags.HasError() {
return NewMapValueOfUnknown[T](ctx), diags
return basetypes.NewMapUnknown(types.StringType), diags
}

value := MapValueOf[T]{
Expand Down Expand Up @@ -92,10 +97,8 @@ func (t MapTypeOf[T]) ValueType(ctx context.Context) attr.Value {
return MapValueOf[T]{}
}

var _ basetypes.MapValuable = MapValueOf[struct{}]{}

// MapValueOf represents a Terraform Plugin Framework Map value whose elements are of type MapTypeOf.
type MapValueOf[T any] struct {
type MapValueOf[T attr.Value] struct {
basetypes.MapValue
}

Expand All @@ -113,32 +116,27 @@ func (v MapValueOf[T]) Type(ctx context.Context) attr.Type {
return NewMapTypeOf[T](ctx)
}

func NewMapValueOfNull[T any](ctx context.Context) MapValueOf[T] {
return MapValueOf[T]{MapValue: basetypes.NewMapNull(NewMapTypeOf[T](ctx))}
}
func NewMapValueOf[T attr.Value](ctx context.Context, elements map[string]attr.Value) (MapValueOf[T], diag.Diagnostics) {
var zero T

func NewMapValueOfUnknown[T any](ctx context.Context) MapValueOf[T] {
return MapValueOf[T]{MapValue: basetypes.NewMapUnknown(NewMapTypeOf[T](ctx))}
}
mapValue, diags := basetypes.NewMapValue(zero.Type(ctx), elements)
if diags.HasError() {
return NewMapValueOfUnknown[T](ctx), diags
}

func NewMapValueOf[T any](ctx context.Context, elements map[string]T) MapValueOf[T] {
return MapValueOf[T]{MapValue: fwdiag.Must(basetypes.NewMapValueFrom(ctx, ElementTypeMust[T](ctx), elements))}
return MapValueOf[T]{MapValue: mapValue}, diags
}

func ElementType[T any](ctx context.Context) (attr.Type, error) {
var t T
val := reflect.ValueOf(t)
typ := val.Type()

v, ok := val.Interface().(attr.Value)

if !ok {
return nil, fmt.Errorf("%T has unsupported type: %s", t, typ)
}
func NewMapValueOfNull[T attr.Value](ctx context.Context) MapValueOf[T] {
var zero T
return MapValueOf[T]{MapValue: basetypes.NewMapNull(zero.Type(ctx))}
}

return v.Type(ctx), nil
func NewMapValueOfUnknown[T attr.Value](ctx context.Context) MapValueOf[T] {
var zero T
return MapValueOf[T]{MapValue: basetypes.NewMapUnknown(zero.Type(ctx))}
}

func ElementTypeMust[T any](ctx context.Context) attr.Type {
return errs.Must(ElementType[T](ctx))
func NewMapValueOfMust[T attr.Value](ctx context.Context, elements map[string]attr.Value) MapValueOf[T] {
return fwdiag.Must(NewMapValueOf[T](ctx, elements))
}
1 change: 1 addition & 0 deletions internal/service/lexv2models/bot_locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ func waitBotLocaleCreated(ctx context.Context, conn *lexmodelsv2.Client, id stri
Target: enum.Slice(awstypes.BotLocaleStatusBuilt, awstypes.BotLocaleStatusNotBuilt),
Refresh: statusBotLocale(ctx, conn, id),
Timeout: timeout,
MinTimeout: 5 * time.Second,
NotFoundChecks: 20,
ContinuousTargetOccurence: 2,
}
Expand Down
1 change: 1 addition & 0 deletions internal/service/lexv2models/exports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ var (
ResourceBot = newResourceBot
ResourceBotLocale = newResourceBotLocale
ResourceBotVersion = newResourceBotVersion
ResourceIntent = newResourceIntent
)
Loading
Loading