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

r/gamelift_script - add new resource #11560

Merged
merged 7 commits into from
Feb 13, 2022
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
11 changes: 11 additions & 0 deletions .changelog/11560.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:new-resource
aws_gamelift_script
```

```release-note:enhancement
resource/aws_gamelift_fleet: Adds `script_id` argument.
```

```release-note:enhancement
resource/aws_gamelift_fleet: Adds `script_arn` attribute.
```
1 change: 1 addition & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,7 @@ func Provider() *schema.Provider {
"aws_gamelift_build": gamelift.ResourceBuild(),
"aws_gamelift_fleet": gamelift.ResourceFleet(),
"aws_gamelift_game_session_queue": gamelift.ResourceGameSessionQueue(),
"aws_gamelift_script": gamelift.ResourceScript(),

"aws_glacier_vault": glacier.ResourceVault(),
"aws_glacier_vault_lock": glacier.ResourceVaultLock(),
Expand Down
25 changes: 25 additions & 0 deletions internal/service/gamelift/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,28 @@ func FindFleetByID(conn *gamelift.GameLift, id string) (*gamelift.FleetAttribute

return fleet, nil
}

func FindScriptByID(conn *gamelift.GameLift, id string) (*gamelift.Script, error) {
input := &gamelift.DescribeScriptInput{
ScriptId: aws.String(id),
}

output, err := conn.DescribeScript(input)

if tfawserr.ErrCodeEquals(err, gamelift.ErrCodeNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || output.Script == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.Script, nil
}
29 changes: 25 additions & 4 deletions internal/service/gamelift/fleet.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ func ResourceFleet() *schema.Resource {
Computed: true,
},
"build_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ExactlyOneOf: []string{"build_id", "script_id"},
},
"certificate_configuration": {
Type: schema.TypeList,
Expand All @@ -79,6 +80,7 @@ func ResourceFleet() *schema.Resource {
"ec2_inbound_permission": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MaxItems: 50,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -215,6 +217,16 @@ func ResourceFleet() *schema.Resource {
},
},
},
"script_arn": {
Type: schema.TypeString,
Computed: true,
},
"script_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ExactlyOneOf: []string{"build_id", "script_id"},
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
},
Expand All @@ -229,12 +241,19 @@ func resourceFleetCreate(d *schema.ResourceData, meta interface{}) error {
tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{})))

input := &gamelift.CreateFleetInput{
BuildId: aws.String(d.Get("build_id").(string)),
EC2InstanceType: aws.String(d.Get("ec2_instance_type").(string)),
Name: aws.String(d.Get("name").(string)),
Tags: Tags(tags.IgnoreAWS()),
}

if v, ok := d.GetOk("build_id"); ok {
input.BuildId = aws.String(v.(string))
}

if v, ok := d.GetOk("script_id"); ok {
input.ScriptId = aws.String(v.(string))
}

if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
Expand Down Expand Up @@ -330,6 +349,8 @@ func resourceFleetRead(d *schema.ResourceData, meta interface{}) error {
d.Set("ec2_instance_type", fleet.InstanceType)
d.Set("new_game_session_protection_policy", fleet.NewGameSessionProtectionPolicy)
d.Set("operating_system", fleet.OperatingSystem)
d.Set("script_arn", fleet.ScriptArn)
d.Set("script_id", fleet.ScriptId)

if err := d.Set("certificate_configuration", flattenGameliftCertificateConfiguration(fleet.CertificateConfiguration)); err != nil {
return fmt.Errorf("error setting certificate_configuration: %w", err)
Expand Down
71 changes: 71 additions & 0 deletions internal/service/gamelift/fleet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,55 @@ func TestAccGameLiftFleet_cert(t *testing.T) {
})
}

func TestAccGameLiftFleet_script(t *testing.T) {
var conf gamelift.FleetAttributes

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resourceName := "aws_gamelift_fleet.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(t)
acctest.PreCheckPartitionHasService(gamelift.EndpointsID, t)
testAccPreCheck(t)
},
ErrorCheck: acctest.ErrorCheck(t, gamelift.EndpointsID),
Providers: acctest.Providers,
CheckDestroy: testAccCheckFleetDestroy,
Steps: []resource.TestStep{
{
Config: testAccFleetScriptConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckFleetExists(resourceName, &conf),
resource.TestCheckResourceAttrPair(resourceName, "script_id", "aws_gamelift_script.test", "id"),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "gamelift", regexp.MustCompile(`fleet/fleet-.+`)),
resource.TestCheckResourceAttr(resourceName, "certificate_configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "certificate_configuration.0.certificate_type", "DISABLED"),
resource.TestCheckResourceAttr(resourceName, "ec2_instance_type", "t2.micro"),
resource.TestCheckResourceAttr(resourceName, "log_paths.#", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "metric_groups.#", "1"),
resource.TestCheckResourceAttr(resourceName, "metric_groups.0", "default"),
resource.TestCheckResourceAttr(resourceName, "new_game_session_protection_policy", "NoProtection"),
resource.TestCheckResourceAttr(resourceName, "resource_creation_limit_policy.#", "0"),
resource.TestCheckResourceAttr(resourceName, "runtime_configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "runtime_configuration.0.server_process.#", "1"),
resource.TestCheckResourceAttr(resourceName, "runtime_configuration.0.server_process.0.concurrent_executions", "1"),
resource.TestCheckResourceAttr(resourceName, "runtime_configuration.0.server_process.0.launch_path", "/local/game/lol"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"runtime_configuration"},
},
},
})
}

func TestAccGameLiftFleet_disappears(t *testing.T) {
var conf gamelift.FleetAttributes

Expand Down Expand Up @@ -892,3 +941,25 @@ resource "aws_gamelift_fleet" "test" {
}
`, rName, launchPath, params)
}

func testAccFleetScriptConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_gamelift_script" "test" {
name = %[1]q
zip_file = "test-fixtures/script.zip"
}

resource "aws_gamelift_fleet" "test" {
script_id = aws_gamelift_script.test.id
ec2_instance_type = "t2.micro"
name = %[1]q

runtime_configuration {
server_process {
concurrent_executions = 1
launch_path = "/local/game/lol"
}
}
}
`, rName)
}
Loading