Running bulk Azure resource updates through Azure CLI Scripts
TypeScriptTo run bulk updates on Azure resources, you can leverage the
AzureCliScript
resource from theazure-native
provider. This allows you to execute Azure CLI commands or scripts directly from Pulumi, which is useful for automating tasks like applying bulk updates to resources.Below you'll find a Pulumi program that demonstrates how to use the
AzureCliScript
resource. This example executes a simple Azure CLI command to list all resource groups in your subscription, but you can modifyscriptContent
with the CLI commands or script to perform your desired bulk updates.Make sure you have Azure CLI installed and properly set up on the local machine or in the environment where this Pulumi program will run. Pulumi will use it to enforce the intended state.
import * as pulumi from "@pulumi/pulumi"; import * as azure_native from "@pulumi/azure-native"; // Create an instance of AzureCliScript to run a custom Azure CLI Script. const cliScript = new azure_native.resources.AzureCliScript("cliScript", { // Specify the Azure CLI version to use. azCliVersion: "2.0.77", // Optionally specify a location, if required by your organization's policies. location: "East US", // Optionally specify a timeout for script execution. // The timeout should be in ISO 8601 format. For example, "PT30M" for 30 minutes. timeout: "PT30M", // Provide the CLI command or series of commands you want to run. scriptContent: ` # This is an example command that lists all resource groups in a subscription. # Replace the content with your own CLI commands to perform bulk updates. az group list --output json `, // Define environment variables if required by the script. environmentVariables: [{ name: "EXAMPLE_VARIABLE", value: "exampleValue", }], // Configure other script settings as needed. cleanupPreference: "OnSuccess", // Cleanup options: Always, OnSuccess, OnExpiration // Specify retention interval in ISO 8601 format. For example, "P1D" for one day. retentionInterval: "P1D", }); // To use the output from the CLI script, refer to it using the `result` property. export const cliScriptResult = cliScript.result;
In this program,
AzureCliScript
is used to execute Azure CLI commands. ThescriptContent
property contains the commands that will be executed. In a real-world use case, you should replace the example command with the actual Azure CLI commands required to perform your bulk resource updates.Key points for using
AzureCliScript
:azCliVersion
: Specify the version of the Azure CLI to use. Ensure compatibility with the script commands.location
: It is recommended to choose the location closest to your Azure resources to optimize performance.timeout
: Define how long Pulumi should wait for script execution before timing out.scriptContent
: The actual script that will get executed. This is where you would place your Azure CLI commands for bulk updates.environmentVariables
: If your script relies on environment variables, define them here.cleanupPreference
: Choose when to clean up the container group for the script execution. Options includeAlways
,OnSuccess
, andOnExpiration
.retentionInterval
: Specify the time Pulumi should retain the execution information. This could be important for audit or troubleshooting purposes.
This Pulumi program defines the deployment script and its behavior. After execution, you can access the results through Pulumi stack outputs, which allows you to handle the output programmatically if needed.