https://www.pulumi.com/registry/packages/gcp/api-docs/sql/databaseinstance/
Python: 3.9.13
-- 1. macにPulumiインストール
brew install pulumi/tap/pulumi
-- 2. GCPプロジェクト作成
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 auth application-default login
-- 3. Create new project
mkdir test
cd test
pulumi new gcp-python
pulumi config set gcp:project project01-9999999
pulumi config set gcp:region asia-northeast1
pulumi config set gcp:zone asia-northeast1-a
pulumi config get gcp:project
pulumi config get gcp:region
pulumi config get gcp:zone
vim __main__.py
import pulumi
import pulumi_gcp as gcp
postgres01 = gcp.sql.DatabaseInstance("postgres01",
database_version="POSTGRES_15",
deletion_protection=False,
name="postgres01",
root_password="password",
settings=gcp.sql.DatabaseInstanceSettingsArgs(
tier="db-f1-micro",
availability_type="ZONAL",
deletion_protection_enabled=False,
disk_autoresize=False,
disk_size=10,
disk_type="PD_HDD",
backup_configuration=gcp.sql.DatabaseInstanceSettingsBackupConfigurationArgs(
enabled=True,
point_in_time_recovery_enabled=True,
transaction_log_retention_days=1,
backup_retention_settings=gcp.sql.DatabaseInstanceSettingsBackupConfigurationBackupRetentionSettingsArgs(
retained_backups=1,
retention_unit="COUNT",
),
),
ip_configuration=gcp.sql.DatabaseInstanceSettingsIpConfigurationArgs(
ipv4_enabled=True,
)
)
)
-- 4. pulumi 実行
pulumi up
gcloud sql instances list
gcloud sql instances describe postgres01
gcloud sql databases list --instance=postgres01
gcloud sql connect postgres01 --user=postgres --database=postgres
-- 5. GCPクリーンアップ
pulumi destroy
pulumi stack rm dev --force
gcloud projects list
gcloud projects delete project01-9999999 \
--quiet