Skip to content

Commit 02472af

Browse files
Sharon NamSharon Nam
Sharon Nam
authored and
Sharon Nam
committed
use partition datasource
1 parent decbb65 commit 02472af

File tree

3 files changed

+43
-50
lines changed

3 files changed

+43
-50
lines changed

internal/service/lexv2models/bot.go

+29-33
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,7 @@ func (r *resourceBot) Create(ctx context.Context, req resource.CreateRequest, re
156156
return
157157
}
158158

159-
dpInput, d := expandDataPrivacy(ctx, dp)
160-
resp.Diagnostics.Append(d...)
161-
if resp.Diagnostics.HasError() {
162-
return
163-
}
159+
dpInput := expandDataPrivacy(ctx, dp)
164160

165161
in := lexmodelsv2.CreateBotInput{
166162
BotName: aws.String(plan.Name.ValueString()),
@@ -178,6 +174,12 @@ func (r *resourceBot) Create(ctx context.Context, req resource.CreateRequest, re
178174
in.Description = aws.String(plan.Description.ValueString())
179175
}
180176

177+
var bm []membersData
178+
if !plan.Members.IsNull() {
179+
bmInput := expandMembers(ctx, bm)
180+
in.BotMembers = bmInput
181+
}
182+
181183
out, err := conn.CreateBot(ctx, &in)
182184
if err != nil {
183185
resp.Diagnostics.AddError(
@@ -255,7 +257,7 @@ func (r *resourceBot) Read(ctx context.Context, req resource.ReadRequest, resp *
255257
state.Description = flex.StringToFramework(ctx, out.Description)
256258
state.IdleSessionTTLInSeconds = flex.Int32ToFramework(ctx, out.IdleSessionTTLInSeconds)
257259

258-
datap, _ := flattenDataPrivacy(ctx, out.DataPrivacy)
260+
datap, _ := flattenDataPrivacy(out.DataPrivacy)
259261
if resp.Diagnostics.HasError() {
260262
return
261263
}
@@ -280,18 +282,13 @@ func (r *resourceBot) Update(ctx context.Context, req resource.UpdateRequest, re
280282
!plan.TestBotAliasTags.Equal(state.TestBotAliasTags) ||
281283
!plan.DataPrivacy.Equal(state.DataPrivacy) ||
282284
!plan.Type.Equal(state.Type) {
283-
284285
var dp []dataPrivacyData
285286
resp.Diagnostics.Append(plan.DataPrivacy.ElementsAs(ctx, &dp, false)...)
286287
if resp.Diagnostics.HasError() {
287288
return
288289
}
289290

290-
dpInput, d := expandDataPrivacy(ctx, dp)
291-
resp.Diagnostics.Append(d...)
292-
if resp.Diagnostics.HasError() {
293-
return
294-
}
291+
dpInput := expandDataPrivacy(ctx, dp)
295292

296293
in := lexmodelsv2.UpdateBotInput{
297294
BotId: flex.StringFromFramework(ctx, plan.ID),
@@ -481,9 +478,7 @@ func FindBotByID(ctx context.Context, conn *lexmodelsv2.Client, id string) (*lex
481478
return out, nil
482479
}
483480

484-
func flattenDataPrivacy(ctx context.Context, apiObject *awstypes.DataPrivacy) (types.List, diag.Diagnostics) {
485-
// attributeTypes := flex.AttributeTypesMust[dataPrivacyData](ctx)
486-
481+
func flattenDataPrivacy(apiObject *awstypes.DataPrivacy) (types.List, diag.Diagnostics) {
487482
var diags diag.Diagnostics
488483
elemType := types.ObjectType{AttrTypes: dataPrivacyAttrTypes}
489484

@@ -503,35 +498,37 @@ func flattenDataPrivacy(ctx context.Context, apiObject *awstypes.DataPrivacy) (t
503498
return listVal, diags
504499
}
505500

506-
func expandDataPrivacy(ctx context.Context, tfList []dataPrivacyData) (*awstypes.DataPrivacy, diag.Diagnostics) {
507-
var diags diag.Diagnostics
501+
func expandDataPrivacy(ctx context.Context, tfList []dataPrivacyData) *awstypes.DataPrivacy {
508502
if len(tfList) == 0 {
509-
return nil, diags
503+
return nil
510504
}
511505

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

515509
return &awstypes.DataPrivacy{
516510
ChildDirected: aws.ToBool(cdBool),
517-
}, diags
511+
}
518512
}
519513

520-
func expandMembers(tfList []membersData) (*awstypes.BotMember, diag.Diagnostics) {
521-
var diags diag.Diagnostics
522-
514+
func expandMembers(ctx context.Context, tfList []membersData) []awstypes.BotMember {
523515
if len(tfList) == 0 {
524-
return nil, diags
516+
return nil
517+
}
518+
var mb []awstypes.BotMember
519+
520+
for _, item := range tfList {
521+
new := awstypes.BotMember{
522+
BotMemberAliasId: flex.StringFromFramework(ctx, item.AliasID),
523+
BotMemberAliasName: flex.StringFromFramework(ctx, item.AliasName),
524+
BotMemberId: flex.StringFromFramework(ctx, item.ID),
525+
BotMemberName: flex.StringFromFramework(ctx, item.Name),
526+
BotMemberVersion: flex.StringFromFramework(ctx, item.Version),
527+
}
528+
mb = append(mb, new)
525529
}
526530

527-
mb := tfList[0]
528-
return &awstypes.BotMember{
529-
BotMemberAliasId: aws.String(mb.AliasID.ValueString()),
530-
BotMemberAliasName: aws.String(mb.AliasName.ValueString()),
531-
BotMemberId: aws.String(mb.ID.ValueString()),
532-
BotMemberName: aws.String(mb.Name.ValueString()),
533-
BotMemberVersion: aws.String(mb.Version.ValueString()),
534-
}, diags
531+
return mb
535532
}
536533

537534
func (rd *resourceBotData) refreshFromOutput(ctx context.Context, out *lexmodelsv2.DescribeBotOutput) diag.Diagnostics {
@@ -547,8 +544,7 @@ func (rd *resourceBotData) refreshFromOutput(ctx context.Context, out *lexmodels
547544
rd.Description = flex.StringToFramework(ctx, out.Description)
548545
rd.IdleSessionTTLInSeconds = flex.Int32ToFramework(ctx, out.IdleSessionTTLInSeconds)
549546

550-
// TIP: Setting a complex type.
551-
datap, d := flattenDataPrivacy(ctx, out.DataPrivacy)
547+
datap, d := flattenDataPrivacy(out.DataPrivacy)
552548
diags.Append(d...)
553549
rd.DataPrivacy = datap
554550

internal/service/lexv2models/bot_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ import (
2323

2424
func TestAccLexV2ModelsBot_basic(t *testing.T) {
2525
ctx := acctest.Context(t)
26-
// TIP: This is a long-running test guard for tests that run longer than
27-
// 300s (5 min) generally.
28-
// if testing.Short() {
29-
// t.Skip("skipping long-running test in short mode")
30-
// }
3126

3227
var bot lexmodelsv2.DescribeBotOutput
3328
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
@@ -209,6 +204,8 @@ func testAccPreCheck(ctx context.Context, t *testing.T) {
209204

210205
func testAccBotBaseConfig(rName string) string {
211206
return fmt.Sprintf(`
207+
data "aws_partition" "current" {}
208+
212209
resource "aws_iam_role" "test_role" {
213210
name = %[1]q
214211
assume_role_policy = jsonencode({
@@ -228,7 +225,7 @@ resource "aws_iam_role" "test_role" {
228225
229226
resource "aws_iam_role_policy_attachment" "test-attach" {
230227
role = aws_iam_role.test_role.name
231-
policy_arn = "arn:aws:iam::aws:policy/AmazonLexFullAccess"
228+
policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonLexFullAccess"
232229
}
233230
`, rName)
234231
}

website/docs/r/lexv2models_bot.html.markdown

+11-11
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ resource "aws_lexv2models_bot" "example" {
2929

3030
The following arguments are required:
3131

32-
* `name` - The name of the bot. The bot name must be unique in the account that creates the bot. Type String. Length Constraints: Minimum length of 1. Maximum length of 100.
32+
* `name` - Name of the bot. The bot name must be unique in the account that creates the bot. Type String. Length Constraints: Minimum length of 1. Maximum length of 100.
3333
* `data_privacy` - Provides information on additional privacy protections Amazon Lex should use with the bot's data. See [`data_privacy`](#data-privacy)
34-
* `idle_session_ttl_in_seconds` - The time, in seconds, that Amazon Lex should keep information about a user's conversation with the bot. You can specify between 60 (1 minute) and 86,400 (24 hours) seconds.
35-
* `role_arn` - The Amazon Resource Name (ARN) of an IAM role that has permission to access the bot.
34+
* `idle_session_ttl_in_seconds` - Time, in seconds, that Amazon Lex should keep information about a user's conversation with the bot. You can specify between 60 (1 minute) and 86,400 (24 hours) seconds.
35+
* `role_arn` - ARN of an IAM role that has permission to access the bot.
3636

3737
The following arguments are optional:
3838

3939
* `members` - List of bot members in a network to be created. See [`bot_members`](#bot-members).
40-
* `bot_tags` - A list of tags to add to the bot. You can only add tags when you create a bot.
41-
* `bot_type` - The type of a bot to create.
42-
* `description` - A description of the bot. It appears in lists to help you identify a particular bot.
43-
* `test_bot_alias_tags` - A list of tags to add to the test alias for a bot. You can only add tags when you create a bot.
40+
* `bot_tags` - List of tags to add to the bot. You can only add tags when you create a bot.
41+
* `bot_type` - Type of a bot to create.
42+
* `description` - Description of the bot. It appears in lists to help you identify a particular bot.
43+
* `test_bot_alias_tags` - List of tags to add to the test alias for a bot. You can only add tags when you create a bot.
4444

4545
## Attribute Reference
4646

4747
This resource exports the following attributes in addition to the arguments above:
4848

49-
* `id` - A unique identifier for a particular bot.
49+
* `id` - Unique identifier for a particular bot.
5050

5151
### Data Privacy
5252

@@ -64,9 +64,9 @@ This resource exports the following attributes in addition to the arguments abov
6464

6565
[Configuration options](https://developer.hashicorp.com/terraform/language/resources/syntax#operation-timeouts):
6666

67-
* `create` - (Default `60m`)
68-
* `update` - (Default `180m`)
69-
* `delete` - (Default `90m`)
67+
* `create` - (Default `30m`)
68+
* `update` - (Default `30m`)
69+
* `delete` - (Default `30m`)
7070

7171
## Import
7272

0 commit comments

Comments
 (0)