Skip to content

Commit

Permalink
r/aws_gamelift_game_server_group: New resource
Browse files Browse the repository at this point in the history
  • Loading branch information
lystor committed Mar 9, 2021
1 parent 5e7785b commit 173692b
Show file tree
Hide file tree
Showing 6 changed files with 2,060 additions and 0 deletions.
33 changes: 33 additions & 0 deletions aws/internal/service/gamelift/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package waiter

import (
"errors"

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

func GameServerGroupState(conn *gamelift.GameLift, gameServerGroupID string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := conn.DescribeGameServerGroup(&gamelift.DescribeGameServerGroupInput{
GameServerGroupName: aws.String(gameServerGroupID),
})

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

if output == nil || output.GameServerGroup == nil {
return nil, "", nil
}

status := aws.StringValue(output.GameServerGroup.Status)

if status == gamelift.GameServerGroupStatusError {
return nil, status, errors.New(aws.StringValue(output.GameServerGroup.StatusReason))
}

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

import (
"time"

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

func GameServerGroupActive(conn *gamelift.GameLift, gameServerGroupID string, timeout time.Duration) (*gamelift.GameServerGroup, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
gamelift.GameServerGroupStatusNew,
gamelift.GameServerGroupStatusActivating,
},
Target: []string{
gamelift.GameServerGroupStatusActive,
},
Refresh: GameServerGroupState(conn, gameServerGroupID),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*gamelift.GameServerGroup); ok {
return v, err
}

return nil, err
}

func GameServerGroupDeleted(conn *gamelift.GameLift, gameServerGroupID string, timeout time.Duration) (*gamelift.GameServerGroup, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
gamelift.GameServerGroupStatusDeleteScheduled,
gamelift.GameServerGroupStatusDeleting,
gamelift.GameServerGroupStatusDeleted,
},
Target: []string{},
Refresh: GameServerGroupState(conn, gameServerGroupID),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

if v, ok := outputRaw.(*gamelift.GameServerGroup); ok {
return v, 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 @@ -688,6 +688,7 @@ func Provider() *schema.Provider {
"aws_gamelift_alias": resourceAwsGameliftAlias(),
"aws_gamelift_build": resourceAwsGameliftBuild(),
"aws_gamelift_fleet": resourceAwsGameliftFleet(),
"aws_gamelift_game_server_group": resourceAwsGameliftGameServerGroup(),
"aws_gamelift_game_session_queue": resourceAwsGameliftGameSessionQueue(),
"aws_glacier_vault": resourceAwsGlacierVault(),
"aws_glacier_vault_lock": resourceAwsGlacierVaultLock(),
Expand Down
Loading

0 comments on commit 173692b

Please sign in to comment.