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

New resource bot version and add flattener for bot #33858

Merged
merged 16 commits into from
Nov 17, 2023
3 changes: 3 additions & 0 deletions .changelog/33858.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_lexv2models_bot_version
```
44 changes: 44 additions & 0 deletions internal/service/lexv2models/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ func (r *resourceBot) Read(ctx context.Context, req resource.ReadRequest, resp *
state.Description = flex.StringToFramework(ctx, out.Description)
state.IdleSessionTTLInSeconds = flex.Int32ToFramework(ctx, out.IdleSessionTTLInSeconds)

members, errDiags := flattenMembers(ctx, out.BotMembers)
resp.Diagnostics.Append(errDiags...)
if resp.Diagnostics.HasError() {
return
}
state.Members = members

datap, _ := flattenDataPrivacy(out.DataPrivacy)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -497,6 +504,35 @@ func flattenDataPrivacy(apiObject *awstypes.DataPrivacy) (types.List, diag.Diagn
return listVal, diags
}

func flattenMembers(ctx context.Context, apiObject []awstypes.BotMember) (types.List, diag.Diagnostics) {
var diags diag.Diagnostics
elemType := types.ObjectType{AttrTypes: botMembersAttrTypes}

if apiObject == nil {
return types.ListNull(elemType), diags
}

elems := []attr.Value{}
for _, source := range apiObject {
obj := map[string]attr.Value{
"alias_name": flex.StringToFramework(ctx, source.BotMemberAliasName),
"alias_id": flex.StringToFramework(ctx, source.BotMemberAliasId),
"id": flex.StringToFramework(ctx, source.BotMemberId),
"name": flex.StringToFramework(ctx, source.BotMemberName),
"version": flex.StringToFramework(ctx, source.BotMemberVersion),
}
objVal, d := types.ObjectValue(botMembersAttrTypes, obj)
diags.Append(d...)

elems = append(elems, objVal)
}

listVal, d := types.ListValue(elemType, elems)
diags.Append(d...)

return listVal, diags
}

func expandDataPrivacy(ctx context.Context, tfList []dataPrivacyData) *awstypes.DataPrivacy {
if len(tfList) == 0 {
return nil
Expand Down Expand Up @@ -581,3 +617,11 @@ type membersData struct {
var dataPrivacyAttrTypes = map[string]attr.Type{
"child_directed": types.BoolType,
}

var botMembersAttrTypes = map[string]attr.Type{
"alias_id": types.StringType,
"alias_name": types.StringType,
"id": types.StringType,
"name": types.StringType,
"version": types.StringType,
}
Loading
Loading