Issue
I'm working with the Python library google-cloud-secret-manager and I'm facing some problems in creating a secret within a defined region.
In the method secretmanager.create_secret seems that there is a metadata parameter that can be filled but I keep receiving errors trying something like:
metadata=[{'region': 'europe-west1'}]
The library code below for me is not very clear on these parameters...
This is the original snippet I'm trying to execute:
response = secret_client.create_secret(
request={
"parent": parent,
"secret_id": secret_id,
"secret": {"replication": {"automatic": {}}},
}
)
Can someone help me?
Thanks in advance!!
EDIT
Following the full code, taken from the official documentation, where it is not specified how to specify the region...
def create_secret(project_id, secret_id):
"""
Create a new secret with the given name. A secret is a logical wrapper
around a collection of secret versions. Secret versions hold the actual
secret material.
"""
# Import the Secret Manager client library.
from google.cloud import secretmanager
# Create the Secret Manager client.
client = secretmanager.SecretManagerServiceClient()
# Build the resource name of the parent project.
parent = f"projects/{project_id}"
# Create the secret.
response = client.create_secret(
request={
"parent": parent,
"secret_id": secret_id,
"secret": {"replication": {"automatic": {}}},
}
)
# Print the new secret name.
print("Created secret: {}".format(response.name))
Solution
If you want to specify the replication key placement manually, you need to specify it like in the example below:
response = client.create_secret(
request={
"parent": parent,
"secret_id": secret_id,
"secret": {"user_managed": {
"replicas": [
{"location": "europe-west1"}
]}
},
}
)
Answered By - Giorgio C
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.