Skip to main content

Minecraft server using an Azure Virtual Machine

Basic example of an Azure web server accessible over HTTP

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 azure-py-minecraft-server
cd pulumi-examples/azure-py-minecraft-server

This example deploys an Azure Virtual Machine and provisions a Minecraft server.

Prerequisites#

  1. Install Pulumi
  2. Configure Azure credentials
  3. Install Python

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  3. Generate an OpenSSH keypair for use with your server:

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

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

    Make the public and private keys available to the virtual machine. The private key is used for subsequent SCP and SSH steps that will configure your server after it is stood up. Notice that we’ve used --secret for privateKey. This 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 --
  4. Set the required configuration for this example. This example requires you to supply a username, password, and location for the virtual machine that we are going to create. Check the Azure virtual machine password requirements before creating a password. Note that --secret ensures your password is encrypted safely.

    Terminal window
    pulumi config set admin_password --secret <admin password>
    pulumi config set admin_username <admin username>
    pulumi config set azure-native:location westus # any valid Azure region will do
  5. Deploy the stack:

    Terminal window
    pulumi up
    Type Name Status
    + pulumi:pulumi:Stack azure-py-webserver-dev created
    + ├─ azure-native:resources:ResourceGroup server-rg created
    + ├─ azure-native:network:VirtualNetwork server-network created
    + ├─ azure-native:network:PublicIPAddress server-ip created
    + ├─ azure-native:network:NetworkInterface server-nic created
    + ├─ azure-native:compute:VirtualMachine server-vm created
    + ├─ pulumi-python:dynamic:Resource config created
    + └─ pulumi-python:dynamic:Resource install created
    Outputs:
    Minecraft Server IP Address: "40.112.182.143"
    Resources:
    + 8 created
    Duration: 7m6s
  6. Get the IP address of the newly-created instance from the stack’s outputs:

    Terminal window
    pulumi stack output public_ip
  7. Check to see that your server is running by adding the server to the Minecraft client.

    Add server

Cleaning up#

Once you are finished, you can destroy your stack and remove it to avoid incurring any additional cost:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.