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 Stack #20547

Merged
merged 20 commits into from
Aug 24, 2021
3 changes: 3 additions & 0 deletions .changelog/20547.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_appstream_stack
```
32 changes: 32 additions & 0 deletions aws/internal/service/appstream/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package finder

import (
"context"
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/appstream"
)

// StackByName Retrieve a appstream stack by name
func StackByName(ctx context.Context, conn *appstream.AppStream, name string) (*appstream.Stack, error) {
input := &appstream.DescribeStacksInput{
Names: []*string{aws.String(name)},
}

var stack *appstream.Stack
resp, err := conn.DescribeStacksWithContext(ctx, input)
if err != nil {
return nil, err
}

if len(resp.Stacks) > 1 {
return nil, fmt.Errorf("[ERROR] got more than one stack with the name %s", name)
}

if len(resp.Stacks) == 1 {
stack = resp.Stacks[0]
}

return stack, nil
}
25 changes: 25 additions & 0 deletions aws/internal/service/appstream/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package waiter

import (
"context"

"github.com/aws/aws-sdk-go/service/appstream"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/appstream/finder"
)

//StackState fetches the fleet and its state
func StackState(ctx context.Context, conn *appstream.AppStream, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
stack, err := finder.StackByName(ctx, conn, name)
if err != nil {
return nil, "Unknown", err
}

if stack == nil {
return stack, "NotFound", nil
}

return stack, "AVAILABLE", nil
}
}
31 changes: 31 additions & 0 deletions aws/internal/service/appstream/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package waiter

import (
"context"
"time"

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

const (
// StackOperationTimeout Maximum amount of time to wait for Stack operation eventual consistency
StackOperationTimeout = 4 * time.Minute
)

// StackStateDeleted waits for a deleted stack
func StackStateDeleted(ctx context.Context, conn *appstream.AppStream, name string) (*appstream.Stack, error) {
stateConf := &resource.StateChangeConf{
Target: []string{"NotFound", "Unknown"},
Refresh: StackState(ctx, conn, name),
Timeout: StackOperationTimeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*appstream.Stack); ok {
return output, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ func Provider() *schema.Provider {
"aws_apprunner_connection": resourceAwsAppRunnerConnection(),
"aws_apprunner_custom_domain_association": resourceAwsAppRunnerCustomDomainAssociation(),
"aws_apprunner_service": resourceAwsAppRunnerService(),
"aws_appstream_stack": resourceAwsAppStreamStack(),
"aws_appsync_api_key": resourceAwsAppsyncApiKey(),
"aws_appsync_datasource": resourceAwsAppsyncDatasource(),
"aws_appsync_function": resourceAwsAppsyncFunction(),
Expand Down
Loading