{Pulumi} VPC/GCP

 

https://www.pulumi.com/registry/packages/gcp/api-docs/compute/network/
https://www.pulumi.com/registry/packages/gcp/installation-configuration/


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

vpc01 = gcp.compute.Network("vpc01",
    auto_create_subnetworks=False,
    name="vpc01")

subnet01 = gcp.compute.Subnetwork("subnet01",
    ip_cidr_range="10.1.0.0/24",
    network="vpc01",
    name="subnet01",
    private_ip_google_access=True)

 


-- 4. pulumi 実行

 

pulumi up

※依存性を考慮してデプロイされない

 


-- 5. GCPクリーンアップ


pulumi destroy

※依存性を考慮してデプロイされない

pulumi stack rm dev --force

 


gcloud projects list

gcloud projects delete project01-9999999 \
--quiet