Exemple #1
0
 public async Task SetUp()
 {
     _rgName        = Recording.GenerateAssetName("CoreRg");
     _client        = GetArmClient();
     _container     = _client.DefaultSubscription.GetResourceGroups();
     _resourceGroup = await _container.Construct(Location.WestUS2).CreateOrUpdateAsync(_rgName);
 }
Exemple #2
0
        public async Task CreateResourceGroupAsync()
        {
            #region Snippet:Creating_A_Virtual_Network_CreateResourceGroup
            ArmClient armClient = new ArmClient(new DefaultAzureCredential());
            ResourceGroupContainer rgContainer = armClient.DefaultSubscription.GetResourceGroups();
            string        rgName        = "myResourceGroup";
            ResourceGroup resourceGroup = await rgContainer.Construct(Location.WestUS2).CreateOrUpdateAsync(rgName);

            #endregion Snippet:Creating_A_Virtual_Network_CreateResourceGroup
        }
Exemple #3
0
        public async Task CreateResourceGroup()
        {
            #region Snippet:Managing_Resource_Groups_CreateAResourceGroup
            // First, initialize the ArmClient and get the default subscription
            ArmClient armClient = new ArmClient(new DefaultAzureCredential());
            // Now we get a ResourceGroup container for that subscription
            Subscription           subscription = armClient.DefaultSubscription;
            ResourceGroupContainer rgContainer  = subscription.GetResourceGroups();

            // With the container, we can create a new resource group with an specific name
            string        rgName        = "myRgName";
            Location      location      = Location.WestUS2;
            ResourceGroup resourceGroup = await rgContainer.Construct(location).CreateOrUpdateAsync(rgName);

            #endregion Snippet:Managing_Resource_Groups_CreateAResourceGroup
        }
Exemple #4
0
        public async Task UpdateAResourceGroup()
        {
            #region Snippet:Managing_Resource_Groups_UpdateAResourceGroup
            // Note: Resource group named 'myRgName' should exist for this example to work.
            ArmClient    armClient    = new ArmClient(new DefaultAzureCredential());
            Subscription subscription = armClient.DefaultSubscription;
            string       rgName       = "myRgName";
#if !SNIPPET
            //Check if 'myRgName' exists, if not, create it first or run CreateResourceGroup()
            ResourceGroup rg = await subscription.GetResourceGroups().GetIfExistsAsync(rgName);

            if (rg == null)
            {
                Location location = Location.WestUS2;
                ResourceGroupContainer rgContainer = subscription.GetResourceGroups();
                _ = await rgContainer.Construct(location).CreateOrUpdateAsync(rgName);
            }
#endif
            ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName);

            resourceGroup = await resourceGroup.AddTagAsync("key", "value");

            #endregion Snippet:Managing_Resource_Groups_UpdateAResourceGroup
        }
Exemple #5
0
        public async Task GettingResourceGroupContainer()
        {
            #region Snippet:Managing_Resource_Groups_GetResourceGroupContainer
            ArmClient              armClient    = new ArmClient(new DefaultAzureCredential());
            Subscription           subscription = armClient.DefaultSubscription;
            ResourceGroupContainer rgContainer  = subscription.GetResourceGroups();

            // code omitted for brevity

            string rgName = "myRgName";
#if !SNIPPET
            //Check if "myRgName" exists, if not, create it first or run CreateResourceGroup()
            ResourceGroup rg = await subscription.GetResourceGroups().GetIfExistsAsync(rgName);

            if (rg == null)
            {
                Location location = Location.WestUS2;
                _ = await rgContainer.Construct(location).CreateOrUpdateAsync(rgName);
            }
#endif
            ResourceGroup resourceGroup = await rgContainer.GetAsync(rgName);

            #endregion Snippet:Managing_Resource_Groups_GetResourceGroupContainer
        }