These samples demonstrate how to create Virtual Machines using the Azure SDK for Go on Azure Stack. The code provided shows how to do the following:

  • Create a resource group
  • Create a virtual network
  • Create a security group
  • Create a public IP
  • Create a network interface
  • Create a storage account
  • Create a virtual machine

To see the code to perform these operations, check out the main() function in app.go. Each operation is clearly labeled with a comment and a print function.

Running this sample

  1. If you don't already have it, install Golang.

  2. Install Go SDK and its dependencies, install Go SDK

  3. Clone the repository.

    git clone https://github.com/Azure-Samples/Hybrid-Compute-Go-Create-VM.git
  4. Create a service principal to work against AzureStack. Make sure your service principal has contributor/owner role on your subscription.

  5. Fill in and export these environment variables into your current shell.

    export AZ_ARM_ENDPOINT={your AzureStack Resource Manager Endpoint}
    export AZ_TENANT_ID={your tenant id}
    export AZ_CLIENT_ID={your client id}
    export AZ_CLIENT_SECRET={your client secret}
    export AZ_SUBSCRIPTION_ID={your subscription id}
    export AZ_LOCATION={your resource location}
  6. Note that in order to run this sample, WindowsServer 2012-R2-Datacenter image must be present in AzureStack market place. These can be either downloaded from Azure or added to Platform Image Repository.

  7. Run the sample.

    go run app.go

More information

Here are some helpful links:

If you don't have a Microsoft Azure subscription you can get a FREE trial account here.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.