From d736910b88baa5e5f7772576e429eabd2a5c1177 Mon Sep 17 00:00:00 2001 From: kosmodromov Date: Sat, 6 Apr 2019 17:49:46 +0300 Subject: [PATCH 1/2] Add fleet_type option for Gamelift fleets. #3809 --- aws/resource_aws_gamelift_fleet.go | 9 +++++++++ aws/resource_aws_gamelift_fleet_test.go | 4 ++++ website/docs/r/gamelift_fleet.html.markdown | 2 ++ 3 files changed, 15 insertions(+) diff --git a/aws/resource_aws_gamelift_fleet.go b/aws/resource_aws_gamelift_fleet.go index 36212a99733c..690499711486 100644 --- a/aws/resource_aws_gamelift_fleet.go +++ b/aws/resource_aws_gamelift_fleet.go @@ -40,6 +40,11 @@ func resourceAwsGameliftFleet() *schema.Resource { Required: true, ForceNew: true, }, + "fleet_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "name": { Type: schema.TypeString, Required: true, @@ -187,6 +192,9 @@ func resourceAwsGameliftFleetCreate(d *schema.ResourceData, meta interface{}) er if v, ok := d.GetOk("description"); ok { input.Description = aws.String(v.(string)) } + if v, ok := d.GetOk("fleet_type"); ok { + input.FleetType = aws.String(v.(string)) + } if v, ok := d.GetOk("ec2_inbound_permission"); ok { input.EC2InboundPermissions = expandGameliftIpPermissions(v.([]interface{})) } @@ -286,6 +294,7 @@ func resourceAwsGameliftFleetRead(d *schema.ResourceData, meta interface{}) erro d.Set("log_paths", aws.StringValueSlice(fleet.LogPaths)) d.Set("metric_groups", flattenStringList(fleet.MetricGroups)) d.Set("name", fleet.Name) + d.Set("fleet_type", fleet.FleetType) d.Set("new_game_session_protection_policy", fleet.NewGameSessionProtectionPolicy) d.Set("operating_system", fleet.OperatingSystem) d.Set("resource_creation_limit_policy", flattenGameliftResourceCreationLimitPolicy(fleet.ResourceCreationLimitPolicy)) diff --git a/aws/resource_aws_gamelift_fleet_test.go b/aws/resource_aws_gamelift_fleet_test.go index 48fd3aa25d3e..f67f2723ad70 100644 --- a/aws/resource_aws_gamelift_fleet_test.go +++ b/aws/resource_aws_gamelift_fleet_test.go @@ -347,6 +347,7 @@ func TestAccAWSGameliftFleet_allFields(t *testing.T) { resource.TestCheckResourceAttrSet("aws_gamelift_fleet.test", "build_id"), resource.TestMatchResourceAttr("aws_gamelift_fleet.test", "arn", regexp.MustCompile(`^arn:[^:]+:gamelift:[^:]+:[^:]+:.+$`)), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "ec2_instance_type", "c4.large"), + resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "fleet_type", "ON_DEMAND"), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "name", fleetName), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "description", desc), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "ec2_inbound_permission.#", "3"), @@ -386,6 +387,7 @@ func TestAccAWSGameliftFleet_allFields(t *testing.T) { resource.TestCheckResourceAttrSet("aws_gamelift_fleet.test", "build_id"), resource.TestMatchResourceAttr("aws_gamelift_fleet.test", "arn", regexp.MustCompile(`^arn:[^:]+:gamelift:[^:]+:[^:]+:.+$`)), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "ec2_instance_type", "c4.large"), + resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "fleet_type", "ON_DEMAND"), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "name", fleetName), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "description", desc), resource.TestCheckResourceAttr("aws_gamelift_fleet.test", "ec2_inbound_permission.#", "3"), @@ -536,6 +538,7 @@ func testAccAWSGameliftFleetAllFieldsConfig(fleetName, desc, launchPath string, resource "aws_gamelift_fleet" "test" { build_id = "${aws_gamelift_build.test.id}" ec2_instance_type = "c4.large" + fleet_type = "ON_DEMAND" name = "%s" description = "%s" @@ -587,6 +590,7 @@ func testAccAWSGameliftFleetAllFieldsUpdatedConfig(fleetName, desc, launchPath s resource "aws_gamelift_fleet" "test" { build_id = "${aws_gamelift_build.test.id}" ec2_instance_type = "c4.large" + fleet_type = "ON_DEMAND" name = "%s" description = "%s" diff --git a/website/docs/r/gamelift_fleet.html.markdown b/website/docs/r/gamelift_fleet.html.markdown index 0ecd4cc45538..4ef01983f599 100644 --- a/website/docs/r/gamelift_fleet.html.markdown +++ b/website/docs/r/gamelift_fleet.html.markdown @@ -16,6 +16,7 @@ Provides a Gamelift Fleet resource. resource "aws_gamelift_fleet" "example" { build_id = "${aws_gamelift_build.example.id}" ec2_instance_type = "t2.micro" + fleet_type = "ON_DEMAND" name = "example-fleet-name" runtime_configuration { @@ -33,6 +34,7 @@ The following arguments are supported: * `build_id` - (Required) ID of the Gamelift Build to be deployed on the fleet. * `ec2_instance_type` - (Required) Name of an EC2 instance type. e.g. `t2.micro` +* `fleet_type` - (Optional) Type of fleet. This value must be `ON_DEMAND` or `SPOT`. Defaults to `ON_DEMAND`. * `name` - (Required) The name of the fleet. * `description` - (Optional) Human-readable description of the fleet. * `ec2_inbound_permission` - (Optional) Range of IP addresses and port settings that permit inbound traffic to access server processes running on the fleet. See below. From d8b5de8812ebda88d80580498eee101d06836b48 Mon Sep 17 00:00:00 2001 From: kosmodromov Date: Tue, 28 Jan 2020 23:38:10 +0100 Subject: [PATCH 2/2] remove dup and add validation --- aws/resource_aws_gamelift_fleet.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aws/resource_aws_gamelift_fleet.go b/aws/resource_aws_gamelift_fleet.go index fc681385f1c8..30a77f577412 100644 --- a/aws/resource_aws_gamelift_fleet.go +++ b/aws/resource_aws_gamelift_fleet.go @@ -44,6 +44,11 @@ func resourceAwsGameliftFleet() *schema.Resource { Type: schema.TypeString, Optional: true, ForceNew: true, + Default: gamelift.FleetTypeOnDemand, + ValidateFunc: validation.StringInSlice([]string{ + gamelift.FleetTypeOnDemand, + gamelift.FleetTypeSpot, + }, false), }, "name": { Type: schema.TypeString, @@ -318,7 +323,6 @@ func resourceAwsGameliftFleetRead(d *schema.ResourceData, meta interface{}) erro d.Set("name", fleet.Name) d.Set("fleet_type", fleet.FleetType) d.Set("instance_role_arn", fleet.InstanceRoleArn) - d.Set("fleet_type", fleet.FleetType) d.Set("new_game_session_protection_policy", fleet.NewGameSessionProtectionPolicy) d.Set("operating_system", fleet.OperatingSystem) d.Set("resource_creation_limit_policy", flattenGameliftResourceCreationLimitPolicy(fleet.ResourceCreationLimitPolicy))