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 Fleet #20543

Merged
merged 28 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/20543.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_appstream_fleet
```
8 changes: 4 additions & 4 deletions aws/data_source_aws_iam_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAccAWSDataSourceIAMGroup_basic(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAwsIAMGroupConfig(groupName),
Config: testAccAwsIAMGroupDataSourceConfig(groupName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.aws_iam_group.test", "group_id"),
resource.TestCheckResourceAttr("data.aws_iam_group.test", "path", "/"),
Expand All @@ -42,7 +42,7 @@ func TestAccAWSDataSourceIAMGroup_users(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAwsIAMGroupConfigWithUser(groupName, userName, groupMemberShipName, userCount),
Config: testAccAwsIAMGroupDataSourceConfigWithUser(groupName, userName, groupMemberShipName, userCount),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.aws_iam_group.test", "group_id"),
resource.TestCheckResourceAttr("data.aws_iam_group.test", "path", "/"),
Expand All @@ -59,7 +59,7 @@ func TestAccAWSDataSourceIAMGroup_users(t *testing.T) {
})
}

func testAccAwsIAMGroupConfig(name string) string {
func testAccAwsIAMGroupDataSourceConfig(name string) string {
return fmt.Sprintf(`
resource "aws_iam_group" "group" {
name = "%s"
Expand All @@ -72,7 +72,7 @@ data "aws_iam_group" "test" {
`, name)
}

func testAccAwsIAMGroupConfigWithUser(groupName, userName, membershipName string, userCount int) string {
func testAccAwsIAMGroupDataSourceConfigWithUser(groupName, userName, membershipName string, userCount int) string {
return fmt.Sprintf(`
resource "aws_iam_group" "group" {
name = "%s"
Expand Down
8 changes: 4 additions & 4 deletions aws/data_source_aws_iam_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccAWSDataSourceIAMRole_basic(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAwsIAMRoleConfig(roleName),
Config: testAccAwsIAMRoleDataSourceConfig(roleName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "assume_role_policy", resourceName, "assume_role_policy"),
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestAccAWSDataSourceIAMRole_tags(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAwsIAMRoleConfig_tags(roleName),
Config: testAccAwsIAMRoleDataSourceConfig_tags(roleName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "assume_role_policy", resourceName, "assume_role_policy"),
Expand All @@ -67,7 +67,7 @@ func TestAccAWSDataSourceIAMRole_tags(t *testing.T) {
})
}

func testAccAwsIAMRoleConfig(roleName string) string {
func testAccAwsIAMRoleDataSourceConfig(roleName string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
name = %[1]q
Expand Down Expand Up @@ -97,7 +97,7 @@ data "aws_iam_role" "test" {
`, roleName)
}

func testAccAwsIAMRoleConfig_tags(roleName string) string {
func testAccAwsIAMRoleDataSourceConfig_tags(roleName string) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
name = %q
Expand Down
27 changes: 26 additions & 1 deletion aws/internal/service/appstream/finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ func StackByName(ctx context.Context, conn *appstream.AppStream, name string) (*

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)
return nil, fmt.Errorf("got more than one stack with the name %s", name)
}

if len(resp.Stacks) == 1 {
Expand All @@ -30,3 +31,27 @@ func StackByName(ctx context.Context, conn *appstream.AppStream, name string) (*

return stack, nil
}

// FleetByName Retrieve a appstream fleet by name
func FleetByName(ctx context.Context, conn *appstream.AppStream, name string) (*appstream.Fleet, error) {
input := &appstream.DescribeFleetsInput{
Names: []*string{aws.String(name)},
}

var fleet *appstream.Fleet
resp, err := conn.DescribeFleetsWithContext(ctx, input)

if err != nil {
return nil, err
}

if len(resp.Fleets) > 1 {
return nil, fmt.Errorf("got more than one fleet with the name %s", name)
}

if len(resp.Fleets) == 1 {
fleet = resp.Fleets[0]
}

return fleet, nil
}
18 changes: 18 additions & 0 deletions aws/internal/service/appstream/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package waiter
import (
"context"

"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/terraform-providers/terraform-provider-aws/aws/internal/service/appstream/finder"
Expand All @@ -23,3 +24,20 @@ func StackState(ctx context.Context, conn *appstream.AppStream, name string) res
return stack, "AVAILABLE", nil
}
}

//FleetState fetches the fleet and its state
func FleetState(ctx context.Context, conn *appstream.AppStream, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
fleet, err := finder.FleetByName(ctx, conn, name)

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

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

return fleet, aws.StringValue(fleet.State), nil
}
}
41 changes: 41 additions & 0 deletions aws/internal/service/appstream/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
const (
// StackOperationTimeout Maximum amount of time to wait for Stack operation eventual consistency
StackOperationTimeout = 4 * time.Minute

// FleetStateTimeout Maximum amount of time to wait for the FleetState to be RUNNING or STOPPED
FleetStateTimeout = 180 * time.Minute
// FleetOperationTimeout Maximum amount of time to wait for Fleet operation eventual consistency
FleetOperationTimeout = 15 * time.Minute
)

// StackStateDeleted waits for a deleted stack
Expand All @@ -29,3 +34,39 @@ func StackStateDeleted(ctx context.Context, conn *appstream.AppStream, name stri

return nil, err
}

// FleetStateRunning waits for a fleet running
func FleetStateRunning(ctx context.Context, conn *appstream.AppStream, name string) (*appstream.Fleet, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{appstream.FleetStateStarting},
Target: []string{appstream.FleetStateRunning},
Refresh: FleetState(ctx, conn, name),
Timeout: FleetStateTimeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

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

return nil, err
}

// FleetStateStopped waits for a fleet stopped
func FleetStateStopped(ctx context.Context, conn *appstream.AppStream, name string) (*appstream.Fleet, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{appstream.FleetStateStopping},
Target: []string{appstream.FleetStateStopped},
Refresh: FleetState(ctx, conn, name),
Timeout: FleetStateTimeout,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*appstream.Fleet); 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 @@ -537,6 +537,7 @@ func Provider() *schema.Provider {
"aws_apprunner_custom_domain_association": resourceAwsAppRunnerCustomDomainAssociation(),
"aws_apprunner_service": resourceAwsAppRunnerService(),
"aws_appstream_stack": resourceAwsAppStreamStack(),
"aws_appstream_fleet": resourceAwsAppStreamFleet(),
"aws_appsync_api_key": resourceAwsAppsyncApiKey(),
"aws_appsync_datasource": resourceAwsAppsyncDatasource(),
"aws_appsync_function": resourceAwsAppsyncFunction(),
Expand Down
Loading