Skip to content

Instantly share code, notes, and snippets.

@pierskarsenbarg
Created February 24, 2021 12:03
Show Gist options
  • Select an option

  • Save pierskarsenbarg/20d9f8d1e2d89efc0ef5187c06b9f06a to your computer and use it in GitHub Desktop.

Select an option

Save pierskarsenbarg/20d9f8d1e2d89efc0ef5187c06b9f06a to your computer and use it in GitHub Desktop.

Revisions

  1. pierskarsenbarg created this gist Feb 24, 2021.
    53 changes: 53 additions & 0 deletions dotnet-waiter-random.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Pulumi;
    using Pulumi.AzureNextGen.Resources.Latest;
    using Pulumi.AzureNextGen.Storage.Latest;
    using Pulumi.AzureNextGen.Storage.Latest.Inputs;
    using Pulumi.Random;

    class MyStack : Stack
    {
    public MyStack()
    {
    // Create an Azure Resource Group
    var resourceGroup = new ResourceGroup("resourceGroup", new ResourceGroupArgs
    {
    ResourceGroupName = "my-rg",
    Location = "WestUS"
    });

    var waitComplete = resourceGroup.Name.Apply(x => Wait(x));

    var randomWaiter = new RandomString("randomString", new RandomStringArgs
    {
    Length = 5,
    Keepers = new Dictionary<string, object> { { "upstream", waitComplete } }
    });

    // Create an Azure resource (Storage Account)
    var storageAccount = new StorageAccount("sa", new StorageAccountArgs
    {
    ResourceGroupName = resourceGroup.Name,
    AccountName = "piersstorage123",
    Location = resourceGroup.Location,
    Sku = new SkuArgs
    {
    Name = SkuName.Standard_LRS
    },
    Kind = Kind.StorageV2
    }, new CustomResourceOptions { DependsOn = randomWaiter });
    }

    private async Task<string> Wait(string name)
    {
    if (!Pulumi.Deployment.Instance.IsDryRun)
    {
    const int WaitTime = 10;
    Console.WriteLine($"Waiting for {WaitTime} seconds");
    await Task.Delay(WaitTime * 1000);
    }
    return name;
    }
    }