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 for AppStream User and Stack User Association #21485

Merged
merged 20 commits into from
Nov 23, 2021

Conversation

coderGo93
Copy link
Contributor

@coderGo93 coderGo93 commented Oct 25, 2021

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #6508

Output from acceptance testing:

AppStream User and Stack User Association

$  make testacc TESTARGS='-run=TestAccAppStreamUser' PKG_NAME=internal/service/appstream       
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/appstream/... -v -count 1 -parallel 20 -run=TestAccAppStreamUser -timeout 180m
=== RUN   TestAccAppStreamUserStackAssociation_basic
=== PAUSE TestAccAppStreamUserStackAssociation_basic
=== RUN   TestAccAppStreamUserStackAssociation_disappears
=== PAUSE TestAccAppStreamUserStackAssociation_disappears
=== RUN   TestAccAppStreamUserStackAssociation_complete
=== PAUSE TestAccAppStreamUserStackAssociation_complete
=== RUN   TestAccAppStreamUser_basic
=== PAUSE TestAccAppStreamUser_basic
=== RUN   TestAccAppStreamUser_disappears
=== PAUSE TestAccAppStreamUser_disappears
=== RUN   TestAccAppStreamUser_complete
=== PAUSE TestAccAppStreamUser_complete
=== CONT  TestAccAppStreamUserStackAssociation_basic
=== CONT  TestAccAppStreamUser_disappears
=== CONT  TestAccAppStreamUser_complete
=== CONT  TestAccAppStreamUserStackAssociation_complete
=== CONT  TestAccAppStreamUser_basic
=== CONT  TestAccAppStreamUserStackAssociation_disappears
--- PASS: TestAccAppStreamUser_basic (32.67s)
--- PASS: TestAccAppStreamUser_disappears (35.67s)
--- PASS: TestAccAppStreamUserStackAssociation_disappears (37.50s)
--- PASS: TestAccAppStreamUserStackAssociation_basic (41.20s)
--- PASS: TestAccAppStreamUser_complete (64.23s)
--- PASS: TestAccAppStreamUserStackAssociation_complete (67.03s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/appstream  68.864s


@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/appstream Issues and PRs that pertain to the appstream service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 25, 2021
@justinretzolk justinretzolk added new-resource Introduces a new resource. and removed needs-triage Waiting for first response or review from a maintainer. labels Oct 26, 2021
@gdavison gdavison mentioned this pull request Nov 8, 2021
8 tasks
@gdavison gdavison self-assigned this Nov 8, 2021
Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @coderGo93. I have a number of suggested changes.

internal/service/appstream/stack_user_association.go Outdated Show resolved Hide resolved
internal/service/appstream/user.go Outdated Show resolved Hide resolved
internal/service/appstream/user.go Outdated Show resolved Hide resolved
_, err = conn.CreateUserWithContext(ctx, input)
}
if err != nil {
return diag.FromErr(fmt.Errorf("error creating Appstream User (%s): %w", d.Id(), err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error and log messages should use the name that AWS uses, "AppStream"

Suggested change
return diag.FromErr(fmt.Errorf("error creating Appstream User (%s): %w", d.Id(), err))
return diag.FromErr(fmt.Errorf("error creating AppStream User (%s): %w", d.Id(), err))

internal/service/appstream/user.go Outdated Show resolved Hide resolved
Comment on lines 71 to 90
err = resource.RetryContext(ctx, fleetOperationTimeout, func() *resource.RetryError {
output, err = conn.BatchAssociateUserStackWithContext(ctx, &appstream.BatchAssociateUserStackInput{
UserStackAssociations: []*appstream.UserStackAssociation{input},
})
if err != nil {
if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}

return nil
})

if tfresource.TimedOut(err) {
output, err = conn.BatchAssociateUserStackWithContext(ctx, &appstream.BatchAssociateUserStackInput{
UserStackAssociations: []*appstream.UserStackAssociation{input},
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a Retry loop? The documentation for BatchAssociateUserStack seems to indicate that the function is synchronous.

internal/service/appstream/stack_user_association.go Outdated Show resolved Hide resolved
{
Config: testAccStackUserAssociationConfig(rName, authType, rEmail),
Check: resource.ComposeTestCheckFunc(
testAccCheckStackUserAssociationExists(resourceName),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check all parameter values

resourceName := "aws_appstream_stack_user_association.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
authType := "USERPOOL"
rEmail := acctest.RandomEmailAddress("hashicorp.com")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use a random domain name generated by acctest.RandomDomainName(), to avoid being delivered to an actual email address.

Suggested change
rEmail := acctest.RandomEmailAddress("hashicorp.com")
domain := acctest.RandomDomainName()
rEmail := acctest.RandomEmailAddress(domain)

internal/service/appstream/user.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added the generators Relates to code generators. label Nov 9, 2021
@coderGo93 coderGo93 requested a review from gdavison November 9, 2021 23:59
Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, @coderGo93. There are a few things to change from the initial review plus some I've added to this review.

I've also added a commit to show what I meant about returning resource.NotFoundError from the FindUserByUserNameAndAuthType() function in #21485 (comment)

internal/service/appstream/user.go Outdated Show resolved Hide resolved
Comment on lines 107 to 125
// Enabling/disabling workflow
if v, ok := d.GetOk("enabled"); ok {
if v.(bool) {
input := &appstream.EnableUserInput{
AuthenticationType: aws.String(authType),
UserName: aws.String(userName),
}

_, err = conn.EnableUserWithContext(ctx, input)
if err != nil {
return diag.FromErr(fmt.Errorf("error enabling AppStream User (%s): %w", d.Id(), err))
}
} else {
input := &appstream.DisableUserInput{
AuthenticationType: aws.String(authType),
UserName: aws.String(userName),
}

_, err = conn.DisableUserWithContext(ctx, input)
if err != nil {
return diag.FromErr(fmt.Errorf("error disabling AppStream User (%s): %w", d.Id(), err))
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like users are enabled by default when they're created, so we only need to change this when enabled is false

// waitUserAvailable waits for a user be available
func waitUserAvailable(ctx context.Context, conn *appstream.AppStream, username, authType string) (*appstream.User, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{"NotFound"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the Refresh function returns nil for the resource value, the status isn't checked, so the Pending list can be removed.

func waitUserAvailable(ctx context.Context, conn *appstream.AppStream, username, authType string) (*appstream.User, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{"NotFound"},
Target: []string{"AVAILABLE"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a constant shared with the status function

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
acctest.PreCheckHasIAMRole(t, "AmazonAppStreamServiceAccess")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating AppStream User resources doesn't require this IAM role, so the check can be removed


for _, err := range output.Errors {
errs = multierror.Append(errs, fmt.Errorf("%s: %s", aws.StringValue(err.ErrorCode), aws.StringValue(err.ErrorMessage)))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return errs, otherwise the errors collected here are ignored

}

if len(resp.UserStackAssociations) == 0 {
log.Printf("[WARN] Appstream User (%s) not found, removing from state", d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Printf("[WARN] Appstream User (%s) not found, removing from state", d.Id())
log.Printf("[WARN] AppStream User Stack Association (%s) not found, removing from state", d.Id())

})

if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
log.Printf("[WARN] Appstream Stack User Association (%s) not found, removing from state", d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log.Printf("[WARN] Appstream Stack User Association (%s) not found, removing from state", d.Id())
log.Printf("[WARN] AppStream User Stack Association (%s) not found, removing from state", d.Id())

Comment on lines 93 to 98
if v, ok := d.GetOk("message_action"); ok {
input.MessageAction = aws.String(v.(string))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message_action parameter should be restored. In #21485 (comment), I was suggesting removing RESEND as a valid option and ignoring changes to the value instead of making it ForceNew. There should still be the options of sending the welcome email or setting SUPPRESS to not send the email.
Another option would be to use a TypeBool send_welcome_email (or send_email_notification to match aws_appstream_user_stack_association)

Copy link
Contributor Author

@coderGo93 coderGo93 Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I misunderstood then, thanks for the clarification.

Type: schema.TypeString,
Required: true,
ForceNew: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter send_email_notification should be restored here, so that the email notification can be controlled. In #21485 (comment), I meant that it should not be ForceNew and that changes should be ignored, since it only has an effect at creation time

@coderGo93 coderGo93 requested a review from gdavison November 18, 2021 00:59
Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @coderGo93. I've made a few updates to tweak the error messages and enhance the tests

Acceptance test results in Commercial partition

--- PASS: TestAccAppStreamUser_disappears (34.66s)
--- PASS: TestAccAppStreamUser_basic (45.50s)
--- PASS: TestAccAppStreamUserStackAssociation_disappears (49.88s)
--- PASS: TestAccAppStreamUserStackAssociation_basic (66.23s)
--- PASS: TestAccAppStreamUserStackAssociation_complete (78.13s)
--- PASS: TestAccAppStreamUser_complete (89.22s)

Acceptance test results in GovCloud (AppStream User pools are not supported in GovCloud)

--- SKIP: TestAccAppStreamUser_complete (15.94s)
--- SKIP: TestAccAppStreamUser_disappears (15.96s)
--- SKIP: TestAccAppStreamUser_basic (15.99s)
--- SKIP: TestAccAppStreamUserStackAssociation_basic (20.52s)
--- SKIP: TestAccAppStreamUserStackAssociation_complete (20.64s)
--- SKIP: TestAccAppStreamUserStackAssociation_disappears (20.79s)

@gdavison gdavison merged commit d088921 into hashicorp:main Nov 23, 2021
@github-actions github-actions bot added this to the v3.67.0 milestone Nov 23, 2021
@github-actions
Copy link

github-actions bot commented Dec 1, 2021

This functionality has been released in v3.67.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Jun 7, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. generators Relates to code generators. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/appstream Issues and PRs that pertain to the appstream service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants