Beispiel #1
0
        public async Task CreateStorageAccountTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var storageNamePrefix      = Environment.GetEnvironmentVariable("AZURE_STORAGENAME_PREFIX");
            var storageAccountName     = string.Format("{0}{1}", storageNamePrefix, new Random().Next(0, 99));
            var storageAccountSku      = Profile2018Storage.Models.SkuName.StandardLRS;
            var credentials            = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var storageController  = new StorageController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE STORAGE ACCOUNT
            var storageAccount = await storageController.CreateStorageAccount(storageAccountName, resourceGroupName, location, storageAccountSku);

            // VALIDATION
            Assert.Equal("OK", storageAccount.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(storageAccount.Body);
            Assert.Equal("Succeeded", storageAccount.Body.ProvisioningState.ToString(), ignoreCase: true);
        }
Beispiel #2
0
        public async Task ResourceGroupExistanceCheckTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var credentials            = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CHECK RESOURCE GROUP
            var resourceGroupExistance = await resourceController.CheckResourceGroupExistance(resourceGroupName);

            // CHECK RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroupExistance.Response.ReasonPhrase, ignoreCase: true);
            Assert.True(resourceGroupExistance.Body);
        }
Beispiel #3
0
        public async Task CreateDataDiskTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var diskName               = Environment.GetEnvironmentVariable("AZURE_DISK_NAME");
            var credentials            = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var computerController = new ComputeController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE DISK
            var disk = await computerController.CreateDisk(resourceGroupName, diskName, 1, location);

            // CREATE DISK VALIDATION
            Assert.Equal("OK", disk.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(disk.Body);
            Assert.Equal("Succeeded", disk.Body.ProvisioningState.ToString(), ignoreCase: true);
        }
Beispiel #4
0
        public async Task CreateStaticPublicIPAddressTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var ipName      = Environment.GetEnvironmentVariable("AZURE_IP_NAME");
            var credentials = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var networkController  = new NetworkController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE IP
            var ip = await networkController.CreatePublicIpAddress(ipName, resourceGroupName, location, "Static");

            // VALIDATION
            Assert.Equal("OK", ip.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(ip.Body);
            Assert.NotEmpty(ip.Body.Id);
        }
Beispiel #5
0
        public async Task AddSubnetToExistingVnetTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var vnetName               = Environment.GetEnvironmentVariable("AZURE_VNET_NAME");
            var vnetAddressSpace       = Environment.GetEnvironmentVariable("AZURE_VNET_ADDRESSES");
            var newSubnetName          = "test-dotnet-newsubnet";
            var newSubnetAddress       = "10.0.16.0/24";
            var credentials            = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLERS
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var networkController  = new NetworkController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // RESOURCE GROUP CREATION VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE VNET
            var vnetAddressSpaces = vnetAddressSpace.Split(';');
            var vnet = await networkController.CreateVirtualNetwork(vnetName, vnetAddressSpaces, resourceGroupName, location);

            // VNET CREATION VALIDATION
            Assert.Equal("OK", vnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vnet.Body);

            // ADD NEW SUBNET
            var subnet = await networkController.AddSubnet(newSubnetName, vnetName, newSubnetAddress, resourceGroupName);

            // SUBNET CREATION VALIDATION
            Assert.Equal("OK", subnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(subnet.Body);
            Assert.Equal("Succeeded", subnet.Body.ProvisioningState, ignoreCase: true);
            Assert.Equal(newSubnetName, subnet.Body.Name);
            Assert.NotEmpty(subnet.Body.Id);
        }
