Skip to main content

Azure web server with manual provisioning

An example of an Azure VM webserver instance with post-provision configuration.

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set classic-azure-ts-vm-provisioners
cd pulumi-examples/classic-azure-ts-vm-provisioners

This demonstrates using the @pulumi/command package to accomplish post-provisioning configuration steps.

Using these building blocks, one can accomplish much of the same as Terraform provisioners.

Prerequisites#

  1. Install Pulumi
  2. Configure Azure credentials
  3. Install Node.js

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Log in to the Azure CLI (you will be prompted to do this during deployment if you forget this step):

    Terminal window
    az login
  3. Set the config for login credentials and location information:

    Terminal window
    pulumi config set azure:location westus
    pulumi config set azure:subscriptionId <YOUR_SUBSCRIPTION_ID>
    pulumi config set username <your_username>
    pulumi config set password --secret <your_desired_password>
  4. Generate an OpenSSH keypair for use with your server, as per the Azure requirements:

    Terminal window
    ssh-keygen -t rsa -f rsa -m PEM

    This will output two files, rsa and rsa.pub, in the current directory. Be sure not to commit these files!

  5. Configure your stack so that the public key is used by your VM, and the private key is used for subsequent SCP and SSH steps to configure your server after it is stood up. Note that using --secret for privateKey ensures the private key is stored as an encrypted Pulumi secret.

    Terminal window
    cat rsa.pub | pulumi config set publicKey --
    cat rsa | pulumi config set privateKey --secret --
  6. Install dependencies:

    Terminal window
    npm install
  7. Deploy the stack. All resources will be provisioned and configured:

    Terminal window
    pulumi up

Cleaning up#

Once you are done, you can destroy all of the resources, and the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.