Loading...
Loading...
Compare original and translation side by side
pulumi previewpulumi previewpulumi previewpulumi previewaz resource listaz resource showaz loginpulumi env run {org}/{project}/{environment} -- bash -c 'az login --service-principal -u "$ARM_CLIENT_ID" --tenant "$ARM_TENANT_ID" --federated-token "$ARM_OIDC_TOKEN"'az account showaz account list --query "[].{Name:name, SubscriptionId:id, IsDefault:isDefault}" -o tablepulumi-escaz resource listaz resource showaz loginpulumi env run {org}/{project}/{environment} -- bash -c 'az login --service-principal -u "$ARM_CLIENT_ID" --tenant "$ARM_TENANT_ID" --federated-token "$ARM_OIDC_TOKEN"'az account showaz account list --query "[].{Name:name, SubscriptionId:id, IsDefault:isDefault}" -o tablepulumi-escundefinedundefined
Extract:
- Resource types and names
- Parameters and their default values
- Variables and expressions
- Dependencies (dependsOn arrays)
- Nested templates or linked templates
- Copy loops (iteration constructs)
- Conditional deployments (condition property)
**Documentation:** [ARM Template Structure](https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/syntax)
提取以下信息:
- 资源类型和名称
- 参数及其默认值
- 变量和表达式
- 依赖关系(dependsOn数组)
- 嵌套模板或链接模板
- 复制循环(迭代结构)
- 条件部署(condition属性)
**文档:** [ARM模板结构](https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/syntax)undefinedundefined
**Documentation:** [Azure CLI Documentation](https://learn.microsoft.com/en-us/cli/azure/)
**文档:** [Azure CLI文档](https://learn.microsoft.com/en-us/cli/azure/)@pulumi/azure-native@pulumi/azure@pulumi/azure-native@pulumi/azure{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2023-01-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}import * as pulumi from "@pulumi/pulumi";
import * as azure_native from "@pulumi/azure-native";
const config = new pulumi.Config();
const storageAccountName = config.require("storageAccountName");
const location = config.require("location");
const resourceGroupName = config.require("resourceGroupName");
const storageAccount = new azure_native.storage.StorageAccount("storageAccount", {
accountName: storageAccountName,
location: location,
resourceGroupName: resourceGroupName,
sku: {
name: azure_native.storage.SkuName.Standard_LRS,
},
kind: azure_native.storage.Kind.StorageV2,
enableHttpsTrafficOnly: true,
});{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2023-01-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {
"supportsHttpsTrafficOnly": true
}
}import * as pulumi from "@pulumi/pulumi";
import * as azure_native from "@pulumi/azure-native";
const config = new pulumi.Config();
const storageAccountName = config.require("storageAccountName");
const location = config.require("location");
const resourceGroupName = config.require("resourceGroupName");
const storageAccount = new azure_native.storage.StorageAccount("storageAccount", {
accountName: storageAccountName,
location: location,
resourceGroupName: resourceGroupName,
sku: {
name: azure_native.storage.SkuName.Standard_LRS,
},
kind: azure_native.storage.Kind.StorageV2,
enableHttpsTrafficOnly: true,
});{
"parameters": {
"location": {
"type": "string",
"defaultValue": "eastus",
"metadata": {
"description": "Location for resources"
}
},
"instanceCount": {
"type": "int",
"defaultValue": 2,
"minValue": 1,
"maxValue": 10
},
"enableBackup": {
"type": "bool",
"defaultValue": true
},
"secretValue": {
"type": "securestring"
}
}
}const config = new pulumi.Config();
const location = config.get("location") || "eastus";
const instanceCount = config.getNumber("instanceCount") || 2;
const enableBackup = config.getBoolean("enableBackup") ?? true;
const secretValue = config.requireSecret("secretValue"); // Returns Output<string>{
"parameters": {
"location": {
"type": "string",
"defaultValue": "eastus",
"metadata": {
"description": "Location for resources"
}
},
"instanceCount": {
"type": "int",
"defaultValue": 2,
"minValue": 1,
"maxValue": 10
},
"enableBackup": {
"type": "bool",
"defaultValue": true
},
"secretValue": {
"type": "securestring"
}
}
}const config = new pulumi.Config();
const location = config.get("location") || "eastus";
const instanceCount = config.getNumber("instanceCount") || 2;
const enableBackup = config.getBoolean("enableBackup") ?? true;
const secretValue = config.requireSecret("secretValue"); // 返回Output<string>{
"variables": {
"storageAccountName": "[concat('storage', uniqueString(resourceGroup().id))]",
"webAppName": "[concat(parameters('prefix'), '-webapp')]"
}
}import * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
const prefix = config.require("prefix");
const resourceGroupId = config.require("resourceGroupId");
// Simple variable
const webAppName = `${prefix}-webapp`;
// For uniqueString equivalent, use stack name or generate hash
const storageAccountName = `storage${resourceGroupId}`.toLowerCase();{
"variables": {
"storageAccountName": "[concat('storage', uniqueString(resourceGroup().id))]",
"webAppName": "[concat(parameters('prefix'), '-webapp')]"
}
}import * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
const prefix = config.require("prefix");
const resourceGroupId = config.require("resourceGroupId");
// 简单变量
const webAppName = `${prefix}-webapp`;
// 替代uniqueString,使用栈名称或生成哈希
const storageAccountName = `storage${resourceGroupId}`.toLowerCase();{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2023-05-01",
"name": "[concat(variables('vnetName'), '/subnet-', copyIndex())]",
"copy": {
"name": "subnetCopy",
"count": "[parameters('subnetCount')]"
},
"properties": {
"addressPrefix": "[concat('10.0.', copyIndex(), '.0/24')]"
}
}const config = new pulumi.Config();
const subnetCount = config.getNumber("subnetCount") || 3;
const subnets: azure_native.network.Subnet[] = [];
for (let i = 0; i < subnetCount; i++) {
subnets.push(new azure_native.network.Subnet(`subnet-${i}`, {
subnetName: `subnet-${i}`,
virtualNetworkName: vnet.name,
resourceGroupName: resourceGroup.name,
addressPrefix: `10.0.${i}.0/24`,
}));
}{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2023-05-01",
"name": "[concat(variables('vnetName'), '/subnet-', copyIndex())]",
"copy": {
"name": "subnetCopy",
"count": "[parameters('subnetCount')]"
},
"properties": {
"addressPrefix": "[concat('10.0.', copyIndex(), '.0/24')]"
}
}const config = new pulumi.Config();
const subnetCount = config.getNumber("subnetCount") || 3;
const subnets: azure_native.network.Subnet[] = [];
for (let i = 0; i < subnetCount; i++) {
subnets.push(new azure_native.network.Subnet(`subnet-${i}`, {
subnetName: `subnet-${i}`,
virtualNetworkName: vnet.name,
resourceGroupName: resourceGroup.name,
addressPrefix: `10.0.${i}.0/24`,
}));
}{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2023-05-01",
"condition": "[parameters('createPublicIP')]",
"name": "[variables('publicIPName')]",
"location": "[parameters('location')]"
}const config = new pulumi.Config();
const createPublicIP = config.getBoolean("createPublicIP") ?? false;
let publicIP: azure_native.network.PublicIPAddress | undefined;
if (createPublicIP) {
publicIP = new azure_native.network.PublicIPAddress("publicIP", {
publicIpAddressName: publicIPName,
location: location,
resourceGroupName: resourceGroup.name,
});
}
// Handle optional references
const publicIPId = publicIP ? publicIP.id : pulumi.output(undefined);{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2023-05-01",
"condition": "[parameters('createPublicIP')]",
"name": "[variables('publicIPName')]",
"location": "[parameters('location')]"
}const config = new pulumi.Config();
const createPublicIP = config.getBoolean("createPublicIP") ?? false;
let publicIP: azure_native.network.PublicIPAddress | undefined;
if (createPublicIP) {
publicIP = new azure_native.network.PublicIPAddress("publicIP", {
publicIpAddressName: publicIPName,
location: location,
resourceGroupName: resourceGroup.name,
});
}
// 处理可选引用
const publicIPId = publicIP ? publicIP.id : pulumi.output(undefined);{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[variables('webAppName')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
]
}// Implicit dependency (preferred)
const webApp = new azure_native.web.WebApp("webApp", {
name: webAppName,
resourceGroupName: resourceGroup.name,
serverFarmId: appServicePlan.id, // Implicit dependency through property reference
});
// Explicit dependency (when needed)
const webApp = new azure_native.web.WebApp("webApp", {
name: webAppName,
resourceGroupName: resourceGroup.name,
serverFarmId: appServicePlan.id,
}, {
dependsOn: [appServicePlan], // Explicit dependency
});{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[variables('webAppName')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
]
}// 隐式依赖(推荐)
const webApp = new azure_native.web.WebApp("webApp", {
name: webAppName,
resourceGroupName: resourceGroup.name,
serverFarmId: appServicePlan.id, // 通过属性引用实现隐式依赖
});
// 显式依赖(必要时使用)
const webApp = new azure_native.web.WebApp("webApp", {
name: webAppName,
resourceGroupName: resourceGroup.name,
serverFarmId: appServicePlan.id,
}, {
dependsOn: [appServicePlan], // 显式依赖
});{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "nestedTemplate",
"properties": {
"mode": "Incremental",
"template": {
"resources": [...]
}
}
}class NetworkComponent extends pulumi.ComponentResource {
public readonly vnet: azure_native.network.VirtualNetwork;
public readonly subnets: azure_native.network.Subnet[];
constructor(name: string, args: NetworkComponentArgs, opts?: pulumi.ComponentResourceOptions) {
super("custom:azure:NetworkComponent", name, {}, opts);
const defaultOptions = { parent: this };
this.vnet = new azure_native.network.VirtualNetwork(`${name}-vnet`, {
virtualNetworkName: args.vnetName,
resourceGroupName: args.resourceGroupName,
location: args.location,
addressSpace: {
addressPrefixes: [args.addressPrefix],
},
}, defaultOptions);
this.subnets = args.subnets.map((subnet, i) =>
new azure_native.network.Subnet(`${name}-subnet-${i}`, {
subnetName: subnet.name,
virtualNetworkName: this.vnet.name,
resourceGroupName: args.resourceGroupName,
addressPrefix: subnet.addressPrefix,
}, defaultOptions)
);
this.registerOutputs({
vnetId: this.vnet.id,
subnetIds: this.subnets.map(s => s.id),
});
}
}{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2021-04-01",
"name": "nestedTemplate",
"properties": {
"mode": "Incremental",
"template": {
"resources": [...]
}
}
}class NetworkComponent extends pulumi.ComponentResource {
public readonly vnet: azure_native.network.VirtualNetwork;
public readonly subnets: azure_native.network.Subnet[];
constructor(name: string, args: NetworkComponentArgs, opts?: pulumi.ComponentResourceOptions) {
super("custom:azure:NetworkComponent", name, {}, opts);
const defaultOptions = { parent: this };
this.vnet = new azure_native.network.VirtualNetwork(`${name}-vnet`, {
virtualNetworkName: args.vnetName,
resourceGroupName: args.resourceGroupName,
location: args.location,
addressSpace: {
addressPrefixes: [args.addressPrefix],
},
}, defaultOptions);
this.subnets = args.subnets.map((subnet, i) =>
new azure_native.network.Subnet(`${name}-subnet-${i}`, {
subnetName: subnet.name,
virtualNetworkName: this.vnet.name,
resourceGroupName: args.resourceGroupName,
addressPrefix: subnet.addressPrefix,
}, defaultOptions)
);
this.registerOutputs({
vnetId: this.vnet.id,
subnetIds: this.subnets.map(s => s.id),
});
}
}{
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
},
"storageAccountId": {
"type": "string",
"value": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
}
}
}export const storageAccountName = storageAccount.name;
export const storageAccountId = storageAccount.id;{
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccountName')]"
},
"storageAccountId": {
"type": "string",
"value": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
}
}
}export const storageAccountName = storageAccount.name;
export const storageAccountId = storageAccount.id;@pulumi/azure@pulumi/azure{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2023-05-01",
"name": "[parameters('vnetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"subnets": [
{
"name": "default",
"properties": {
"addressPrefix": "10.0.1.0/24"
}
},
{
"name": "apps",
"properties": {
"addressPrefix": "10.0.2.0/24"
}
}
]
}
}import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const config = new pulumi.Config();
const vnetName = config.require("vnetName");
const location = config.require("location");
const resourceGroupName = config.require("resourceGroupName");
const vnet = new azure.network.VirtualNetwork("vnet", {
name: vnetName,
location: location,
resourceGroupName: resourceGroupName,
addressSpaces: ["10.0.0.0/16"],
subnets: [
{
name: "default",
addressPrefix: "10.0.1.0/24",
},
{
name: "apps",
addressPrefix: "10.0.2.0/24",
},
],
});{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2023-05-01",
"name": "[parameters('vnetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"subnets": [
{
"name": "default",
"properties": {
"addressPrefix": "10.0.1.0/24"
}
},
{
"name": "apps",
"properties": {
"addressPrefix": "10.0.2.0/24"
}
}
]
}
}import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const config = new pulumi.Config();
const vnetName = config.require("vnetName");
const location = config.require("location");
const resourceGroupName = config.require("resourceGroupName");
const vnet = new azure.network.VirtualNetwork("vnet", {
name: vnetName,
location: location,
resourceGroupName: resourceGroupName,
addressSpaces: ["10.0.0.0/16"],
subnets: [
{
name: "default",
addressPrefix: "10.0.1.0/24",
},
{
name: "apps",
addressPrefix: "10.0.2.0/24",
},
],
});{
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2023-01-01",
"name": "[parameters('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"capacity": 1
},
"kind": "linux",
"properties": {
"reserved": true
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
"siteConfig": {
"linuxFxVersion": "NODE|18-lts",
"appSettings": [
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "~18"
}
]
}
}
}
]
}import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const config = new pulumi.Config();
const appServicePlanName = config.require("appServicePlanName");
const webAppName = config.require("webAppName");
const location = config.require("location");
const resourceGroupName = config.require("resourceGroupName");
const appServicePlan = new azure.appservice.ServicePlan("appServicePlan", {
name: appServicePlanName,
location: location,
resourceGroupName: resourceGroupName,
osType: "Linux",
skuName: "B1",
});
const webApp = new azure.appservice.LinuxWebApp("webApp", {
name: webAppName,
location: location,
resourceGroupName: resourceGroupName,
servicePlanId: appServicePlan.id,
siteConfig: {
applicationStack: {
nodeVersion: "18-lts",
},
},
appSettings: {
"WEBSITE_NODE_DEFAULT_VERSION": "~18",
},
});LinuxWebAppWindowsWebAppWebApp{
"resources": [
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2023-01-01",
"name": "[parameters('appServicePlanName')]",
"location": "[parameters('location')]",
"sku": {
"name": "B1",
"tier": "Basic",
"size": "B1",
"capacity": 1
},
"kind": "linux",
"properties": {
"reserved": true
}
},
{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-01-01",
"name": "[parameters('webAppName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]"
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlanName'))]",
"siteConfig": {
"linuxFxVersion": "NODE|18-lts",
"appSettings": [
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "~18"
}
]
}
}
}
]
}import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const config = new pulumi.Config();
const appServicePlanName = config.require("appServicePlanName");
const webAppName = config.require("webAppName");
const location = config.require("location");
const resourceGroupName = config.require("resourceGroupName");
const appServicePlan = new azure.appservice.ServicePlan("appServicePlan", {
name: appServicePlanName,
location: location,
resourceGroupName: resourceGroupName,
osType: "Linux",
skuName: "B1",
});
const webApp = new azure.appservice.LinuxWebApp("webApp", {
name: webAppName,
location: location,
resourceGroupName: resourceGroupName,
servicePlanId: appServicePlan.id,
siteConfig: {
applicationStack: {
nodeVersion: "18-lts",
},
},
appSettings: {
"WEBSITE_NODE_DEFAULT_VERSION": "~18",
},
});LinuxWebAppWindowsWebAppWebApp!.apply()// ❌ WRONG - Will cause TypeScript errors
const webAppUrl = `https://${webApp.defaultHostName!}`;
// ✅ CORRECT - Handle undefined safely
const webAppUrl = webApp.defaultHostName.apply(hostname =>
hostname ? `https://${hostname}` : ""
);!.apply()// ❌ 错误写法 - 会导致TypeScript错误
const webAppUrl = `https://${webApp.defaultHostName!}`;
// ✅ 正确写法 - 安全处理undefined
const webAppUrl = webApp.defaultHostName.apply(hostname =>
hostname ? `https://${hostname}` : ""
);name// ARM: "name": "myStorageAccount"
// Pulumi:
new azure_native.storage.StorageAccount("logicalName", {
accountName: "mystorageaccount", // Actual Azure resource name
// ...
});name// ARM: "name": "myStorageAccount"
// Pulumi:
new azure_native.storage.StorageAccount("logicalName", {
accountName: "mystorageaccount", // Azure资源的实际名称
// ...
});// ARM: "apiVersion": "2023-01-01"
// Pulumi: API version is embedded in the provider// ARM: "apiVersion": "2023-01-01"
// Pulumi: API版本已嵌入到提供商中.apply()azureazure-nativeconcat()uniqueString().apply()azureconcat()uniqueString()importpulumi-cdk-importer/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}pulumi previewimportpulumi-cdk-importer/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}pulumi previewundefinedundefinedundefinedundefinedpulumi stack outputpulumi stack graphpulumi stack outputpulumi stack graphpulumi config setpulumi config set