Deleting a realm

This page explains how to delete a Game Servers realm.

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 realm

gcloud

You can delete a global or regional realm using the gcloud command-line tool.

To delete a global realm, run the following command and replace realmID with the identifier for a realm you have previously created:

gcloud game servers realms delete realmID

To delete a regional realm, run the following command and replace the placeholder values, such as realmID, with appropriate values:

gcloud game servers realms delete realmID --location=region

The variable placeholders correspond to the following descriptions:

  • realmID is the unique identifier for a realm.
  • region is the region for the realm, if it exists.

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"
)

// deleteRealm deletes a game server realm.
func deleteRealm(w io.Writer, projectID, location, realmID string) error {
	// projectID := "my-project"
	// location := "global"
	// realmID := "myrealm"
	ctx := context.Background()
	client, err := gaming.NewRealmsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewRealmsClient: %v", err)
	}
	defer client.Close()

	req := &gamingpb.DeleteRealmRequest{
		Name: fmt.Sprintf("projects/%s/locations/%s/realms/%s", projectID, location, realmID),
	}

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

	fmt.Fprintf(w, "Realm 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.OperationMetadata;
import com.google.cloud.gaming.v1.RealmsServiceClient;
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 DeleteRealm {
  public static void deleteRealm(String projectId, String regionId, String realmId)
      throws InterruptedException, ExecutionException, TimeoutException, IOException {
    // String projectId = "your-project-id";
    // String regionId = "us-central1-f";
    // String realmId = "your-realm-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 (RealmsServiceClient client = RealmsServiceClient.create()) {
      String parent = String.format("projects/%s/locations/%s", projectId, regionId);
      String realmName = String.format("%s/realms/%s", parent, realmId);

      OperationFuture<Empty, OperationMetadata> call = client.deleteRealmAsync(realmName);

      call.get(1, TimeUnit.MINUTES);
      System.out.println("Realm deleted: " + realmName);
    }
  }
}

Node.js

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

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

const client = new RealmsServiceClient();

async function deleteRealm() {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'Your Google Cloud Project ID';
  // const location = 'A Compute Engine region, e.g. "us-central1"';
  // const realmId = 'Unique identifier of the realm';
  const request = {
    // Realm name is the full resource name including project ID,location,
    // and the realm ID.
    name: client.realmPath(projectId, location, realmId),
  };

  const [operation] = await client.deleteRealm(request);
  await operation.promise();
  console.log(`Realm with ID ${realmId} deleted.`);
}

deleteRealm();

Python

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

def delete_realm(project_id, location, realm_id):
    """Deletes a realm."""

    client = gaming.RealmsServiceClient()

    request = realms.DeleteRealmRequest(
        name=f"projects/{project_id}/locations/{location}/realms/{realm_id}",
    )

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

Verifying that your realm has been deleted

To verify that you successfully deleted the realm, list your global or regional realms using the gcloud command-line tool.

To list all global realms, run the following command:

gcloud game servers realms list

To list realms in a region, run the following command and replace region with the region you want to list:

gcloud game servers realms list --location=region

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

What's next

Learn about audit logging.