-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20547 from coderGo93/appstream-stack
New resource for AppStream Stack
- Loading branch information
Showing
9 changed files
with
1,202 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
aws_appstream_stack | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.