Skip to content

Commit 2ab2cbd

Browse files
Add game service cluster test (#3321) (#1915)
* Add game service cluster test This test relies on a GKE cluster with agones provisioned to be set up in advance. Instructions for privisioning this cluster are in the comments of game_service_cluster_basic.tf.erb Signed-off-by: Modular Magician <[email protected]>
1 parent bc63aba commit 2ab2cbd

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

.changelog/3321.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This file is automatically generated by Magic Modules and manual
8+
// changes will be clobbered when the file is regenerated.
9+
//
10+
// Please read more about how to change this file in
11+
// .github/CONTRIBUTING.md.
12+
//
13+
// ----------------------------------------------------------------------------
14+
15+
package google
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
"testing"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
23+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
24+
"github.com/hashicorp/terraform-plugin-sdk/terraform"
25+
)
26+
27+
func TestAccGameServicesGameServerCluster_gameServiceClusterBasicExample(t *testing.T) {
28+
t.Parallel()
29+
30+
context := map[string]interface{}{
31+
"agones_cluster": "bootstrapped-agones-cluster",
32+
"random_suffix": acctest.RandString(10),
33+
}
34+
35+
resource.Test(t, resource.TestCase{
36+
PreCheck: func() { testAccPreCheck(t) },
37+
Providers: testAccProvidersOiCS,
38+
CheckDestroy: testAccCheckGameServicesGameServerClusterDestroy,
39+
Steps: []resource.TestStep{
40+
{
41+
Config: testAccGameServicesGameServerCluster_gameServiceClusterBasicExample(context),
42+
},
43+
},
44+
})
45+
}
46+
47+
func testAccGameServicesGameServerCluster_gameServiceClusterBasicExample(context map[string]interface{}) string {
48+
return Nprintf(`
49+
resource "google_game_services_game_server_cluster" "default" {
50+
provider = google-beta
51+
52+
cluster_id = "%{agones_cluster}"
53+
realm_id = google_game_services_realm.default.realm_id
54+
55+
connection_info {
56+
gke_cluster_reference {
57+
cluster = "locations/us-west1/clusters/%{agones_cluster}"
58+
}
59+
namespace = "default"
60+
}
61+
}
62+
63+
resource "google_game_services_realm" "default" {
64+
provider = google-beta
65+
66+
realm_id = "realm%{random_suffix}"
67+
time_zone = "PST8PDT"
68+
69+
description = "Test Game Realm"
70+
}
71+
`, context)
72+
}
73+
74+
func testAccCheckGameServicesGameServerClusterDestroy(s *terraform.State) error {
75+
for name, rs := range s.RootModule().Resources {
76+
if rs.Type != "google_game_services_game_server_cluster" {
77+
continue
78+
}
79+
if strings.HasPrefix(name, "data.") {
80+
continue
81+
}
82+
83+
config := testAccProvider.Meta().(*Config)
84+
85+
url, err := replaceVarsForTest(config, rs, "{{GameServicesBasePath}}projects/{{project}}/locations/{{location}}/realms/{{realm_id}}/gameServerClusters/{{cluster_id}}")
86+
if err != nil {
87+
return err
88+
}
89+
90+
_, err = sendRequest(config, "GET", "", url, nil)
91+
if err == nil {
92+
return fmt.Errorf("GameServicesGameServerCluster still exists at %s", url)
93+
}
94+
}
95+
96+
return nil
97+
}

website/docs/r/game_services_game_server_cluster.html.markdown

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ To get more information about GameServerCluster, see:
3333
* How-to Guides
3434
* [Official Documentation](https://cloud.google.com/game-servers/docs)
3535

36+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
37+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=game_service_cluster_basic&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
38+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
39+
</a>
40+
</div>
41+
## Example Usage - Game Service Cluster Basic
42+
43+
44+
```hcl
45+
resource "google_game_services_game_server_cluster" "default" {
46+
provider = google-beta
47+
48+
cluster_id = ""
49+
realm_id = google_game_services_realm.default.realm_id
50+
51+
connection_info {
52+
gke_cluster_reference {
53+
cluster = "locations/us-west1/clusters/%{agones_cluster}"
54+
}
55+
namespace = "default"
56+
}
57+
}
58+
59+
resource "google_game_services_realm" "default" {
60+
provider = google-beta
61+
62+
realm_id = "realm"
63+
time_zone = "PST8PDT"
64+
65+
description = "Test Game Realm"
66+
}
67+
```
68+
3669
## Argument Reference
3770

3871
The following arguments are supported:

0 commit comments

Comments
 (0)