Skip to content

Commit

Permalink
Merge pull request #21485 from coderGo93/appstream-user
Browse files Browse the repository at this point in the history
New resource for AppStream User and Stack User Association
  • Loading branch information
gdavison authored Nov 23, 2021
2 parents baa990e + f130d56 commit d088921
Show file tree
Hide file tree
Showing 14 changed files with 1,061 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changelog/21485.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
aws_appstream_user
```

```release-note:new-resource
aws_appstream_stack_user_association
```
10 changes: 6 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,12 @@ func Provider() *schema.Provider {
"aws_apprunner_custom_domain_association": apprunner.ResourceCustomDomainAssociation(),
"aws_apprunner_service": apprunner.ResourceService(),

"aws_appstream_directory_config": appstream.ResourceDirectoryConfig(),
"aws_appstream_fleet": appstream.ResourceFleet(),
"aws_appstream_image_builder": appstream.ResourceImageBuilder(),
"aws_appstream_stack": appstream.ResourceStack(),
"aws_appstream_directory_config": appstream.ResourceDirectoryConfig(),
"aws_appstream_fleet": appstream.ResourceFleet(),
"aws_appstream_image_builder": appstream.ResourceImageBuilder(),
"aws_appstream_stack": appstream.ResourceStack(),
"aws_appstream_user_stack_association": appstream.ResourceUserStackAssociation(),
"aws_appstream_user": appstream.ResourceUser(),

"aws_appsync_api_key": appsync.ResourceAPIKey(),
"aws_appsync_datasource": appsync.ResourceDataSource(),
Expand Down
60 changes: 59 additions & 1 deletion internal/service/appstream/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appstream"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// FindStackByName Retrieve a appstream stack by name
Expand Down Expand Up @@ -82,12 +84,68 @@ func FindImageBuilderByName(ctx context.Context, conn *appstream.AppStream, name
return !lastPage
})

if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if result == nil {
return nil, nil
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return result, nil
}

// FindUserByUserNameAndAuthType Retrieve a appstream fleet by Username and authentication type
func FindUserByUserNameAndAuthType(ctx context.Context, conn *appstream.AppStream, username, authType string) (*appstream.User, error) {
input := &appstream.DescribeUsersInput{
AuthenticationType: aws.String(authType),
}

var result *appstream.User

err := describeUsersPagesWithContext(ctx, conn, input, func(page *appstream.DescribeUsersOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, user := range page.Users {
if user == nil {
continue
}
if aws.StringValue(user.UserName) == username {
result = user
return false
}
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, appstream.ErrCodeResourceNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}
if err != nil {
return nil, err
}

if result == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return result, nil
Expand Down
1 change: 1 addition & 0 deletions internal/service/appstream/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func init() {
func testAccErrorCheckSkipAppStream(t *testing.T) resource.ErrorCheckFunc {
return acctest.ErrorCheckSkipMessagesContaining(t,
"ResourceNotFoundException: The image",
"InvalidParameterValueException: The AppStream 2.0 user pool feature",
)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/appstream/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeFleets,DescribeImageBuilders,DescribeStacks
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeFleets,DescribeImageBuilders,DescribeStacks,DescribeUsers
//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsMap -UpdateTags
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
23 changes: 22 additions & 1 deletion internal/service/appstream/list_pages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions internal/service/appstream/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appstream"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)

//statusStackState fetches the fleet and its state
Expand Down Expand Up @@ -57,3 +58,20 @@ func statusImageBuilderState(ctx context.Context, conn *appstream.AppStream, nam
return imageBuilder, aws.StringValue(imageBuilder.State), nil
}
}

//statusUserAvailable fetches the user available
func statusUserAvailable(ctx context.Context, conn *appstream.AppStream, username, authType string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
user, err := FindUserByUserNameAndAuthType(ctx, conn, username, authType)

if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return nil, "", err
}

return user, userAvailable, nil
}
}
Loading

0 comments on commit d088921

Please sign in to comment.