Beispiel #6
0
        public async Task CreateVnetWithSubnetTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var vnetName               = Environment.GetEnvironmentVariable("AZURE_VNET_NAME");
            var subnetNames            = Environment.GetEnvironmentVariable("AZURE_SUBNET_NAMES");
            var subnetAddresses        = Environment.GetEnvironmentVariable("AZURE_SUBNET_ADDRESSES");
            var vnetAddresses          = Environment.GetEnvironmentVariable("AZURE_VNET_ADDRESSES");
            var credentials            = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var networkController  = new NetworkController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE VNET
            var vnetAddressSpaces = vnetAddresses.Split(';');
            var subNames          = subnetNames.Split(';');
            var suAddresses       = subnetAddresses.Split(';');
            var subnets           = new Dictionary <string, string>();

            for (int i = 0; i < subNames.Length; i++)
            {
                subnets.Add(subNames[i], suAddresses[i]);
            }

            var vnet = await networkController.CreateVirtualNetwork(vnetName, vnetAddressSpaces, resourceGroupName, location, subnets);

            // VALIDATION
            Assert.Equal("OK", vnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vnet.Body);
            Assert.NotEmpty(vnet.Body.Id);
        }
Beispiel #7
0
        public async Task CreateLinuxVirtualMachineWithManagedDiskTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var vmName          = Environment.GetEnvironmentVariable("AZURE_VM_NAME");
            var vnetName        = Environment.GetEnvironmentVariable("AZURE_VNET_NAME");
            var subnetNames     = Environment.GetEnvironmentVariable("AZURE_SUBNET_NAMES");
            var subnetAddresses = Environment.GetEnvironmentVariable("AZURE_SUBNET_ADDRESSES");
            var vnetAddresses   = Environment.GetEnvironmentVariable("AZURE_VNET_ADDRESSES");
            var ipName          = Environment.GetEnvironmentVariable("AZURE_IP_NAME");
            var nicName         = Environment.GetEnvironmentVariable("AZURE_NIC_NAME");
            var diskName        = Environment.GetEnvironmentVariable("AZURE_DISK_NAME");
            var credentials     = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var networkController  = new NetworkController(new Uri(baseUriString), credentials, subscriptionId);
            var computerController = new ComputeController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE VNET
            var vnetAddressSpaces = vnetAddresses.Split(';');
            var subNames          = subnetNames.Split(';');
            var suAddresses       = subnetAddresses.Split(';');
            var subnets           = new Dictionary <string, string>();

            for (int i = 0; i < subNames.Length; i++)
            {
                subnets.Add(subNames[i], suAddresses[i]);
            }

            var vnet = await networkController.CreateVirtualNetwork(vnetName, vnetAddressSpaces, resourceGroupName, location, subnets);

            // CREATE VNET VALIDATION
            Assert.Equal("OK", vnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vnet.Body);

            // CREATE IP
            var ip = await networkController.CreatePublicIpAddress(ipName, resourceGroupName, location);

            // CREATE IP VALIDATION
            Assert.Equal("OK", ip.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(ip.Body);

            // CREATE NIC
            var nic = await networkController.CreateNetworkInterface(nicName, resourceGroupName, vnetName, subNames[0], ipName, location);

            // CREATE NIC VALIDATION
            Assert.Equal("OK", nic.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(nic.Body);
            Assert.Equal("Succeeded", nic.Body.ProvisioningState, ignoreCase: true);

            // CREATE DISK
            var disk = await computerController.CreateDisk(resourceGroupName, diskName, 1, location);

            // CREATE DISK VALIDATION
            Assert.Equal("OK", disk.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(disk.Body);
            Assert.Equal("Succeeded", disk.Body.ProvisioningState.ToString(), ignoreCase: true);

            // CREATE VM
            var vm = await computerController.CreateVirtialMachineWithManagedDisk(resourceGroupName, vmName, nic.Body.Id, disk.Body.Id, location);

            // VALIDATION
            Assert.Equal("OK", vm.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vm.Body);
            Assert.Equal("Succeeded", vm.Body.ProvisioningState.ToString(), ignoreCase: true);
        }
Beispiel #8
0
        public async Task CreateLinuxVirtualMachineTest()
        {
            // SET PARAMETERS
            var location               = Environment.GetEnvironmentVariable("AZURE_LOCATION");
            var baseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var resourceGroupName      = Environment.GetEnvironmentVariable("AZURE_RESOURCEGROUP");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var azureResourceId        = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var tenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var subscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var vmName             = Environment.GetEnvironmentVariable("AZURE_VM_NAME");
            var vnetName           = Environment.GetEnvironmentVariable("AZURE_VNET_NAME");
            var subnetNames        = Environment.GetEnvironmentVariable("AZURE_SUBNET_NAMES");
            var subnetAddresses    = Environment.GetEnvironmentVariable("AZURE_SUBNET_ADDRESSES");
            var vnetAddresses      = Environment.GetEnvironmentVariable("AZURE_VNET_ADDRESSES");
            var ipName             = Environment.GetEnvironmentVariable("AZURE_IP_NAME");
            var nicName            = Environment.GetEnvironmentVariable("AZURE_NIC_NAME");
            var storageNamePrefix  = Environment.GetEnvironmentVariable("AZURE_STORAGENAME_PREFIX");
            var storageEndpoint    = Environment.GetEnvironmentVariable("AZURE_STORAGE_ENDPOINT");
            var storageAccountName = string.Format("{0}{1}", storageNamePrefix, new Random().Next(0, 99));
            var storageAccountSku  = Profile2018Storage.Models.SkuName.StandardLRS;
            var credentials        = new CustomLoginCredentials(servicePrincipalId, servicePrincipalSecret, azureResourceId, tenantId);

            // SET CONTROLLER
            var resourceController = new ResourcesController(new Uri(baseUriString), credentials, subscriptionId);
            var networkController  = new NetworkController(new Uri(baseUriString), credentials, subscriptionId);
            var storageController  = new StorageController(new Uri(baseUriString), credentials, subscriptionId);
            var computerController = new ComputeController(new Uri(baseUriString), credentials, subscriptionId);

            // CREATE RESOURCE GROUP
            var resourceGroup = await resourceController.CreateResourceGroup(resourceGroupName, location);

            // CREATE RESOURCE GROUP VALIDATION
            Assert.Equal("OK", resourceGroup.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(resourceGroup.Body);

            // CREATE VNET
            var vnetAddressSpaces = vnetAddresses.Split(';');
            var subNames          = subnetNames.Split(';');
            var suAddresses       = subnetAddresses.Split(';');
            var subnets           = new Dictionary <string, string>();

            for (int i = 0; i < subNames.Length; i++)
            {
                subnets.Add(subNames[i], suAddresses[i]);
            }

            var vnet = await networkController.CreateVirtualNetwork(vnetName, vnetAddressSpaces, resourceGroupName, location, subnets);

            // CREATE VNET VALIDATION
            Assert.Equal("OK", vnet.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vnet.Body);

            // CREATE IP
            var ip = await networkController.CreatePublicIpAddress(ipName, resourceGroupName, location);

            // CREATE IP VALIDATION
            Assert.Equal("OK", ip.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(ip.Body);

            // CREATE NIC
            var nic = await networkController.CreateNetworkInterface(nicName, resourceGroupName, vnetName, subNames[0], ipName, location);

            // CREATE NIC VALIDATION
            Assert.Equal("OK", nic.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(nic.Body);
            Assert.Equal("Succeeded", nic.Body.ProvisioningState, ignoreCase: true);

            // CREATE STORAGE ACCOUNT
            var storageAccount = await storageController.CreateStorageAccount(storageAccountName, resourceGroupName, location, storageAccountSku);

            // STORAGE ACCOUNT VALIDATION
            Assert.Equal("OK", storageAccount.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(storageAccount.Body);
            Assert.Equal("Succeeded", storageAccount.Body.ProvisioningState.ToString(), ignoreCase: true);

            // CREATE VM
            var vm = await computerController.CreateVirtialMachine(resourceGroupName, vmName, storageAccountName, storageEndpoint, nic.Body.Id, location);

            // VALIDATION
            Assert.Equal("OK", vm.Response.ReasonPhrase, ignoreCase: true);
            Assert.NotNull(vm.Body);
            Assert.Equal("Succeeded", vm.Body.ProvisioningState.ToString(), ignoreCase: true);
        }
        static void Main(string[] args)
        {
            //Set Azure environment variables
            var azureLocation           = "westus";
            var azureBaseUrl            = "https://management.azure.com/";
            var azureResourceGroupName  = "test-hybrid-dotnet-azure-resourcegroup";
            var azureCredentials        = SdkContext.AzureCredentialsFactory.FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));
            var azureVnetName           = Environment.GetEnvironmentVariable("AZURE_VNET_NAME");
            var azureSubnetName         = Environment.GetEnvironmentVariable("AZURE_SUBNET_NAMES");
            var azureSubnetAddressSpace = Environment.GetEnvironmentVariable("AZURE_SUBNET_ADDRESSES");
            var azureVnetAddress        = Environment.GetEnvironmentVariable("AZURE_VNET_ADDRESSES");
            var azureIpName             = Environment.GetEnvironmentVariable("AZURE_IP_NAME");
            var azureNicName            = Environment.GetEnvironmentVariable("AZURE_NIC_NAME");
            var azureVmName             = Environment.GetEnvironmentVariable("AZURE_VM_NAME");


            //Set Azure stack environment variables
            var stackLocation               = "redmond";
            var stackResourceGroupName      = "test-hybrid-dotnet-stack-resourcegroup";
            var stackBaseUriString          = Environment.GetEnvironmentVariable("AZURE_BASE_URL");
            var stackServicePrincipalId     = Environment.GetEnvironmentVariable("AZURE_CLIENT_ID");
            var stackServicePrincipalSecret = Environment.GetEnvironmentVariable("AZURE_CLIENT_SECRET");
            var stackResourceId             = Environment.GetEnvironmentVariable("AZURE_RESOURCE_ID");
            var stackTenantId               = Environment.GetEnvironmentVariable("AZURE_TENANT_ID");
            var stackSubscriptionId         = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
            var stackCredentials            = new CustomLoginCredentials(
                stackServicePrincipalId, stackServicePrincipalSecret, stackResourceId, stackTenantId);
            var stackDiskName = Environment.GetEnvironmentVariable("AZURE_DISK_NAME");

            //Set controllers
            var stackResourceController = new ResourcesController(new Uri(stackBaseUriString), stackCredentials, stackSubscriptionId);
            var azureResourceController = new ResourcesController(new Uri(azureBaseUrl), azureCredentials, "azure");
            var azureNetworkController  = new NetworkController(new Uri(azureBaseUrl), azureCredentials, "azure");
            var stackComputeController  = new ComputeController(new Uri(stackBaseUriString), stackCredentials, stackSubscriptionId);
            var azureComputeController  = new ComputeController(new Uri(azureBaseUrl), azureCredentials, "azure");

            //Create resource group in Azure
            var azureRgTask = azureResourceController.CreateResourceGroup(azureResourceGroupName, azureLocation);

            azureRgTask.Wait();

            //Create resource group in Azure Stack
            var stackRgTask = stackResourceController.CreateResourceGroup(stackResourceGroupName, stackLocation);

            stackRgTask.Wait();

            //Create NIC on Azure
            var nicTask = azureNetworkController.CreateNetworkInterface(
                azureNicName,
                azureResourceGroupName,
                azureVnetName,
                azureVnetAddress,
                azureSubnetName,
                azureSubnetAddressSpace,
                azureIpName,
                azureLocation);

            nicTask.Wait();

            //Create disk on Azure Stack
            var diskTask = stackComputeController.CreateDisk(
                stackResourceGroupName,
                stackDiskName,
                1,
                stackLocation);

            diskTask.Wait();

            //Create a VM on Azure with its data on Azure Stack
            var vmTask = azureComputeController.CreateVirtialMachineWithManagedDisk(
                azureResourceGroupName,
                azureVmName,
                nicTask.Result.Body,
                diskTask.Result.Body,
                azureLocation);

            vmTask.Wait();
        }