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

Adding support for v1 game servers. #6983

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/3790.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:new-resource
`gameservices: Added new resource `google_game_services_realm`
`gameservices: Added new resource `google_game_services_game_server_cluster`
`gameservices: Added new resource `google_game_services_game_server_config`
`gameservices: Added new resource `google_game_services_game_server_deployment`
`gameservices: Added new resource `google_game_services_game_server_deployment_rollout`
```
3 changes: 3 additions & 0 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type Config struct {
DNSBasePath string
FilestoreBasePath string
FirestoreBasePath string
GameServicesBasePath string
HealthcareBasePath string
IapBasePath string
IdentityPlatformBasePath string
Expand Down Expand Up @@ -248,6 +249,7 @@ var DialogflowDefaultBasePath = "https://dialogflow.googleapis.com/v2/"
var DNSDefaultBasePath = "https://www.googleapis.com/dns/v1/"
var FilestoreDefaultBasePath = "https://file.googleapis.com/v1/"
var FirestoreDefaultBasePath = "https://firestore.googleapis.com/v1/"
var GameServicesDefaultBasePath = "https://gameservices.googleapis.com/v1/"
var HealthcareDefaultBasePath = "https://healthcare.googleapis.com/v1/"
var IapDefaultBasePath = "https://iap.googleapis.com/v1/"
var IdentityPlatformDefaultBasePath = "https://identitytoolkit.googleapis.com/v2/"
Expand Down Expand Up @@ -793,6 +795,7 @@ func ConfigureBasePaths(c *Config) {
c.DNSBasePath = DNSDefaultBasePath
c.FilestoreBasePath = FilestoreDefaultBasePath
c.FirestoreBasePath = FirestoreDefaultBasePath
c.GameServicesBasePath = GameServicesDefaultBasePath
c.HealthcareBasePath = HealthcareDefaultBasePath
c.IapBasePath = IapDefaultBasePath
c.IdentityPlatformBasePath = IdentityPlatformDefaultBasePath
Expand Down
30 changes: 30 additions & 0 deletions google/data_google_game_services_game_server_deployment_rollout.go
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
package google

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

func dataSourceGameServicesGameServerDeploymentRollout() *schema.Resource {

dsSchema := datasourceSchemaFromResourceSchema(resourceGameServicesGameServerDeploymentRollout().Schema)
addRequiredFieldsToSchema(dsSchema, "deployment_id")

return &schema.Resource{
Read: dataSourceGameServicesGameServerDeploymentRolloutRead,
Schema: dsSchema,
}
}

func dataSourceGameServicesGameServerDeploymentRolloutRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

id, err := replaceVars(d, config, "projects/{{project}}/locations/global/gameServerDeployments/{{deployment_id}}/rollout")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return resourceGameServicesGameServerDeploymentRolloutRead(d, meta)

}
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
package google

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceGameServicesGameServerDeploymentRollout_basic(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckGameServicesGameServerDeploymentRolloutDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGameServicesGameServerDeploymentRollout_basic(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_game_services_game_server_deployment_rollout.qa", "google_game_services_game_server_deployment_rollout.foo"),
),
},
},
})
}

func testAccDataSourceGameServicesGameServerDeploymentRollout_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_game_services_game_server_deployment" "default" {
deployment_id = "tf-test-deployment-%{random_suffix}"
description = "a deployment description"
}

resource "google_game_services_game_server_config" "default" {
config_id = "tf-test-config-%{random_suffix}"
deployment_id = google_game_services_game_server_deployment.default.deployment_id
description = "a config description"

fleet_configs {
name = "some-non-guid"
fleet_spec = jsonencode({ "replicas" : 1, "scheduling" : "Packed", "template" : { "metadata" : { "name" : "tf-test-game-server-template" }, "spec" : { "template" : { "spec" : { "containers" : [{ "name" : "simple-udp-server", "image" : "gcr.io/agones-images/udp-server:0.14" }] } } } } })

// Alternate usage:
// fleet_spec = file(fleet_configs.json)
}
}

resource "google_game_services_game_server_deployment_rollout" "foo" {
deployment_id = google_game_services_game_server_deployment.default.deployment_id
default_game_server_config = google_game_services_game_server_config.default.name
}

data "google_game_services_game_server_deployment_rollout" "qa" {
deployment_id = google_game_services_game_server_deployment_rollout.foo.deployment_id
}
`, context)
}
72 changes: 72 additions & 0 deletions google/game_services_operation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------
package google

import (
"encoding/json"
"fmt"
"time"
)

type GameServicesOperationWaiter struct {
Config *Config
Project string
CommonOperationWaiter
}

func (w *GameServicesOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("https://gameservices.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", w.Project, url, nil)
}

func createGameServicesWaiter(config *Config, op map[string]interface{}, project, activity string) (*GameServicesOperationWaiter, error) {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil, nil
}
w := &GameServicesOperationWaiter{
Config: config,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func gameServicesOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeout time.Duration) error {
w, err := createGameServicesWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func gameServicesOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeout time.Duration) error {
w, err := createGameServicesWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeout, config.PollInterval)
}