LinuxCommandLibrary

gcloud-config

Manage gcloud SDK configurations

TLDR

Define a property (like compute/zone) for the current configuration

$ gcloud config set [property] [value]
copy

Fetch the value of a gcloud property
$ gcloud config get [property]
copy

Display all the properties for the current configuration
$ gcloud config list
copy

Create a new configuration with a given name
$ gcloud config configurations create [configuration_name]
copy

Display a list of all available configurations
$ gcloud config configurations list
copy

Switch to an existing configuration with a given name
$ gcloud config configurations activate [configuration_name]
copy

SYNOPSIS

gcloud config <subcommand> [<arguments>...] [<flags>...]

PARAMETERS

set <PROPERTY_NAME> <VALUE>
    Sets a specified SDK property to a given value. Common properties include project, account, compute/zone, and compute/region.

get <PROPERTY_NAME>
    Retrieves the value of a specified SDK property from the active configuration or global settings.

list [--all]
    Lists all active SDK properties. The --all flag shows properties from all possible levels (user, active configuration, environment variables, etc.).

unset <PROPERTY_NAME>
    Removes a specified SDK property from the active configuration.

configurations activate <CONFIG_NAME>
    Activates a named configuration, making its properties the current active settings for the SDK.

configurations create <CONFIG_NAME>
    Creates a new, empty named configuration. This configuration can then be populated with properties using gcloud config set.

configurations delete <CONFIG_NAME>
    Deletes a specified named configuration. The currently active configuration cannot be deleted directly.

configurations describe <CONFIG_NAME>
    Displays the properties associated with a specific named configuration.

configurations list
    Lists all available named configurations configured with the SDK.

DESCRIPTION

The gcloud config command group is central to managing the Google Cloud SDK's behavior. It allows users to control various SDK properties, such as the active Google Cloud project, default compute zone, and user account. These properties dictate how subsequent gcloud commands interact with Google Cloud services.

Beyond individual properties, gcloud config also facilitates the creation and management of named configurations. A configuration is a distinct set of properties that can be activated to quickly switch contexts, for instance, between development and production environments, or between different Google Cloud projects. This feature is crucial for users working with multiple projects or needing different settings for various tasks, streamlining workflow and reducing errors.

Properties can be set at different levels, including globally for the SDK, specific to an active configuration, or overridden by environment variables and command-line flags, providing a flexible hierarchy for managing SDK settings.

CAVEATS

Properties set via gcloud config apply to the current active configuration or global settings. Environment variables (e.g., CLOUDSDK_CORE_PROJECT) and command-line flags (e.g., --project) generally take precedence over properties set through gcloud config.

Ensure that the Google Cloud SDK is properly initialized (using gcloud init) for optimal functionality.

PROPERTY PRECEDENCE

The Google Cloud SDK resolves property values based on a specific order of precedence, from highest to lowest:
1. Command-line flags (e.g., --project)
2. Environment variables (e.g., CLOUDSDK_CORE_PROJECT)
3. Properties in the active configuration
4. Properties in the global configuration
Understanding this hierarchy is crucial for debugging unexpected behavior.

USE CASES FOR MULTIPLE CONFIGURATIONS

Multiple configurations are invaluable for managing different operational contexts:
Switching Projects: Easily switch between development, staging, and production projects without re-authenticating or re-setting project IDs.
Managing Multiple Accounts: Use different Google accounts for distinct tasks or projects.
Regional Deployments: Define configurations for different default compute regions or zones.

HISTORY

The gcloud config command group is an integral part of the Google Cloud SDK, which has evolved significantly since its inception. It provides a consistent interface for managing SDK settings, adapting to the growing complexity and features of Google Cloud Platform. Its development has focused on simplifying multi-project and multi-environment workflows for developers and administrators.

SEE ALSO

gcloud(1), gcloud auth(1), gcloud init(1), gcloud projects(1), gcloud components(1)

Copied to clipboard