{GCP Secret Manager}Secret Manager でシークレットを作成する

 

https://cloud.google.com/secret-manager/docs/create-secret?hl=ja

https://zenn.dev/nananaoto/articles/43e3414fdb1da37b377e


-- 1. 前作業

gcloud init
gcloud auth list

gcloud --version

gcloud projects create project01-9999999 \
--name="project01"

gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-northeast1 --quiet
gcloud config set compute/zone asia-northeast1-a --quiet

gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111

gcloud services enable compute.googleapis.com --project project01-9999999

gcloud components update

 

-- 2. Secret Manager API有効化

gcloud services list --enabled

gcloud services enable secretmanager.googleapis.com


-- 3. シークレットの作成

gcloud secrets create secret01 \
--replication-policy="automatic"

gcloud secrets list
gcloud secrets describe secret01

-- 4. シークレット バージョンの追加

echo "test" | gcloud secrets versions add secret01 --data-file=-

gcloud secrets versions list secret01

-- 5. シークレット バージョンへのアクセス

gcloud secrets versions access 1 --secret="secret01"
gcloud secrets versions access latest --secret="secret01"


-- 6. クリーンアップ

gcloud secrets versions disable 1 --secret="secret01"
gcloud secrets versions destroy 1 --secret="secret01"

gcloud secrets delete secret01

 

gcloud projects list
gcloud projects delete project01-9999999