Create a parameter
Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to create a parameter. A parameter acts as a dynamic variable for your application, holding key configuration values like database connection strings, feature flags, or service endpoints.
Parameters can store various types of data, including:
- Structured data like YAML or JSON for organized, machine-readable information.
- Unstructured data such as plain text or binary content.
You can create both global and regional parameters in Parameter Manager.
The following table explains the key differences between the global and regional parameters.
| Feature | Global parameters | Regional parameters |
|---|---|---|
| Storage | Stored centrally | Stored within a specific location |
| Access | Standard API endpoint | Regional endpoint corresponding to the location of the parameter |
| Use cases |
Parameters that apply to your application or service regardless of where the application or service is running:
|
Parameters that vary based on the location where your application is deployed:
|
Before you begin
If you haven't already, then set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs.
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
Required roles
To get the permissions that
you need to create a parameter,
ask your administrator to grant you the
Parameter Manager Admin (roles/parametermanager.admin) IAM role on the project, folder, or organization.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Create a parameter to store structured data
To create a parameter for storing structured data, use one of the following methods:
Global parameters
Console
-
In the Google Cloud console, go to the Secret Manager page.
-
Click Parameter Manager to go to the Parameter Manager page, and then click Create parameter.
-
In the Create parameter page, enter the parameter name.
-
To specify the format in which the parameter stores data, select either YAML or JSON in the Parameter format section.
-
To create a global parameter, select Multi-region in the Location section, and then select global (Global) from the Region list.
-
Optional: To add a label to your parameter resource, click Add label, and then define the label key and value.
-
Click Create.
gcloud
Before using any of the command data below, make the following replacements:
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
- FORMAT: the data type or format of the parameter's value, such as
YAMLorJSON.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloudparametermanagerparameterscreatePARAMETER_ID--location=global--parameter-format=FORMAT
Windows (PowerShell)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=global--parameter-format=FORMAT
Windows (cmd.exe)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=global--parameter-format=FORMAT
You should receive a response similar to the following:
Created parameter [app_config].
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID: the Google Cloud project ID.
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
HTTP method and URL:
POST https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters?parameter_id=PARAMETER_ID
Request JSON body:
{"format": "YAML"}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters?parameter_id=PARAMETER_ID"
PowerShell
Save the request body in a file named request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters?parameter_id=PARAMETER_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{
"name": "projects/production-1/locations/global/parameters/app_config",
"createTime": "2024-10-15T08:39:05.191747694Z",
"updateTime": "2024-10-15T08:39:05.191747694Z",
"format": "YAML",
"policyMember": {
"iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/global/parameters/c86ca5bc-f4c2-439d-b62c-d578b4b78b12"
}
}
C#
To run this code, first set up a C# development environment and install the Parameter Manager C# SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
usingGoogle.Api.Gax.ResourceNames ;
usingGoogle.Cloud.ParameterManager.V1 ;
publicclassCreateStructuredParameterSample
{
/// <summary>
/// This function creates a parameter of the specified format type using the Parameter Manager SDK for GCP.
/// </summary>
/// <param name="projectId">The ID of the project where the parameter is to be created.</param>
/// <param name="parameterId">The ID to assign to the new parameter. This ID must be unique within the project.</param>
/// <param name="format">The format type of the parameter (UNFORMATTED, YAML, JSON).</param>
/// <returns>The created Parameter object.</returns>
publicParameterCreateStructuredParameter(
stringprojectId,
stringparameterId,
ParameterFormat format)
{
// Create the client.
ParameterManagerClient client=ParameterManagerClient .Create ();
// Build the parent resource name.
LocationName parent=newLocationName (projectId,"global");
// Build the parameter with the specified format.
Parameterparameter=newParameter
{
Format=format
};
// Call the API to create the parameter.
ParametercreatedParameter=client.CreateParameter (parent,parameter,parameterId);
// Print the created parameter name.
Console.WriteLine($"Created parameter {createdParameter.Name} with format {createdParameter.Format}");
// Return the created parameter.
returncreatedParameter;
}
}Go
To run this code, first set up a Go development environment and install the Parameter Manager Go SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
import(
"context"
"fmt"
"io"
parametermanager"cloud.google.com/go/parametermanager/apiv1"
parametermanagerpb"cloud.google.com/go/parametermanager/apiv1/parametermanagerpb"
)
// createStructuredParam creates a new parameter with the specified format in Parameter Manager.
//
// w: The io.Writer object used to write the output.
// projectID: The ID of the project where the parameter is located.
// parameterID: The ID of the parameter to be created.
// format: The format type of the parameter (UNFORMATTED, YAML, JSON).
//
// The function returns an error if the parameter creation fails.
funccreateStructuredParam(wio.Writer,projectID,parameterIDstring,formatparametermanagerpb.ParameterFormat)error{
// Create a context and a Parameter Manager client.
ctx:=context.Background()
client,err:=parametermanager.NewClient (ctx)
iferr!=nil{
returnfmt.Errorf("failed to create Parameter Manager client: %w",err)
}
deferclient.Close ()
// Construct the name of the create parameter.
parent:=fmt.Sprintf("projects/%s/locations/global",projectID)
// Build the request to create a new parameter with the specified format.
req:=¶metermanagerpb.CreateParameterRequest{
Parent:parent,
ParameterId:parameterID,
Parameter:¶metermanagerpb.Parameter{
Format:format,
},
}
// Call the API to create the parameter.
parameter,err:=client.CreateParameter(ctx,req)
iferr!=nil{
returnfmt.Errorf("failed to create parameter: %w",err)
}
fmt.Fprintf(w,"Created parameter %s with format %s\n",parameter.Name,parameter.Format.String())
returnnil
}
Java
To run this code, first set up a Java development environment and install the Parameter Manager Java SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
importcom.google.cloud.parametermanager.v1.LocationName ;
importcom.google.cloud.parametermanager.v1.Parameter ;
importcom.google.cloud.parametermanager.v1.ParameterFormat ;
importcom.google.cloud.parametermanager.v1.ParameterManagerClient ;
importjava.io.IOException;
/**
* Example class to create a new parameter with a specific format using the Parameter Manager SDK
* for GCP.
*/
publicclass CreateStructuredParam{
publicstaticvoidmain(String[]args)throwsIOException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="your-project-id";
StringparameterId="your-parameter-id";
ParameterFormat format=ParameterFormat .YAML;
// Call the method to create a parameter with the specified format.
createStructuredParameter(projectId,parameterId,format);
}
// This is an example snippet for creating a new parameter with a specific format.
publicstaticParameter createStructuredParameter(
StringprojectId,StringparameterId,ParameterFormat format)throwsIOException{
// Initialize the client that will be used to send requests.
try(ParameterManagerClient client=ParameterManagerClient .create()){
StringlocationId="global";
// Build the parent name from the project.
LocationName location=LocationName .of(projectId,locationId);
// Build the parameter to create with the provided format.
Parameter parameter=Parameter .newBuilder().setFormat (format).build();
// Create the parameter.
Parameter createdParameter=
client.createParameter(location.toString (),parameter,parameterId);
System.out.printf(
"Created parameter %s with format %s\n",
createdParameter.getName (),createdParameter.getFormat ());
returncreatedParameter;
}
}
}Node.js
To run this code, first set up a Node.js development environment and install the Parameter Manager Node.js SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const {protos} = require('@google-cloud/parametermanager');
// const projectId = 'YOUR_PROJECT_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
// const formatType = protos.google.cloud.parametermanager.v1.ParameterFormat.JSON;
// Imports the Parameter Manager library
const{ParameterManagerClient}=require('@google-cloud/parametermanager');
// Instantiates a client
constclient=newParameterManagerClient ();
asyncfunctioncreateStructuredParam(){
constparent=client.locationPath (projectId,'global');
constrequest={
parent:parent,
parameterId:parameterId,
parameter:{
format:formatType,
},
};
const[parameter]=awaitclient.createParameter(request);
console.log(
`Created parameter ${parameter.name} with format ${parameter.format}`
);
returnparameter;
}
returnawaitcreateStructuredParam();PHP
To run this code, first learn about using PHP on Google Cloud and install the Parameter Manager PHP SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
// Import necessary classes for creating a parameter.
use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient;
use Google\Cloud\ParameterManager\V1\CreateParameterRequest;
use Google\Cloud\ParameterManager\V1\Parameter;
use Google\Cloud\ParameterManager\V1\ParameterFormat;
/**
* Creates a parameter with the specified format.
*
* @param string $projectId The Google Cloud Project ID (e.g. 'my-project')
* @param string $parameterId The Parameter ID (e.g. 'my-param')
* @param string $format The format type of the parameter (UNFORMATTED, YAML, JSON)
*/
function create_structured_param(string $projectId, string $parameterId, string $format): void
{
// Create a client for the Parameter Manager service.
$client = new ParameterManagerClient();
// Build the resource name of the parent object.
$parent = $client->locationName($projectId, 'global');
// Create a new Parameter object and set the format.
$parameter = (new Parameter())
->setFormat(ParameterFormat::value($format));
// Prepare the request with the parent, parameter ID, and the parameter object.
$request = (new CreateParameterRequest())
->setParent($parent)
->setParameterId($parameterId)
->setParameter($parameter);
// Call the API and handle any network failures with print statements.
$newParameter = $client->createParameter($request);
printf('Created parameter %s with format %s' . PHP_EOL, $newParameter->getName(), ParameterFormat::name($newParameter->getFormat()));
}Python
To run this code, first set up a Python development environment and install the Parameter Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
defcreate_structured_param(
project_id: str, parameter_id: str, format_type: parametermanager_v1 .ParameterFormat
) -> parametermanager_v1.Parameter:
"""
Creates a parameter in the global location of the specified
project with specified format using the Google Cloud Parameter Manager SDK.
Args:
project_id (str): The ID of the project where
the parameter is to be created.
parameter_id (str): The ID to assign to the new parameter.
This ID must be unique within the project.
format_type (parametermanager_v1.ParameterFormat): The format type of
the parameter (UNFORMATTED, YAML, JSON).
Returns:
parametermanager_v1.Parameter: An object representing the
newly created parameter.
Example:
create_structured_param(
"my-project",
"my-global-parameter",
parametermanager_v1.ParameterFormat.JSON
)
"""
# Import the necessary library for Google Cloud Parameter Manager.
fromgoogle.cloudimport parametermanager_v1
# Create the Parameter Manager client.
client = parametermanager_v1 .ParameterManagerClient ()
# Build the resource name of the parent project in the global location.
parent = client.common_location_path (project_id, "global")
# Define the parameter creation request with the specified format.
request = parametermanager_v1 .CreateParameterRequest (
parent=parent,
parameter_id=parameter_id,
parameter=parametermanager_v1 .Parameter (format_=format_type),
)
# Create the parameter.
response = client.create_parameter (request=request)
# Print the newly created parameter name.
print(f"Created parameter {response.name} with format {response.format_.name}")Ruby
To run this code, first set up a Ruby development environment and install the Parameter Manager Ruby SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
require"google/cloud/parameter_manager"
##
# Create a parameter
#
# @param project_id [String] The Google Cloud project (e.g. "my-project")
# @param parameter_id [String] The parameter name (e.g. "my-parameter")
# @param format [Google::Cloud::ParameterManager::V1::ParameterFormat::]
# The type of parameter format (UNFORMATTED, YAML, JSON)
#
defcreate_structured_paramproject_id:,parameter_id:,format:
# Create a Parameter Manager client.
client=Google::Cloud::ParameterManager .parameter_manager
# Build the resource name of the parent project.
parent=client.location_path project:project_id,location:"global"
parameter={
format:format
}
# Create the parameter.
param=client.create_parameterparent:parent,parameter_id:parameter_id,parameter:parameter
# Print the new parameter name.
puts"Created parameter #{param.name} with format #{param.format }"
endRegional parameters
Console
-
In the Google Cloud console, go to the Secret Manager page.
-
Click Parameter Manager to go to the Parameter Manager page, and then click Create parameter.
-
In the Create parameter page, enter the parameter name.
-
To specify the format in which the parameter stores data, select either YAML or JSON in the Parameter format section.
-
To create a regional parameter, select Region in the Location section, and then select the location from the Region list.
-
Optional: To add a label to your parameter resource, click Add label, and then define the label key and value.
-
Click Create.
gcloud
Before using any of the command data below, make the following replacements:
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
- LOCATION: the Google Cloud location of the parameter.
- FORMAT: the data type or format of the parameter's value, such as
YAMLorJSON.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloudparametermanagerparameterscreatePARAMETER_ID--location=LOCATION--parameter-format=FORMAT
Windows (PowerShell)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=LOCATION--parameter-format=FORMAT
Windows (cmd.exe)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=LOCATION--parameter-format=FORMAT
You should receive a response similar to the following:
Created parameter [app_config].
REST
Before using any of the request data, make the following replacements:
- LOCATION: the Google Cloud location of the parameter.
- PROJECT_ID: the Google Cloud project ID.
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
HTTP method and URL:
POST https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters?parameter_id=PARAMETER_ID
Request JSON body:
{"format": "YAML"}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters?parameter_id=PARAMETER_ID"
PowerShell
Save the request body in a file named request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters?parameter_id=PARAMETER_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{
"name": "projects/production-1/locations/us-central1/parameters/app_config",
"createTime": "2024-10-30T05:27:28.934719122Z",
"updateTime": "2024-10-30T05:27:28.934719122Z",
"format": "YAML",
"policyMember": {
"iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/463050620945/uid/locations/us-central1/parameters/6ffe4045-0778-490a-a786-d77b124e2613"
}
}
C#
To run this code, first set up a C# development environment and install the Parameter Manager C# SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
usingGoogle.Api.Gax.ResourceNames ;
usingGoogle.Cloud.ParameterManager.V1 ;
publicclassCreateStructuredRegionalParameterSample
{
/// <summary>
/// This function creates a regional parameter of the specified format type using the Parameter Manager SDK for GCP.
/// </summary>
/// <param name="projectId">The ID of the project where the parameter is to be created.</param>
/// <param name="locationId">The region where the parameter is to be created.</param>
/// <param name="parameterId">The ID to assign to the new parameter. This ID must be unique within the project.</param>
/// <param name="format">The format type of the parameter (UNFORMATTED, YAML, JSON).</param>
/// <returns>The created Parameter object.</returns>
publicParameterCreateStructuredRegionalParameter(
stringprojectId,
stringlocationId,
stringparameterId,
ParameterFormat format)
{
// Define the regional endpoint
stringregionalEndpoint=$"parametermanager.{locationId}.rep.googleapis.com";
// Create the client with the regional endpoint
ParameterManagerClient client=newParameterManagerClientBuilder
{
Endpoint=regionalEndpoint
}.Build ();
// Build the parent resource name for the regional locationId
LocationName parent=newLocationName (projectId,locationId);
// Build the parameter with the specified format
Parameterparameter=newParameter
{
Format=format
};
// Call the API to create the parameter
ParametercreatedParameter=client.CreateParameter (parent,parameter,parameterId);
// Print the created parameter name
Console.WriteLine($"Created regional parameter {createdParameter.Name} with format {createdParameter.Format}");
// Return the created parameter
returncreatedParameter;
}
}Go
To run this code, first set up a Go development environment and install the Parameter Manager Go SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
import(
"context"
"fmt"
"io"
parametermanager"cloud.google.com/go/parametermanager/apiv1"
parametermanagerpb"cloud.google.com/go/parametermanager/apiv1/parametermanagerpb"
"google.golang.org/api/option"
)
// createStructuredRegionalParam creates a parameter regional of the format type given as a method argument using the Parameter Manager SDK for GCP.
//
// w: The io.Writer object used to write the output.
// projectID: The ID of the project where the parameter is located.
// locationID: The region where the parameter is to be created.
// parameterID: The ID of the parameter to be created.
// format: The format type of the parameter (UNFORMATTED, YAML, JSON).
//
// The function returns an error if the parameter creation fails.
funccreateStructuredRegionalParam(wio.Writer,projectID,locationID,parameterIDstring,formatparametermanagerpb.ParameterFormat)error{
// Create a context and a Parameter Manager client.
ctx:=context.Background()
// Create a Parameter Manager client.
endpoint:=fmt.Sprintf("parametermanager.%s.rep.googleapis.com:443",locationID)
client,err:=parametermanager.NewClient (ctx,option.WithEndpoint(endpoint))
iferr!=nil{
returnfmt.Errorf("failed to create Parameter Manager client: %w",err)
}
deferclient.Close ()
// Construct the name of the create parameter.
parent:=fmt.Sprintf("projects/%s/locations/%s",projectID,locationID)
// Create a parameter with the given format.
req:=¶metermanagerpb.CreateParameterRequest{
Parent:parent,
ParameterId:parameterID,
Parameter:¶metermanagerpb.Parameter{
Format:format,
},
}
parameter,err:=client.CreateParameter(ctx,req)
iferr!=nil{
returnfmt.Errorf("failed to create parameter: %w",err)
}
fmt.Fprintf(w,"Created regional parameter %s with format %s\n",parameter.Name,parameter.Format.String())
returnnil
}
Java
To run this code, first set up a Java development environment and install the Parameter Manager Java SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
importcom.google.cloud.parametermanager.v1.LocationName ;
importcom.google.cloud.parametermanager.v1.Parameter ;
importcom.google.cloud.parametermanager.v1.ParameterFormat ;
importcom.google.cloud.parametermanager.v1.ParameterManagerClient ;
importcom.google.cloud.parametermanager.v1.ParameterManagerSettings ;
importjava.io.IOException;
/**
* Example class to create a new regional parameter with a specific format using the Parameter
* Manager SDK for GCP.
*/
publicclass CreateStructuredRegionalParam{
publicstaticvoidmain(String[]args)throwsIOException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="your-project-id";
StringlocationId="your-location-id";
StringparameterId="your-parameter-id";
ParameterFormat format=ParameterFormat .JSON;
// Call the method to create a regional parameter with the specified format.
createStructuredRegionalParam(projectId,locationId,parameterId,format);
}
// This is an example snippet that creates a regional parameter with a specific format.
publicstaticParameter createStructuredRegionalParam(
StringprojectId,StringlocationId,StringparameterId,ParameterFormat format)
throwsIOException{
// Endpoint to call the regional parameter manager server
StringapiEndpoint=String.format("parametermanager.%s.rep.googleapis.com:443",locationId);
ParameterManagerSettings parameterManagerSettings=
ParameterManagerSettings .newBuilder().setEndpoint(apiEndpoint).build();
// Initialize the client that will be used to send requests. This client only needs to be
// created once, and can be reused for multiple requests.
try(ParameterManagerClient client=ParameterManagerClient .create(parameterManagerSettings)){
// Build the parent name from the project.
LocationName location=LocationName .of(projectId,locationId);
// Build the regional parameter to create with the provided format.
Parameter parameter=Parameter .newBuilder().setFormat (format).build();
// Create the regional parameter.
Parameter createdParameter=
client.createParameter(location.toString (),parameter,parameterId);
System.out.printf(
"Created regional parameter %s with format %s\n",
createdParameter.getName (),createdParameter.getFormat ());
returncreatedParameter;
}
}
}Node.js
To run this code, first set up a Node.js development environment and install the Parameter Manager Node.js SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const {protos} = require('@google-cloud/parametermanager');
// const projectId = 'YOUR_PROJECT_ID';
// const locationId = 'YOUR_LOCATION_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
// const formatType = protos.google.cloud.parametermanager.v1.ParameterFormat.JSON;
// Imports the Parameter Manager library
const{ParameterManagerClient}=require('@google-cloud/parametermanager');
// Adding the endpoint to call the regional parameter manager server
constoptions={
apiEndpoint:`parametermanager.${locationId}.rep.googleapis.com`,
};
// Instantiates a client with regional endpoint
constclient=newParameterManagerClient (options);
asyncfunctioncreateStructuredRegionalParam(){
constparent=client.locationPath (projectId,locationId);
constrequest={
parent:parent,
parameterId:parameterId,
parameter:{
format:formatType,
},
};
const[parameter]=awaitclient.createParameter(request);
console.log(
`Created regional parameter ${parameter.name} with format ${parameter.format}`
);
returnparameter;
}
returnawaitcreateStructuredRegionalParam();PHP
To run this code, first learn about using PHP on Google Cloud and install the Parameter Manager PHP SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
// Import necessary classes for creating a parameter.
use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient;
use Google\Cloud\ParameterManager\V1\CreateParameterRequest;
use Google\Cloud\ParameterManager\V1\Parameter;
use Google\Cloud\ParameterManager\V1\ParameterFormat;
/**
* Creates a regional parameter with the specified format.
*
* @param string $projectId The Google Cloud Project ID (e.g. 'my-project')
* @param string $locationId The Parameter Location (e.g. 'us-central1')
* @param string $parameterId The Parameter ID (e.g. 'my-param')
* @param string $format The format type of the parameter (UNFORMATTED, YAML, JSON).
*/
function create_structured_regional_param(string $projectId, string $locationId, string $parameterId, string $format): void
{
// Specify regional endpoint.
$options = ['apiEndpoint' => "parametermanager.$locationId.rep.googleapis.com"];
// Create a client for the Parameter Manager service.
$client = new ParameterManagerClient($options);
// Build the resource name of the parent object.
$parent = $client->locationName($projectId, $locationId);
// Create a new Parameter object and set the format.
$parameter = (new Parameter())
->setFormat(ParameterFormat::value($format));
// Prepare the request with the parent, parameter ID, and the parameter object.
$request = (new CreateParameterRequest())
->setParent($parent)
->setParameterId($parameterId)
->setParameter($parameter);
// Call the API and handle any network failures with print statements.
$newParameter = $client->createParameter($request);
printf('Created regional parameter %s with format %s' . PHP_EOL, $newParameter->getName(), ParameterFormat::name($newParameter->getFormat()));
}Python
To run this code, first set up a Python development environment and install the Parameter Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
#!/usr/bin/env python
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
"""
command line application and sample code
for creating a new formatted regional parameter.
"""
fromgoogle.cloudimport parametermanager_v1
defcreate_structured_regional_param(
project_id: str,
location_id: str,
parameter_id: str,
format_type: parametermanager_v1 .ParameterFormat ,
) -> parametermanager_v1.Parameter:
"""
Creates a parameter in the specified region of the specified
project using the Google Cloud Parameter Manager SDK. The parameter is
created with the specified format type.
Args:
project_id (str): The ID of the project where
the parameter is to be created.
location_id (str): The ID of the region where
the parameter is to be created.
parameter_id (str): The ID to assign to the new parameter.
This ID must be unique within the project.
format_type (parametermanager_v1.ParameterFormat): The format type of
the parameter (UNFORMATTED, YAML, JSON).
Returns:
parametermanager_v1.Parameter: An object representing the
newly created parameter.
Example:
create_structured_regional_param(
"my-project",
"my-regional-parameter",
"us-central1",
parametermanager_v1.ParameterFormat.JSON
)
"""
# Import the necessary library for Google Cloud Parameter Manager.
fromgoogle.cloudimport parametermanager_v1
# Create the Parameter Manager client with the regional endpoint.
api_endpoint = f"parametermanager.{location_id}.rep.googleapis.com"
client = parametermanager_v1 .ParameterManagerClient (
client_options={"api_endpoint": api_endpoint}
)
# Build the resource name of the parent project in the specified region.
parent = client.common_location_path (project_id, location_id)
# Define the parameter creation request with the specified format.
request = parametermanager_v1 .CreateParameterRequest (
parent=parent,
parameter_id=parameter_id,
parameter=parametermanager_v1 .Parameter (format_=format_type),
)
# Create the parameter.
response = client.create_parameter (request=request)
# Print the newly created parameter name.
print(
f"Created regional parameter: {response.name} "
f"with format {response.format_.name}"
)
return response
Ruby
To run this code, first set up a Ruby development environment and install the Parameter Manager Ruby SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
require"google/cloud/parameter_manager"
##
# Create a regional parameter
#
# @param project_id [String] The Google Cloud project (e.g. "my-project")
# @param location_id [String] The location name (e.g. "us-central1")
# @param parameter_id [String] The parameter name (e.g. "my-parameter")
# @param format [Google::Cloud::ParameterManager::V1::ParameterFormat::]
# The type of parameter format (UNFORMATTED, YAML, JSON)
#
defcreate_structured_regional_paramproject_id:,location_id:,parameter_id:,format:
# Endpoint for the regional parameter manager service.
api_endpoint="parametermanager.#{location_id}.rep.googleapis.com"
# Create the Parameter Manager client.
client=Google::Cloud::ParameterManager .parameter_manager do|config|
config.endpoint=api_endpoint
end
# Build the resource name of the parent project.
parent=client.location_path project:project_id,location:location_id
parameter={
format:format
}
# Create the parameter.
param=client.create_parameterparent:parent,parameter_id:parameter_id,parameter:parameter
# Print the new parameter name.
puts"Created regional parameter #{param.name} with format #{param.format }"
endCreate a parameter to store unstructured data
To create a parameter for storing unstructured data, use one of the following methods:
Global parameters
Console
-
In the Google Cloud console, go to the Secret Manager page.
-
Click Parameter Manager to go to the Parameter Manager page, and then click Create parameter.
-
In the Create parameter page, enter the parameter name.
-
To create a parameter that stores unformatted data, select Unformatted in the Parameter format section.
-
To create a global parameter, select Multi-region in the Location section, and then select global (Global) from the Region list.
-
Optional: To add a label to your parameter resource, click Add label, and then define the label key and value.
-
Click Create.
gcloud
Before using any of the command data below, make the following replacements:
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloudparametermanagerparameterscreatePARAMETER_ID--location=global--parameter-format=UNFORMATTED
Windows (PowerShell)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=global--parameter-format=UNFORMATTED
Windows (cmd.exe)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=global--parameter-format=UNFORMATTED
You should receive a response similar to the following:
Created parameter [allowed_ip_ranges].
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID: the Google Cloud project ID.
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
HTTP method and URL:
POST https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters?parameter_id=PARAMETER_ID
Request JSON body:
{"format": "UNFORMATTED"}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters?parameter_id=PARAMETER_ID"
PowerShell
Save the request body in a file named request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.googleapis.com/v1/projects/PROJECT_ID/locations/global/parameters?parameter_id=PARAMETER_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{
"name": "projects/production-1/locations/global/parameters/allowed_ip_ranges",
"createTime": "2024-10-15T08:31:53.250487112Z",
"updateTime": "2024-10-15T08:31:53.250487112Z",
"format": "UNFORMATTED",
"policyMember": {
"iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/567445493557/uid/locations/global/parameters/c0100d79-7c8d-4da3-8eb6-fe2a35843d9b"
}
}
C#
To run this code, first set up a C# development environment and install the Parameter Manager C# SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
usingGoogle.Api.Gax.ResourceNames ;
usingGoogle.Cloud.ParameterManager.V1 ;
publicclassCreateParameterSample
{
/// <summary>
/// This function creates a parameter of the format type "unformatted" using the Parameter Manager SDK for GCP.
/// </summary>
/// <param name="projectId">The ID of the project where the parameter is to be created.</param>
/// <param name="parameterId">The ID to assign to the new parameter. This ID must be unique within the project.</param>
/// <returns>The created Parameter object.</returns>
publicParameterCreateParameter(
stringprojectId,
stringparameterId)
{
// Create the client.
ParameterManagerClient client=ParameterManagerClient .Create ();
// Build the parent resource name.
LocationName parent=newLocationName (projectId,"global");
// Build the parameter.
Parameterparameter=newParameter();
// Call the API to create the parameter.
ParametercreatedParameter=client.CreateParameter (parent,parameter,parameterId);
// Print the created parameter name.
Console.WriteLine($"Created parameter: {createdParameter.Name}");
// Return the created parameter.
returncreatedParameter;
}
}Go
To run this code, first set up a Go development environment and install the Parameter Manager Go SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
import(
"context"
"fmt"
"io"
parametermanager"cloud.google.com/go/parametermanager/apiv1"
parametermanagerpb"cloud.google.com/go/parametermanager/apiv1/parametermanagerpb"
)
// createParam creates a new parameter with the format type "unformatted" in Parameter Manager.
//
// w: The io.Writer object used to write the output.
// projectID: The ID of the project where the parameter is located.
// parameterID: The ID of the parameter to be created.
//
// The function returns an error if the parameter creation fails.
funccreateParam(wio.Writer,projectID,parameterIDstring)error{
// Create a context and a Parameter Manager client.
ctx:=context.Background()
client,err:=parametermanager.NewClient (ctx)
iferr!=nil{
returnfmt.Errorf("failed to create Parameter Manager client: %w",err)
}
deferclient.Close ()
// Construct the name of the create parameter.
parent:=fmt.Sprintf("projects/%s/locations/global",projectID)
// Build the request to create a new parameter
req:=¶metermanagerpb.CreateParameterRequest{
Parent:parent,
ParameterId:parameterID,
Parameter:¶metermanagerpb.Parameter{},
}
// Call the API to create the parameter.
parameter,err:=client.CreateParameter(ctx,req)
iferr!=nil{
returnfmt.Errorf("failed to create parameter: %w",err)
}
fmt.Fprintf(w,"Created parameter: %s\n",parameter.Name)
returnnil
}
Java
To run this code, first set up a Java development environment and install the Parameter Manager Java SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
importcom.google.cloud.parametermanager.v1.LocationName ;
importcom.google.cloud.parametermanager.v1.Parameter ;
importcom.google.cloud.parametermanager.v1.ParameterManagerClient ;
importjava.io.IOException;
/** This class demonstrates how to create a parameter using the Parameter Manager SDK for GCP. */
publicclass CreateParam{
publicstaticvoidmain(String[]args)throwsIOException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="your-project-id";
StringparameterId="your-parameter-id";
// Call the method to create parameter.
createParam(projectId,parameterId);
}
// This is an example snippet for creating a new parameter.
publicstaticParameter createParam(StringprojectId,StringparameterId)throwsIOException{
// Initialize the client that will be used to send requests. This client only
// needs to be created once, and can be reused for multiple requests.
try(ParameterManagerClient client=ParameterManagerClient .create()){
StringlocationId="global";
// Build the parent name from the project.
LocationName location=LocationName .of(projectId,locationId);
// Build the parameter to create.
Parameter parameter=Parameter .newBuilder().build();
// Create the parameter.
Parameter createdParameter=
client.createParameter(location.toString (),parameter,parameterId);
System.out.printf("Created parameter: %s\n",createdParameter.getName ());
returncreatedParameter;
}
}
}Node.js
To run this code, first set up a Node.js development environment and install the Parameter Manager Node.js SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
// Imports the Parameter Manager library
const{ParameterManagerClient}=require('@google-cloud/parametermanager');
// Instantiates a client
constclient=newParameterManagerClient ();
asyncfunctioncreateParam(){
constparent=client.locationPath (projectId,'global');
constrequest={
parent:parent,
parameterId:parameterId,
};
const[parameter]=awaitclient.createParameter(request);
console.log(`Created parameter: ${parameter.name}`);
returnparameter;
}
returnawaitcreateParam();PHP
To run this code, first learn about using PHP on Google Cloud and install the Parameter Manager PHP SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
// Import necessary classes for creating a parameter.
use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient;
use Google\Cloud\ParameterManager\V1\CreateParameterRequest;
use Google\Cloud\ParameterManager\V1\Parameter;
/**
* Creates a parameter of type "unformatted" using the Parameter Manager SDK for GCP.
*
* @param string $projectId The Google Cloud Project ID (e.g. 'my-project')
* @param string $parameterId The Parameter ID (e.g. 'my-param')
*/
function create_param(string $projectId, string $parameterId): void
{
// Create a client for the Parameter Manager service.
$client = new ParameterManagerClient();
// Build the resource name of the parent object.
$parent = $client->locationName($projectId, 'global');
// Create a new Parameter object.
$parameter = new Parameter();
// Prepare the request with the parent, parameter ID, and the parameter object.
$request = (new CreateParameterRequest())
->setParent($parent)
->setParameterId($parameterId)
->setParameter($parameter);
// Crete the parameter.
$newParameter = $client->createParameter($request);
// Print the new parameter name
printf('Created parameter: %s' . PHP_EOL, $newParameter->getName());
}Python
To run this code, first set up a Python development environment and install the Parameter Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
defcreate_param(project_id: str, parameter_id: str) -> parametermanager_v1.Parameter:
"""
Creates a parameter with default format (Unformatted)
in the global location of the specified
project using the Google Cloud Parameter Manager SDK.
Args:
project_id (str): The ID of the project where
the parameter is to be created.
parameter_id (str): The ID to assign to the new parameter.
This ID must be unique within the project.
Returns:
parametermanager_v1.Parameter: An object representing
the newly created parameter.
Example:
create_param(
"my-project",
"my-global-parameter"
)
"""
# Import the necessary library for Google Cloud Parameter Manager.
fromgoogle.cloudimport parametermanager_v1
# Create the Parameter Manager client.
client = parametermanager_v1.ParameterManagerClient()
# Build the resource name of the parent project in the global location.
parent = client.common_location_path(project_id, "global")
# Define the parameter creation request.
request = parametermanager_v1.CreateParameterRequest(
parent=parent,
parameter_id=parameter_id,
)
# Create the parameter.
response = client.create_parameter(request=request)
# Print the newly created parameter name.
print(f"Created parameter: {response.name}")Ruby
To run this code, first set up a Ruby development environment and install the Parameter Manager Ruby SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
require"google/cloud/parameter_manager"
##
# Create a parameter
#
# @param project_id [String] The Google Cloud project (e.g. "my-project")
# @param parameter_id [String] The parameter name (e.g. "my-parameter")
#
defcreate_paramproject_id:,parameter_id:
# Create a Parameter Manager client.
client=Google::Cloud::ParameterManager .parameter_manager
# Build the resource name of the parent project.
parent=client.location_path project:project_id,location:"global"
# Create the parameter.
param=client.create_parameterparent:parent,parameter_id:parameter_id
# Print the new parameter name.
puts"Created parameter #{param.name}"
endRegional parameters
Console
-
In the Google Cloud console, go to the Secret Manager page.
-
Click Parameter Manager to go to the Parameter Manager page, and then click Create parameter.
-
In the Create parameter page, enter the parameter name.
-
To create a parameter that stores unformatted data, select Unformatted in the Parameter format section.
-
To create a regional parameter, select Region in the Location section, and then select the location from the Region list.
-
Optional: To add a label to your parameter resource, click Add label, and then define the label key and value.
-
Click Create.
gcloud
Before using any of the command data below, make the following replacements:
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
- LOCATION: the Google Cloud location of the parameter.
Execute the following command:
Linux, macOS, or Cloud Shell
gcloudparametermanagerparameterscreatePARAMETER_ID--location=LOCATION--parameter-format=UNFORMATTED
Windows (PowerShell)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=LOCATION--parameter-format=UNFORMATTED
Windows (cmd.exe)
gcloudparametermanagerparameterscreatePARAMETER_ID--location=LOCATION--parameter-format=UNFORMATTED
You should receive a response similar to the following:
Created parameter [allowed_ip_ranges].
REST
Before using any of the request data, make the following replacements:
- LOCATION: the Google Cloud location of the parameter.
- PROJECT_ID: the Google Cloud project ID.
- PARAMETER_ID: the name of the new parameter. Parameter names must be 63 characters or less and consist only of English letters (A-Z, a-z), numbers (0-9), dashes (-), and underscores (_). Names can't begin with a dash.
HTTP method and URL:
POST https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters?parameter_id=PARAMETER_ID
Request JSON body:
{"format": "UNFORMATTED"}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters?parameter_id=PARAMETER_ID"
PowerShell
Save the request body in a file named request.json,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://parametermanager.LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/parameters?parameter_id=PARAMETER_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{
"name": "projects/production-1/locations/europe-west1/parameters/allowed_ip_ranges",
"createTime": "2024-11-08T08:33:05.255559134Z",
"updateTime": "2024-11-08T08:33:05.255559134Z",
"format": "UNFORMATTED",
"policyMember": {
"iamPolicyUidPrincipal": "principal://parametermanager.googleapis.com/projects/609765466568/uid/locations/europe-west1/parameters/a7787f0d-b033-4f7e-aec0-e8ca4d0b1476"
}
}
C#
To run this code, first set up a C# development environment and install the Parameter Manager C# SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
usingGoogle.Api.Gax.ResourceNames ;
usingGoogle.Cloud.ParameterManager.V1 ;
publicclassCreateRegionalParameterSample
{
/// <summary>
/// This function creates a regional parameter using the Parameter Manager SDK for GCP.
/// </summary>
/// <param name="projectId">The ID of the project where the parameter is to be created.</param>
/// <param name="locationId">The region where the parameter is to be created.</param>
/// <param name="parameterId">The ID to assign to the new parameter. This ID must be unique within the project.</param>
/// <returns>The created Parameter object.</returns>
publicParameterCreateRegionalParameter(
stringprojectId,
stringlocationId,
stringparameterId)
{
// Define the regional endpoint
stringregionalEndpoint=$"parametermanager.{locationId}.rep.googleapis.com";
// Create the client with the regional endpoint
ParameterManagerClient client=newParameterManagerClientBuilder
{
Endpoint=regionalEndpoint
}.Build ();
// Build the parent resource name for the regional locationId
LocationName parent=newLocationName (projectId,locationId);
// Build the parameter
Parameterparameter=newParameter();
// Call the API to create the parameter
ParametercreatedParameter=client.CreateParameter (parent,parameter,parameterId);
// Print the created parameter name
Console.WriteLine($"Created regional parameter: {createdParameter.Name}");
// Return the created parameter
returncreatedParameter;
}
}Go
To run this code, first set up a Go development environment and install the Parameter Manager Go SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
import(
"context"
"fmt"
"io"
parametermanager"cloud.google.com/go/parametermanager/apiv1"
parametermanagerpb"cloud.google.com/go/parametermanager/apiv1/parametermanagerpb"
"google.golang.org/api/option"
)
// createRegionalParam creates a parameter regional of the format type "unformatted" using the Parameter Manager SDK for GCP.
//
// w: The io.Writer object used to write the output.
// projectID: The ID of the project where the parameter is located.
// locationID: The region where the parameter is to be created.
// parameterID: The ID of the parameter to be created.
//
// The function returns an error if the parameter creation fails.
funccreateRegionalParam(wio.Writer,projectID,locationID,parameterIDstring)error{
// Create a context and a Parameter Manager client.
ctx:=context.Background()
// Create a Parameter Manager client.
endpoint:=fmt.Sprintf("parametermanager.%s.rep.googleapis.com:443",locationID)
client,err:=parametermanager.NewClient (ctx,option.WithEndpoint(endpoint))
iferr!=nil{
returnfmt.Errorf("failed to create Parameter Manager client: %w",err)
}
deferclient.Close ()
// Construct the name of the create parameter.
parent:=fmt.Sprintf("projects/%s/locations/%s",projectID,locationID)
// Create a parameter with unformatted format.
req:=¶metermanagerpb.CreateParameterRequest{
Parent:parent,
ParameterId:parameterID,
Parameter:¶metermanagerpb.Parameter{
Format:parametermanagerpb.ParameterFormat_UNFORMATTED ,
},
}
parameter,err:=client.CreateParameter(ctx,req)
iferr!=nil{
returnfmt.Errorf("failed to create parameter: %w",err)
}
fmt.Fprintf(w,"Created regional parameter: %s\n",parameter.Name)
returnnil
}
Java
To run this code, first set up a Java development environment and install the Parameter Manager Java SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
importcom.google.cloud.parametermanager.v1.LocationName ;
importcom.google.cloud.parametermanager.v1.Parameter ;
importcom.google.cloud.parametermanager.v1.ParameterManagerClient ;
importcom.google.cloud.parametermanager.v1.ParameterManagerSettings ;
importjava.io.IOException;
/**
* This class demonstrates how to create a regional parameter using the Parameter Manager SDK for
* GCP.
*/
publicclass CreateRegionalParam{
publicstaticvoidmain(String[]args)throwsIOException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="your-project-id";
StringlocationId="your-location-id";
StringparameterId="your-parameter-id";
createRegionalParam(projectId,locationId,parameterId);
}
// This is an example snippet for creating a new regional parameter.
publicstaticParameter createRegionalParam(
StringprojectId,StringlocationId,StringparameterId)throwsIOException{
// Endpoint to call the regional parameter manager server
StringapiEndpoint=String.format("parametermanager.%s.rep.googleapis.com:443",locationId);
ParameterManagerSettings parameterManagerSettings=
ParameterManagerSettings .newBuilder().setEndpoint(apiEndpoint).build();
// Initialize the client that will be used to send requests. This client only needs to be
// created once, and can be reused for multiple requests.
try(ParameterManagerClient client=ParameterManagerClient .create(parameterManagerSettings)){
// Build the parent name from the project.
LocationName location=LocationName .of(projectId,locationId);
// Build the regional parameter to create.
Parameter parameter=Parameter .newBuilder().build();
// Create the regional parameter.
Parameter createdParameter=
client.createParameter(location.toString (),parameter,parameterId);
System.out.printf("Created regional parameter: %s\n",createdParameter.getName ());
returncreatedParameter;
}
}
}Node.js
To run this code, first set up a Node.js development environment and install the Parameter Manager Node.js SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const locationId = 'YOUR_LOCATION_ID';
// const parameterId = 'YOUR_PARAMETER_ID';
// Imports the Parameter Manager library
const{ParameterManagerClient}=require('@google-cloud/parametermanager');
// Adding the endpoint to call the regional parameter manager server
constoptions={
apiEndpoint:`parametermanager.${locationId}.rep.googleapis.com`,
};
// Instantiates a client with regional endpoint
constclient=newParameterManagerClient (options);
asyncfunctioncreateRegionalParam(){
constparent=client.locationPath (projectId,locationId);
constrequest={
parent:parent,
parameterId:parameterId,
};
const[parameter]=awaitclient.createParameter(request);
console.log(`Created regional parameter: ${parameter.name}`);
returnparameter;
}
returnawaitcreateRegionalParam();PHP
To run this code, first learn about using PHP on Google Cloud and install the Parameter Manager PHP SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
// Import necessary classes for creating a parameter.
use Google\Cloud\ParameterManager\V1\Client\ParameterManagerClient;
use Google\Cloud\ParameterManager\V1\CreateParameterRequest;
use Google\Cloud\ParameterManager\V1\Parameter;
/**
* Creates a regional parameter of type "unformatted" using the Parameter Manager SDK for GCP.
*
* @param string $projectId The Google Cloud Project ID (e.g. 'my-project')
* @param string $locationId The Parameter Location (e.g. 'us-central1')
* @param string $parameterId The Parameter ID (e.g. 'my-param')
*/
function create_regional_param(string $projectId, string $locationId, string $parameterId): void
{
// Specify regional endpoint.
$options = ['apiEndpoint' => "parametermanager.$locationId.rep.googleapis.com"];
// Create a client for the Parameter Manager service.
$client = new ParameterManagerClient($options);
// Build the resource name of the parent object.
$parent = $client->locationName($projectId, $locationId);
// Create a new Parameter object.
$parameter = new Parameter();
// Prepare the request with the parent, parameter ID, and the parameter object.
$request = (new CreateParameterRequest())
->setParent($parent)
->setParameterId($parameterId)
->setParameter($parameter);
// Crete the parameter.
$newParameter = $client->createParameter($request);
// Print the new parameter name
printf('Created regional parameter: %s' . PHP_EOL, $newParameter->getName());
}Python
To run this code, first set up a Python development environment and install the Parameter Manager Python SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
defcreate_regional_param(
project_id: str, location_id: str, parameter_id: str
) -> parametermanager_v1.Parameter:
"""
Creates a regional parameter with default format (Unformatted)
in the specified location and
project using the Google Cloud Parameter Manager SDK.
Args:
project_id (str): The ID of the project where
the parameter is to be created.
location_id (str): The region where the parameter is to be created.
parameter_id (str): The ID to assign to the new parameter.
This ID must be unique within the project.
Returns:
parametermanager_v1.Parameter: An object representing
the newly created parameter.
Example:
create_regional_param(
"my-project",
"us-central1",
"my-regional-parameter"
)
"""
# Import the Parameter Manager client library.
fromgoogle.cloudimport parametermanager_v1
api_endpoint = f"parametermanager.{location_id}.rep.googleapis.com"
# Create the Parameter Manager client for the specified region.
client = parametermanager_v1 .ParameterManagerClient (
client_options={"api_endpoint": api_endpoint}
)
# Build the resource name of the parent project for the specified region.
parent = client.common_location_path (project_id, location_id)
# Define the parameter creation request.
request = parametermanager_v1 .CreateParameterRequest (
parent=parent,
parameter_id=parameter_id,
)
# Create the parameter.
response = client.create_parameter (request=request)
# Print the newly created parameter name.
print(f"Created regional parameter: {response.name}")Ruby
To run this code, first set up a Ruby development environment and install the Parameter Manager Ruby SDK. On Compute Engine or GKE, you must authenticate with the cloud-platform scope.
require"google/cloud/parameter_manager"
##
# Create a regional parameter
#
# @param project_id [String] The Google Cloud project (e.g. "my-project")
# @param location_id [String] The location name (e.g. "us-central1")
# @param parameter_id [String] The parameter name (e.g. "my-parameter")
#
defcreate_regional_paramproject_id:,location_id:,parameter_id:
# Endpoint for the regional parameter manager service.
api_endpoint="parametermanager.#{location_id}.rep.googleapis.com"
# Create the Parameter Manager client.
client=Google::Cloud::ParameterManager .parameter_manager do|config|
config.endpoint=api_endpoint
end
# Build the resource name of the parent project.
parent=client.location_path project:project_id,location:location_id
# Create the parameter.
param=client.create_parameterparent:parent,parameter_id:parameter_id
# Print the new parameter name.
puts"Created regional parameter #{param.name}"
endBuilt-in identities for parameters
Parameters are resource types with built-in identities.
This means that each parameter has a unique identifier that distinguishes it from all
other resources in your Google Cloud project. This unique identifier is automatically
generated when you create a parameter and stored in the iamPolicyUidPrincipal field
of the parameter resource.
You can grant roles to the parameter by including the resource's principal identifier in your allow policies when you want the parameter to access Secret Manager resources. For more information, see Built-in identities for resources.