Deleting a deployment

This page explains how to delete a Game Servers deployment.

Before you begin

Before you start, we recommend you familiarize yourself with key concepts in the Game Servers Overview. Make sure you have also performed the following tasks:

  • Ensure that you have enabled the Game Services API.
  • Enable Game Services API
  • Either choose a shell with Cloud SDK installed, or use an API client:
  • Cloud Shell

    To launch Cloud Shell, perform the following steps:

    1. Go to Google Cloud Console.

      Google Cloud Console

    2. From the upper-right corner of the console, click the Activate Cloud Shell button:

    A Cloud Shell session opens inside a frame lower on the console. You use this shell to run gcloud commands.

    Local shell

    To install gcloud, install the Cloud SDK, which includes the gcloud command-line tool.

    Verify that you have set desired default project for gcloud command-line tool (otherwise you need to specify flag --project explicitly for each command later):

    gcloud config list project
    

    If not you can run the following command to set a default project, replacing project-id with your desired project ID :

    gcloud config set project project-id
    

    Run the following command to verify your version of the Google Cloud SDK. Game Servers requires version 306.0.0 or higher of the SDK.

    gcloud version
    

    To update your installation, run the following command:

    gcloud components update
    

    Client Library

    Google Cloud Game Servers can be controlled programmatically using a client library. See Client Libraries Overview for instructions on using the library and authenticating.

Deleting a deployment

Before you delete a Game Servers deployment, make sure you delete all configs under the deployment.

gcloud

You can delete a deployment using the gcloud command-line tool.

To delete a deployment, run the following command and replace deploymentID with the identifier for a deployment you have previously created:

gcloud game servers deployments delete deploymentID

Go

To learn how to install and use the client library for Game Servers, see the Game Servers Client Libraries.


import (
	"context"
	"fmt"
	"io"

	gaming "cloud.google.com/go/gaming/apiv1"
	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"
)

// deleteGameServerDeployment deletes a game server deployment.
func deleteGameServerDeployment(w io.Writer, projectID, deploymentID string) error {
	// projectID := "my-project"
	// deploymentID := "mydeployment"
	ctx := context.Background()
	client, err := gaming.NewGameServerDeploymentsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerDeploymentsClient: %v", err)
	}
	defer client.Close()

	req := &gamingpb.DeleteGameServerDeploymentRequest{
		Name: fmt.Sprintf("projects/%s/locations/global/gameServerDeployments/%s", projectID, deploymentID),
	}

	op, err := client.DeleteGameServerDeployment(ctx, req)
	if err != nil {
		return fmt.Errorf("DeleteGameServerDeployment: %v", err)
	}
	err = op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %v", err)
	}

	fmt.Fprintf(w, "Deployment deleted.")
	return nil
}

Java

To learn how to install and use the client library for Game Servers, see the Game Servers Client Libraries.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient;
import com.google.cloud.gaming.v1.OperationMetadata;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class DeleteDeployment {
  public static void deleteGameServerDeployment(String projectId, String deploymentId)
      throws InterruptedException, ExecutionException, TimeoutException, IOException {
    // String projectId = "your-project-id";
    // String deploymentId = "your-game-server-deployment-id";
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.create()) {
      String parent = String.format("projects/%s/locations/global", projectId);
      String deploymentName = String.format("%s/gameServerDeployments/%s", parent, deploymentId);

      OperationFuture<Empty, OperationMetadata> call =
          client.deleteGameServerDeploymentAsync(deploymentName);
      call.get(1, TimeUnit.MINUTES);
      System.out.println("Game Server Deployment deleted: " + deploymentName);
    }
  }
}

Node.js

To learn how to install and use the client library for Game Servers, see the Game Servers Client Libraries.

const {
  GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function deleteGameServerDeployment() {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'Your Google Cloud Project ID';
  // const deploymentId = 'A unique ID for the Game Server Deployment';
  const request = {
    // The full resource name
    name: client.gameServerDeploymentPath(projectId, 'global', deploymentId),
  };

  const [operation] = await client.deleteGameServerDeployment(request);
  await operation.promise();

  console.log(`Deployment with name ${request.name} deleted.`);
}

deleteGameServerDeployment();

Python

To learn how to install and use the client library for Game Servers, see the Game Servers Client Libraries.

def delete_deployment(project_id, deployment_id):
    """Deletes a game server deployment."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    request = game_server_deployments.DeleteGameServerDeploymentRequest(
        name=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}",
    )

    operation = client.delete_game_server_deployment(request)
    print(f"Delete deployment operation: {operation.operation.name}")
    operation.result(timeout=120)

Verifying that your deployment has been deleted

To verify that you successfully deleted the deployment, list your deployments using the gcloud command-line tool.

To list all deployments, run the following command:

gcloud game servers deployments list

Your deleted deployment no longer appears in the output of the command.

What's next

Learn how to Game Servers audit logging information.