1. Packages
  2. Azure Native
  3. How-to Guides
  4. Minecraft Server Using an Azure Virtual Machine
This is the latest version of Azure Native. Use the Azure Native v1 docs if using the v1 version of this package.
Azure Native v2.44.1 published on Thursday, Jun 6, 2024 by Pulumi

Minecraft Server Using an Azure Virtual Machine

azure-native logo
This is the latest version of Azure Native. Use the Azure Native v1 docs if using the v1 version of this package.
Azure Native v2.44.1 published on Thursday, Jun 6, 2024 by Pulumi

    View Code Deploy this example with Pulumi

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

    Prerequisites

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

    Deploying and running the program

    1. Create a new stack:

      $ pulumi stack init dev
      
    2. Create a Python virtualenv, activate it, and install dependencies:

      This installs the dependent packages needed for our Pulumi program.

      $ python3 -m venv venv
      $ source venv/bin/activate
      $ pip3 install -r requirements.txt
      
    3. Next, generate an OpenSSH keypair for use with your server.

      $ 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!

      We must configure our stack and make the public key and private available to the virtual machine. The private key is used for subsequent SCP and SSH steps that will configure our server after it is stood up.

      $ cat rsa.pub | pulumi config set publicKey --
      $ cat rsa | pulumi config set privateKey --secret --
      

      Notice that we’ve used --secret for privateKey. This ensures the private key is stored as an encrypted Pulumi secret.

    4. Set the required configuration for this example. This example requires you to supply a username, password, location, and the public and private keys to the virtual machine that we are going to create. Check the Azure virtual machine password requirements before creating a password.

      $ 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
      

      Note that --secret ensures your password is encrypted safely.

    5. Run pulumi up to preview and deploy the changes:

      $ pulumi up
      Previewing update (dev)
      
      View Live: https://app.pulumi.com/spara/azure-py-webserver/dev/previews/19ff86d5-9303-4f53-a1ae-d0882a59e9a9
      
          Type                                              Name                    Plan
      +   pulumi:pulumi:Stack                               azure-py-webserver-dev  create
      +   ├─ azure-native:resources:ResourceGroup           server-rg               create
      +   ├─ azure-native:network:PublicIPAddress           server-ip               create
      +   ├─ azure-native:network:VirtualNetwork            server-network          create
      +   ├─ azure-native:network:NetworkInterface          server-nic              create
      +   ├─ azure-native:compute:VirtualMachine            server-vm               create
      +   ├─ pulumi-python:dynamic:Resource                 config                  create
      +   └─ pulumi-python:dynamic:Resource                 install                 create
      
      Resources:
          + 8 to create
      
      Do you want to perform this update? yes
      Updating (dev)
      
      View Live: https://app.pulumi.com/spara/azure-py-webserver/dev/updates/40
      
          Type                                              Name                    Status      Info
      +   pulumi:pulumi:Stack                               azure-py-webserver-dev  created     1 message
      +   ├─ 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
      
      Diagnostics:
      
      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:

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

      Add server

    8. Destroy the stack:

      $ pulumi destroy
      Previewing destroy (dev)
      
      View Live: https://app.pulumi.com/spara/azure-py-webserver/dev/previews/2544442c-ddd7-44cc-a633-2a5fed28dafb
      
          Type                                              Name                    Plan
      -   pulumi:pulumi:Stack                               azure-py-webserver-dev  delete
      -   ├─ pulumi-python:dynamic:Resource                 install                 delete
      -   ├─ pulumi-python:dynamic:Resource                 config                  delete
      -   ├─ azure-native:compute:VirtualMachine            server-vm               delete
      -   ├─ azure-native:network:NetworkInterface          server-nic              delete
      -   ├─ azure-native:network:PublicIPAddress           server-ip               delete
      -   ├─ azure-native:network:VirtualNetwork            server-network          delete
      -   └─ azure-native:resources:ResourceGroup           server-rg               delete
      
      Outputs:
      - Minecraft Server IP Address: "40.112.182.143"
      
      Resources:
          - 8 to delete
      
      Do you want to perform this destroy? yes
      Destroying (dev)
      
      View Live: https://app.pulumi.com/spara/azure-py-webserver/dev/updates/41
      
          Type                                              Name                    Status
      -   pulumi:pulumi:Stack                               azure-py-webserver-dev  deleted
      -   ├─ pulumi-python:dynamic:Resource                 install                 deleted
      -   ├─ pulumi-python:dynamic:Resource                 config                  deleted
      -   ├─ azure-native:compute:VirtualMachine            server-vm               deleted
      -   ├─ azure-native:network:NetworkInterface          server-nic              deleted
      -   ├─ azure-native:network:PublicIPAddress           server-ip               deleted
      -   ├─ azure-native:network:VirtualNetwork            server-network          deleted
      -   └─ azure-native:resources:ResourceGroup           server-rg               deleted
      
      Outputs:
      - Minecraft Server IP Address: "40.112.182.143"
      
      Resources:
          - 8 deleted
      
      Duration: 4m33s
      
    azure-native logo
    This is the latest version of Azure Native. Use the Azure Native v1 docs if using the v1 version of this package.
    Azure Native v2.44.1 published on Thursday, Jun 6, 2024 by Pulumi