1. Docs
  2. Clouds
  3. Azure
  4. Get started
  5. Modify program

Pulumi & Azure: Modify program

    Now that your storage account is provisioned, let’s add an object to it. First, from within your project directory, create a new index.html file with some content in it.

    cat <<EOT > index.html
    <html>
        <body>
            <h1>Hello, Pulumi!</h1>
        </body>
    </html>
    EOT
    
    cat <<EOT > index.html
    <html>
        <body>
            <h1>Hello, Pulumi!</h1>
        </body>
    </html>
    EOT
    
    @"
    <html>
      <body>
        <h1>Hello, Pulumi!</h1>
      </body>
    </html>
    "@ | Out-File -FilePath index.html
    

    Now that you have your new index.html with some content, you can enable static website support, upload index.html to a storage container, and retrieve a public URL through the use of resource properties. These properties can be used to define dependencies between related resources or to retrieve property values for further processing.

    To start, open index.ts and add the following right after the storage account creation:

    // Enable static website support
    const staticWebsite = new storage.StorageAccountStaticWebsite("staticWebsite", {
        accountName: storageAccount.name,
        resourceGroupName: resourceGroup.name,
        indexDocument: "index.html",
    });
    

    To start, open __main__.py and add the following right after the storage account creation:

    # Enable static website support
    static_website = storage.StorageAccountStaticWebsite(
        "staticWebsite",
        account_name=account.name,
        resource_group_name=resource_group.name,
        index_document="index.html",
    )
    

    To start, open main.go and add the following right after the storage account creation:

    // Enable static website support
    staticWebsite, err := storage.NewStorageAccountStaticWebsite(ctx, "staticWebsite", &storage.StorageAccountStaticWebsiteArgs{
        AccountName:       account.Name,
        ResourceGroupName: resourceGroup.Name,
        IndexDocument:     pulumi.String("index.html"),
    })
    if err != nil {
        return err
    }
    

    To start, open Program.cs and add the following right after the storage account creation:

    // Enable static website support
    var staticWebsite = new StorageAccountStaticWebsite("staticWebsite", new StorageAccountStaticWebsiteArgs
    {
        AccountName = storageAccount.Name,
        ResourceGroupName = resourceGroup.Name,
        IndexDocument = "index.html",
    });
    

    To start, open App.java and add the following imports:

    import com.pulumi.azurenative.storage.StorageAccountStaticWebsite;
    import com.pulumi.azurenative.storage.StorageAccountStaticWebsiteArgs;
    import com.pulumi.azurenative.storage.Blob;
    import com.pulumi.azurenative.storage.BlobArgs;
    import com.pulumi.azurenative.storage.outputs.EndpointsResponse;
    import com.pulumi.asset.FileAsset;
    

    Next, add the following right after the storage account creation:

    var staticWebsite = new StorageAccountStaticWebsite("staticWebsite",
                        StorageAccountStaticWebsiteArgs.builder()
                                .accountName(storageAccount.name())
                                .resourceGroupName(resourceGroup.name())
                                .indexDocument("index.html")
                                .build());
    

    To start, open Pulumi.yaml and add the following right after the storage account creation:

    resources:
      # ...
      staticWebsite:
        type: azure-native:storage:StorageAccountStaticWebsite
        properties:
          accountName: ${sa.name}
          resourceGroupName: ${resourceGroup.name}
          indexDocument: index.html
    

    The static website resource leverages the storage account and resource group names defined previously in your program.

    Now use all of these cloud resources and a local FileAsset resource to upload index.html into your storage container by adding the following at the end of the file (after enabling the static website support):

    // Upload the file
    const indexHtml = new storage.Blob("index.html", {
        resourceGroupName: resourceGroup.name,
        accountName: storageAccount.name,
        containerName: staticWebsite.containerName,
        source: new pulumi.asset.FileAsset("index.html"),
        contentType: "text/html",
    });
    
    # Upload the file
    index_html = storage.Blob(
        "index.html",
        resource_group_name=resource_group.name,
        account_name=account.name,
        container_name=static_website.container_name,
        source=pulumi.FileAsset("index.html"),
        content_type="text/html",
    )
    
    // Upload the file
    _, err = storage.NewBlob(ctx, "index.html", &storage.BlobArgs{
        ResourceGroupName: resourceGroup.Name,
        AccountName:       account.Name,
        ContainerName:     staticWebsite.ContainerName,
        Source:            pulumi.NewFileAsset("index.html"),
        ContentType:       pulumi.String("text/html"),
    })
    if err != nil {
        return err
    }
    
    // Upload the file
    var indexHtml = new Blob("index.html", new BlobArgs
    {
        ResourceGroupName = resourceGroup.Name,
        AccountName = storageAccount.Name,
        ContainerName = staticWebsite.ContainerName,
        Source = new FileAsset("./index.html"),
        ContentType = "text/html",
    });
    
    // Upload the file
    var index_html = new Blob("index.html", BlobArgs.builder()
                        .resourceGroupName(resourceGroup.name())
                        .accountName(storageAccount.name())
                        .containerName(staticWebsite.containerName())
                        .source(new FileAsset("index.html"))
                        .contentType("text/html")
                        .build());
    
    resources:
      # ...
      # Upload the file
      index-html:
        type: azure-native:storage:Blob
        properties:
          resourceGroupName: ${resourceGroup.name}
          accountName: ${sa.name}
          containerName: ${staticWebsite.containerName}
          source:
            fn::fileAsset: ./index.html
          contentType: text/html
          blobName: index.html
          type: Block
    

    Finally, at the end of index.ts, export the resulting storage container’s endpoint URL to stdout for easy access:

    // Web endpoint to the website
    export const staticEndpoint = storageAccount.primaryEndpoints.web;
    

    Finally, at the end of __main__.py, export the resulting storage container’s endpoint URL to stdout for easy access:

    # Web endpoint to the website
    pulumi.export("staticEndpoint", account.primary_endpoints.web)
    

    Finally, at the end of main.go, export the resulting storage container’s endpoint URL to stdout for easy access:

    // Web endpoint to the website
    ctx.Export("staticEndpoint", account.PrimaryEndpoints.Web())
    

    Finally, at the end of Program.cs, export the resulting storage container’s endpoint URL to stdout for easy access:

    // Web endpoint to the website
    return new Dictionary<string, object?>
    {
        ["primaryStorageKey"] = primaryStorageKey,
        ["staticEndpoint"] = storageAccount.PrimaryEndpoints.Apply(primaryEndpoints => primaryEndpoints.Web)
    };
    

    Finally, at the end of App.java, export the resulting storage container’s endpoint URL to stdout for easy access:

    ctx.export("staticEndpoint", storageAccount.primaryEndpoints()
            .applyValue(EndpointsResponse::web));
    

    Finally, at the end of Pulumi.yaml in the outputs, export the resulting storage container’s endpoint URL to stdout for easy access:

    outputs:
      # ...
      staticEndpoint: ${sa.primaryEndpoints.web}
    

    Now that you have declared how you want your resources to be provisioned, it is time to deploy these remaining changes.

      Introducing Pulumi Copilot - Intelligent Cloud Management