https://www.pulumi.com/registry/packages/azure-native/api-docs/network/virtualnetwork/
https://www.pulumi.com/docs/clouds/azure/get-started/
Python: 3.9.13
-- 1. macにPulumiインストール
brew install pulumi/tap/pulumi
-- 2. Azureログイン
az login --use-device-code
az account show
az version
az configure --list-defaults
az configure --defaults location=japaneast
az configure --list-defaults
az group list
az upgrade
-- 3. Create new project
mkdir test
cd test
pulumi new azure-python
Japan East
japaneast
↑locationはどちらの表記でもOK
az account list-locations --output table
pulumi config get azure-native:location
pulumi config set azure-native:location japaneast
pulumi config get azure-native:location
vim __main__.py
import pulumi
import pulumi_azure_native as azure_native
rg9999999 = azure_native.resources.ResourceGroup("rg9999999",
resource_group_name="rg9999999")
vnet01 = azure_native.network.VirtualNetwork("vnet01",
address_space=azure_native.network.AddressSpaceArgs(
address_prefixes=["10.2.0.0/16"],
),
resource_group_name="rg9999999",
subnets=[azure_native.network.SubnetArgs(
address_prefix="10.2.1.0/24",
name="subnet01",
)],
virtual_network_name="vnet01")
nsg01 = azure_native.network.NetworkSecurityGroup("nsg01",
network_security_group_name="nsg01",
resource_group_name="rg9999999",
security_rules=[azure_native.network.SecurityRuleArgs(
access="Allow",
destination_address_prefix="*",
destination_port_range="22",
direction="Inbound",
name="nsgr01",
priority=100,
protocol="Tcp",
source_address_prefix="*",
source_port_range="*",
)] )
pip01 = azure_native.network.PublicIPAddress("pip01",
public_ip_address_version="IPv4",
public_ip_allocation_method="Static",
public_ip_address_name="pip01",
resource_group_name="rg9999999",
sku=azure_native.network.PublicIPAddressSkuArgs(
name="Standard",
tier="Regional",
) )
-- 4. pulumi 実行
pulumi up
※依存性を考慮せずに作成している模様。エラーが出たら再実行
az group list
az network vnet list
az network vnet subnet list \
--resource-group rg9999999 \
--vnet-name vnet01
az network nsg list \
--resource-group rg9999999
az network nsg rule list \
--nsg-name nsg01 \
--resource-group rg9999999
az network public-ip list
-- 5. Azureクリーンアップ
pulumi destroy
※一部削除がエラーとなる。依存性を考慮せずに削除している模様。
pulumi stack rm dev
※エラーになってPulumi側でリソースが残る場合、下記を実行
pulumi stack rm dev --force
az group delete \
--name NetworkWatcherRG \
--yes