Resource: aws_gamelift_game_server_group

Provides an GameLift Game Server Group resource.

Example Usage

resource "aws_gamelift_game_server_group" "example" {
  game_server_group_name = "example"

  instance_definition {
    instance_type = "c5.large"
  }

  instance_definition {
    instance_type = "c5a.large"
  }

  launch_template {
    id = aws_launch_template.example.id
  }

  max_size = 1
  min_size = 1
  role_arn = aws_iam_role.example.arn

  depends_on = [
    aws_iam_role_policy_attachment.example
  ]
}

Full usage:

resource "aws_gamelift_game_server_group" "example" {
  auto_scaling_policy {
    estimated_instance_warmup = 60
    target_tracking_configuration {
      target_value = 75
    }
  }

  balancing_strategy            = "SPOT_ONLY"
  game_server_group_name        = "example"
  game_server_protection_policy = "FULL_PROTECTION"

  instance_definition {
    instance_type     = "c5.large"
    weighted_capacity = "1"
  }

  instance_definition {
    instance_type     = "c5.2xlarge"
    weighted_capacity = "2"
  }

  launch_template {
    id      = aws_launch_template.example.id
    version = "1"
  }

  max_size = 1
  min_size = 1
  role_arn = aws_iam_role.example.arn

  tags = {
    Name = "example"
  }

  vpc_subnets = [
    "subnet-12345678",
    "subnet-23456789"
  ]

  depends_on = [
    aws_iam_role_policy_attachment.example
  ]
}

Example IAM Role for GameLift Game Server Group

data "aws_partition" "current" {}

data "aws_iam_policy_document" "assume_role" {
  statement {
    effect = "Allow"

    principals {
      type = "Service"

      identifiers = [
        "autoscaling.amazonaws.com",
        "gamelift.amazonaws.com",
      ]
    }

    actions = ["sts:AssumeRole"]
  }
}

resource "aws_iam_role" "example" {
  assume_role_policy = data.aws_iam_policy_document.assume_role.json
  name               = "gamelift-game-server-group-example"
}

resource "aws_iam_role_policy_attachment" "example" {
  policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/GameLiftGameServerGroupPolicy"
  role       = aws_iam_role.example.name
}

Argument Reference

This resource supports the following arguments:

auto_scaling_policy

Configuration settings to define a scaling policy for the Auto Scaling group that is optimized for game hosting. The scaling policy uses the metric PercentUtilizedGameServers to maintain a buffer of idle game servers that can immediately accommodate new games and players.

target_tracking_configuration

Settings for a target-based scaling policy applied to Auto Scaling group. These settings are used to create a target-based policy that tracks the GameLift FleetIQ metric PercentUtilizedGameServers and specifies a target value for the metric.

instance_definition

The EC2 instance types and sizes to use in the Auto Scaling group. The instance definitions must specify at least two different instance types that are supported by GameLift FleetIQ.

launch_template

The EC2 launch template that contains configuration settings and game server code to be deployed to all instances in the game server group. You can specify the template using either the template name or ID.

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import GameLift Game Server Group using the name. For example:

import {
  to = aws_gamelift_game_server_group.example
  id = "example"
}

Using terraform import, import GameLift Game Server Group using the name. For example:

% terraform import aws_gamelift_game_server_group.example example