Skip to content

Commit

Permalink
use partition datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Nam authored and Sharon Nam committed Sep 21, 2023
1 parent decbb65 commit b4678b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
36 changes: 11 additions & 25 deletions internal/service/lexv2models/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,7 @@ func (r *resourceBot) Create(ctx context.Context, req resource.CreateRequest, re
return
}

dpInput, d := expandDataPrivacy(ctx, dp)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
}
dpInput := expandDataPrivacy(ctx, dp)

in := lexmodelsv2.CreateBotInput{
BotName: aws.String(plan.Name.ValueString()),
Expand Down Expand Up @@ -255,7 +251,7 @@ 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)

datap, _ := flattenDataPrivacy(ctx, out.DataPrivacy)
datap, _ := flattenDataPrivacy(out.DataPrivacy)
if resp.Diagnostics.HasError() {
return
}
Expand All @@ -280,18 +276,13 @@ func (r *resourceBot) Update(ctx context.Context, req resource.UpdateRequest, re
!plan.TestBotAliasTags.Equal(state.TestBotAliasTags) ||
!plan.DataPrivacy.Equal(state.DataPrivacy) ||
!plan.Type.Equal(state.Type) {

var dp []dataPrivacyData
resp.Diagnostics.Append(plan.DataPrivacy.ElementsAs(ctx, &dp, false)...)
if resp.Diagnostics.HasError() {
return
}

dpInput, d := expandDataPrivacy(ctx, dp)
resp.Diagnostics.Append(d...)
if resp.Diagnostics.HasError() {
return
}
dpInput := expandDataPrivacy(ctx, dp)

in := lexmodelsv2.UpdateBotInput{
BotId: flex.StringFromFramework(ctx, plan.ID),
Expand Down Expand Up @@ -481,9 +472,7 @@ func FindBotByID(ctx context.Context, conn *lexmodelsv2.Client, id string) (*lex
return out, nil
}

func flattenDataPrivacy(ctx context.Context, apiObject *awstypes.DataPrivacy) (types.List, diag.Diagnostics) {
// attributeTypes := flex.AttributeTypesMust[dataPrivacyData](ctx)

func flattenDataPrivacy(apiObject *awstypes.DataPrivacy) (types.List, diag.Diagnostics) {
var diags diag.Diagnostics
elemType := types.ObjectType{AttrTypes: dataPrivacyAttrTypes}

Expand All @@ -503,25 +492,22 @@ func flattenDataPrivacy(ctx context.Context, apiObject *awstypes.DataPrivacy) (t
return listVal, diags
}

func expandDataPrivacy(ctx context.Context, tfList []dataPrivacyData) (*awstypes.DataPrivacy, diag.Diagnostics) {
var diags diag.Diagnostics
func expandDataPrivacy(ctx context.Context, tfList []dataPrivacyData) *awstypes.DataPrivacy {
if len(tfList) == 0 {
return nil, diags
return nil
}

dp := tfList[0]
cdBool := flex.BoolFromFramework(ctx, dp.ChildDirected)

return &awstypes.DataPrivacy{
ChildDirected: aws.ToBool(cdBool),
}, diags
}
}

func expandMembers(tfList []membersData) (*awstypes.BotMember, diag.Diagnostics) {
var diags diag.Diagnostics

func expandMembers(tfList []membersData) *awstypes.BotMember {

Check failure on line 508 in internal/service/lexv2models/bot.go

View workflow job for this annotation

GitHub Actions / 2 of 2

func `expandMembers` is unused (unused)
if len(tfList) == 0 {
return nil, diags
return nil
}

mb := tfList[0]
Expand All @@ -531,7 +517,7 @@ func expandMembers(tfList []membersData) (*awstypes.BotMember, diag.Diagnostics)
BotMemberId: aws.String(mb.ID.ValueString()),
BotMemberName: aws.String(mb.Name.ValueString()),
BotMemberVersion: aws.String(mb.Version.ValueString()),
}, diags
}
}

func (rd *resourceBotData) refreshFromOutput(ctx context.Context, out *lexmodelsv2.DescribeBotOutput) diag.Diagnostics {
Expand All @@ -548,7 +534,7 @@ func (rd *resourceBotData) refreshFromOutput(ctx context.Context, out *lexmodels
rd.IdleSessionTTLInSeconds = flex.Int32ToFramework(ctx, out.IdleSessionTTLInSeconds)

// TIP: Setting a complex type.
datap, d := flattenDataPrivacy(ctx, out.DataPrivacy)
datap, d := flattenDataPrivacy(out.DataPrivacy)
diags.Append(d...)
rd.DataPrivacy = datap

Expand Down
4 changes: 3 additions & 1 deletion internal/service/lexv2models/bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func testAccPreCheck(ctx context.Context, t *testing.T) {

func testAccBotBaseConfig(rName string) string {
return fmt.Sprintf(`
data "aws_partition" "current" {}
resource "aws_iam_role" "test_role" {
name = %[1]q
assume_role_policy = jsonencode({
Expand All @@ -228,7 +230,7 @@ resource "aws_iam_role" "test_role" {
resource "aws_iam_role_policy_attachment" "test-attach" {
role = aws_iam_role.test_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonLexFullAccess"
policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonLexFullAccess"
}
`, rName)
}
Expand Down

0 comments on commit b4678b9

Please sign in to comment.