Port two Azure examples to Go.
And fix the Gopkg.toml files for AWS examples.
MODIFY
aws-go-fargate/Gopkg.toml
aws-go-fargate/Gopkg.toml
[[constraint]]
name = "github.com/pulumi/pulumi-aws"
- branch = "tfgo"
+ version = "1.20.0"
[prune]
go-tests = true

MODIFY
aws-go-s3-folder/Gopkg.toml
aws-go-s3-folder/Gopkg.toml
[[constraint]]
name = "github.com/pulumi/pulumi-aws"
- branch = "tfgo"
+ version = "1.20.0"
[prune]
go-tests = true

MODIFY
aws-go-webserver/Gopkg.toml
aws-go-webserver/Gopkg.toml
[[constraint]]
name = "github.com/pulumi/pulumi-aws"
- branch = "tfgo"
+ version = "1.20.0"
[prune]
go-tests = true

ADD
azure-go-appservice/Gopkg.toml
+# Gopkg.toml example
+#
+# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
+# for detailed Gopkg.toml documentation.
+#
+# required = ["github.com/user/thing/cmd/thing"]
+# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
+#
+# [[constraint]]
+# name = "github.com/user/project"
+# version = "1.0.0"
+#
+# [[constraint]]
+# name = "github.com/user/project2"
+# branch = "dev"
+# source = "github.com/myfork/project2"
+#
+# [[override]]
+# name = "github.com/x/y"
+# version = "2.4.0"
+#
+# [prune]
+# non-go = false
+# go-tests = true
+# unused-packages = true
+
+
+[[constraint]]
+ name = "github.com/pulumi/pulumi"
+ version = "1.9.1"
+
+[[constraint]]
+ name = "github.com/pulumi/pulumi-azure"
+ version = "1.13.0"
+
+[prune]
+ go-tests = true
+ unused-packages = true

ADD
azure-go-appservice/Pulumi.yaml
+name: azure-appservice
+runtime: go
+description: Creates Azure App Service with SQL Database and Application Insights
+template:
+ config:
+ azure:environment:
+ description: The Azure environment to use (`public`, `usgovernment`, `german`, `china`)
+ default: public
+ sqlPassword:
+ description: SQL Server password (complex enough to satisfy Azure policy)
+ secret: true

ADD
azure-go-appservice/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Azure App Service with SQL Database and Application Insights
+
+Starting point for building web application hosted in Azure App Service.
+
+Provisions Azure SQL Database and Azure Application Insights to be used in combination
+with App Service.
+
+## Running the App
+
+1. Create a new stack:
+
+ ```
+ $ pulumi stack init azure-appservice
+ ```
+
+1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
+
+ ```
+ $ az login
+ ```
+
+1. Set the azure location in which to run the test:
+
+ ```
+ $ pulumi config set azure:location westus2
+ ```
+
+1. Define SQL Server password (make it complex enough to satisfy Azure policy):
+
+ ```
+ pulumi config set --secret sqlPassword <value>
+ ```
+
+1. Run `pulumi up` to preview and deploy changes:
+
+ ```
+ $ pulumi up
+ Previewing changes:
+ ...
+
+ Performing changes:
+ ...
+ info: 10 changes performed:
+ + 10 resources created
+ Update duration: 1m14.59910109s
+ ```
+
+1. Check the deployed website endpoint:
+
+ ```
+ $ pulumi stack output endpoint
+ https://azpulumi-as0ef47193.azurewebsites.net
+ $ curl "$(pulumi stack output endpoint)"
+ <html>
+ <body>
+ <h1>Greetings from Azure App Service!</h1>
+ </body>
+ </html>
+ ```

ADD
azure-go-appservice/main.go
+package main
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/appinsights"
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/appservice"
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/core"
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/sql"
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/storage"
+ "github.com/pulumi/pulumi/sdk/go/pulumi"
+ "github.com/pulumi/pulumi/sdk/go/pulumi/config"
+)
+
+func main() {
+ pulumi.Run(func(ctx *pulumi.Context) error {
+ // use first 10 characters of the stackname as prefix for resource names
+ prefix := ctx.Stack()
+ if len(prefix) > 10 {
+ prefix = prefix[:10]
+ }
+
+ resourceGroup, err := core.NewResourceGroup(ctx, prefix+"-rg", nil)
+ if err != nil {
+ return err
+ }
+
+ storageAccountName := strings.Replace(strings.ToLower(prefix), "-", "", -1) + "sa"
+ storageAccount, err := storage.NewAccount(ctx, storageAccountName, &storage.AccountArgs{
+ ResourceGroupName: resourceGroup.Name,
+ Location: resourceGroup.Location,
+ AccountKind: pulumi.String("StorageV2"),
+ AccountTier: pulumi.String("Standard"),
+ AccountReplicationType: pulumi.String("LRS"),
+ })
+ if err != nil {
+ return err
+ }
+
+ appServicePlan, err := appservice.NewPlan(ctx, prefix+"-asp", &appservice.PlanArgs{
+ ResourceGroupName: resourceGroup.Name,
+ Location: resourceGroup.Location,
+ Kind: pulumi.String("App"),
+ Sku: appservice.PlanSkuInputs{
+ Tier: pulumi.String("Basic"),
+ Size: pulumi.String("B1"),
+ },
+ })
+ if err != nil {
+ return err
+ }
+
+ storageContainer, err := storage.NewContainer(ctx, prefix+"-c", &storage.ContainerArgs{
+ StorageAccountName: storageAccount.Name,
+ ContainerAccessType: pulumi.String("private"),
+ })
+ if err != nil {
+ return err
+ }
+
+ blob, err := storage.NewZipBlob(ctx, prefix+"-b", &storage.ZipBlobArgs{
+ StorageAccountName: storageAccount.Name,
+ StorageContainerName: storageContainer.Name,
+ Type: pulumi.String("block"),
+ Content: pulumi.NewFileArchive("wwwroot"),
+ })
+ if err != nil {
+ return err
+ }
+
+ codeBlobURL := signedBlobReadURL(ctx, blob, storageAccount)
+
+ appInsights, err := appinsights.NewInsights(ctx, prefix+"-i", &appinsights.InsightsArgs{
+ ResourceGroupName: resourceGroup.Name,
+ Location: resourceGroup.Location,
+ ApplicationType: pulumi.String("Web"),
+ })
+ if err != nil {
+ return err
+ }
+
+ username := "pulumi"
+
+ // Get the password to use for SQL from config.
+ passwd := config.New(ctx, "").Require("sqlPassword")
+
+ sqlServer, err := sql.NewSqlServer(ctx, prefix+"-sql", &sql.SqlServerArgs{
+ ResourceGroupName: resourceGroup.Name,
+ Location: resourceGroup.Location,
+ AdministratorLogin: pulumi.String(username),
+ AdministratorLoginPassword: pulumi.String(passwd),
+ Version: pulumi.String("12.0"),
+ })
+ if err != nil {
+ return err
+ }
+
+ database, err := sql.NewDatabase(ctx, prefix+"-db", &sql.DatabaseArgs{
+ ResourceGroupName: resourceGroup.Name,
+ Location: resourceGroup.Location,
+ ServerName: sqlServer.Name,
+ RequestedServiceObjectiveName: pulumi.String("S0"),
+ })
+ if err != nil {
+ return err
+ }
+
+ app, err := appservice.NewAppService(ctx, prefix+"-as", &appservice.AppServiceArgs{
+ ResourceGroupName: resourceGroup.Name,
+ Location: resourceGroup.Location,
+ AppServicePlanId: appServicePlan.ID(),
+ AppSettings: pulumi.StringMap{
+ "WEBSITE_RUN_FROM_ZIP": codeBlobURL,
+ "ApplicationInsights:InstrumentationKey": appInsights.InstrumentationKey,
+ "APPINSIGHTS_INSTRUMENTATIONKEY": appInsights.InstrumentationKey,
+ },
+ ConnectionStrings: appservice.AppServiceConnectionStringsArray{
+ appservice.AppServiceConnectionStringsInputs{
+ Name: pulumi.String("db"),
+ Value: pulumi.Sprintf("Server=tcp:%s.database.windows.net;initial catalog=%s;user ID=%s;password=%s;Min Pool Size=0;Max Pool Size=30;Persist Security Info=true;",
+ sqlServer.Name, database.Name, username, passwd),
+ Type: pulumi.String("SQLAzure"),
+ },
+ },
+ })
+ if err != nil {
+ return err
+ }
+
+ ctx.Export("endpoint", pulumi.Sprintf("https://%s", app.DefaultSiteHostname))
+ return nil
+ })
+}
+
+func signedBlobReadURL(ctx *pulumi.Context, blob *storage.ZipBlob, account *storage.Account) pulumi.StringOutput {
+ // Choose a fixed, far-future expiration date for signed blob URLs. The shared access signature
+ // (SAS) we generate for the Azure storage blob must remain valid for as long as the Function
+ // App is deployed, since new instances will download the code on startup. By using a fixed
+ // date, rather than (e.g.) "today plus ten years", the signing operation is idempotent.
+ const signatureExpiration = "2100-01-01"
+
+ return pulumi.All(account.Name, account.PrimaryConnectionString, blob.StorageContainerName, blob.Name).
+ ApplyT(func(args []interface{}) (string, error) {
+ accountName := args[0].(string)
+ connectionString := args[1].(string)
+ containerName := args[2].(string)
+ blobName := args[3].(string)
+
+ sas, err := storage.LookupAccountBlobContainerSAS(ctx, &storage.GetAccountBlobContainerSASArgs{
+ ConnectionString: connectionString,
+ ContainerName: containerName,
+ Start: "2019-01-01",
+ Expiry: signatureExpiration,
+ Permissions: storage.GetAccountBlobContainerSASPermissionsArgs{Read: true},
+ })
+ if err != nil {
+ return "", err
+ }
+ return fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s%s", accountName, containerName, blobName, sas.Sas), nil
+ }).(pulumi.StringOutput)
+}

ADD
azure-go-appservice/wwwroot/index.html
+<html>
+ <body>
+ <h1>Greetings from Azure App Service!</h1>
+ </body>
+</html>
\ No newline at end of file

ADD
azure-go-webserver-component/Gopkg.toml
+# Gopkg.toml example
+#
+# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
+# for detailed Gopkg.toml documentation.
+#
+# required = ["github.com/user/thing/cmd/thing"]
+# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
+#
+# [[constraint]]
+# name = "github.com/user/project"
+# version = "1.0.0"
+#
+# [[constraint]]
+# name = "github.com/user/project2"
+# branch = "dev"
+# source = "github.com/myfork/project2"
+#
+# [[override]]
+# name = "github.com/x/y"
+# version = "2.4.0"
+#
+# [prune]
+# non-go = false
+# go-tests = true
+# unused-packages = true
+
+
+[[constraint]]
+ name = "github.com/pulumi/pulumi"
+ version = "1.9.1"
+
+[[constraint]]
+ name = "github.com/pulumi/pulumi-azure"
+ version = "1.13.0"
+
+[prune]
+ go-tests = true
+ unused-packages = true

ADD
azure-go-webserver-component/Pulumi.yaml
+name: ws-go-azure-comp
+runtime: go
+description: Basic example of an Azure web server accessible over HTTP
+template:
+ config:
+ azure:location:
+ description: The Azure location to use
+ default: westus
+ username:
+ description: The username used to configure the Virtual Machine
+ password:
+ description: The password used to configure the Virtual Machine
+ secret: true

ADD
azure-go-webserver-component/README.md
+[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
+
+# Web Server Component Using Azure Virtual Machine
+
+This example provisions a configurable number of Linux web servers in an Azure Virtual Machine, and returns the
+resulting public IP addresses. This example uses a reusable [Pulumi component](
+https://www.pulumi.com/docs/intro/concepts/programming-model/#components) to simplify the creation of new virtual machines. By
+defining a `WebServer` class, we can hide many details (see [here](./webserver.ts) for its definition).
+
+## Prerequisites
+
+- [Node.js](https://nodejs.org/en/download/)
+- [Download and install the Pulumi CLI](https://www.pulumi.com/docs/get-started/install/)
+- [Connect Pulumi with your Azure account](https://www.pulumi.com/docs/intro/cloud-providers/azure/setup/) (if your `az` CLI is
+ configured, this will just work)
+
+## Running the App
+
+1. Create a new stack:
+
+ ```
+ $ pulumi stack init dev
+ ```
+
+1. Configure the deployment. The username and password here will be used to configure the Virtual Machine. The
+ password must adhere to the [Azure restrictions on VM passwords](
+ https://docs.microsoft.com/en-us/azure/virtual-machines/windows/faq#what-are-the-password-requirements-when-creating-a-vm).
+
+ ```
+ $ pulumi config set azure:location westus # any valid Azure region will do
+ $ pulumi config set username webmaster
+ $ pulumi config set password <your-password> --secret
+ $ pulumi config set count 5 # optional -- will default to 2 if left out
+ ```
+
+ Note that `--secret` ensures your password is encrypted safely.
+
+1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
+
+ ```
+ $ az login
+ ```
+
+1. Run `pulumi up` to preview and deploy changes:
+
+ ```
+ $ pulumi up
+ Previewing changes:
+ ...
+
+ Performing changes:
+ ...
+ info: 15 changes performed:
+ + 15 resources created
+ Update duration: 4m27s
+ ```
+
+1. Check the resulting IP addresses:
+
+ ```
+ $ pulumi stack output ipAddresses
+ [ 40.112.181.239, ..., 40.112.181.240 ]
+ ```

ADD
azure-go-webserver-component/main.go
+// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
+
+package main
+
+import (
+ "fmt"
+
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/core"
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/network"
+ "github.com/pulumi/pulumi/sdk/go/pulumi"
+ "github.com/pulumi/pulumi/sdk/go/pulumi/config"
+)
+
+// Get the desired username and password for our webserver VMs.
+func main() {
+ pulumi.Run(func(ctx *pulumi.Context) error {
+ config := config.New(ctx, "")
+
+ count := config.GetInt("count")
+ if count == 0 {
+ count = 2
+ }
+ username := config.Require("username")
+ password := config.Require("password")
+
+ // All resources will share a resource group.
+ rg, err := core.NewResourceGroup(ctx, "server-rg", nil)
+ if err != nil {
+ return err
+ }
+
+ // Create a network and subnet for all VMs.
+ network, err := network.NewVirtualNetwork(ctx, "server-network", &network.VirtualNetworkArgs{
+ ResourceGroupName: rg.Name,
+ AddressSpaces: pulumi.StringArray{pulumi.String("10.0.0.0/16")},
+ Subnets: network.VirtualNetworkSubnetsArrayArgs{
+ network.VirtualNetworkSubnetsArgs{
+ Name: pulumi.String("default"),
+ AddressPrefix: pulumi.String("10.0.1.0/24"),
+ },
+ },
+ })
+
+ // Now, allocate a few websever VMs -- by default, just 2, but this is configurable.
+ var ipAddresses pulumi.StringArray
+ for i := 0; i < count; i++ {
+ server, err := NewWebserver(ctx, fmt.Sprintf("ws-%v", i), &WebserverArgs{
+ Username: pulumi.String(username),
+ Password: pulumi.String(password),
+ BootScript: pulumi.String(fmt.Sprintf(`#!/bin/bash
+echo "Hello, from Server %v!" > index.html
+nohup python -m SimpleHTTPServer 80 &`, i)),
+ ResourceGroupName: rg.Name,
+ SubnetID: network.Subnets.Index(pulumi.Int(0)).Id(),
+ })
+ if err != nil {
+ return err
+ }
+ ipAddresses = append(ipAddresses, server.GetIPAddress(ctx))
+ }
+
+ ctx.Export("ipAddresses", ipAddresses)
+ return nil
+ })
+}

ADD
azure-go-webserver-component/webserver.go
+// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
+
+package main
+
+import (
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/compute"
+ "github.com/pulumi/pulumi-azure/sdk/go/azure/network"
+ "github.com/pulumi/pulumi/sdk/go/pulumi"
+)
+
+// Webserver is a reusable web server component that creates and exports a NIC, public IP, and VM.
+type Webserver struct {
+ pulumi.ResourceState
+
+ PublicIP *network.PublicIp
+ NetworkInterface *network.NetworkInterface
+ VM *compute.VirtualMachine
+}
+
+type WebserverArgs struct {
+ // A required username for the VM login.
+ Username pulumi.StringInput
+
+ // A required encrypted password for the VM password.
+ Password pulumi.StringInput
+
+ // An optional boot script that the VM will use.
+ BootScript pulumi.StringInput
+
+ // An optional VM size; if unspecified, Standard_A0 (micro) will be used.
+ VMSize pulumi.StringInput
+
+ // A required Resource Group in which to create the VM
+ ResourceGroupName pulumi.StringInput
+
+ // A required Subnet in which to deploy the VM
+ SubnetID pulumi.StringInput
+}
+
+// NewWebserver allocates a new web server VM, NIC, and public IP address.
+func NewWebserver(ctx *pulumi.Context, name string, args *WebserverArgs, opts ...pulumi.ResourceOption) (*Webserver, error) {
+ webserver := &Webserver{}
+ reg, err := ctx.RegisterComponentResource("ws-ts-azure-comp:webserver:WebServer", name, webserver, opts...)
+ if err != nil {
+ return nil, err
+ }
+ defer reg.Close()
+
+ webserver.PublicIP, err = network.NewPublicIp(ctx, name+"-ip", &network.PublicIpArgs{
+ ResourceGroupName: args.ResourceGroupName,
+ AllocationMethod: pulumi.String("Dynamic"),
+ }, pulumi.Parent(webserver))
+ if err != nil {
+ return nil, err
+ }
+
+ webserver.NetworkInterface, err = network.NewNetworkInterface(ctx, name+"-nic", &network.NetworkInterfaceArgs{
+ ResourceGroupName: args.ResourceGroupName,
+ IpConfigurations: network.NetworkInterfaceIpConfigurationsArrayArgs{
+ network.NetworkInterfaceIpConfigurationsArgs{
+ Name: pulumi.String("webserveripcfg"),
+ SubnetId: args.SubnetID,
+ PrivateIpAddressAllocation: pulumi.String("Dynamic"),
+ PublicIpAddressId: webserver.PublicIP.ID(),
+ },
+ },
+ }, pulumi.Parent(webserver))
+ if err != nil {
+ return nil, err
+ }
+
+ vmSize := args.VMSize
+ if vmSize == nil {
+ vmSize = pulumi.String("Standard_A0")
+ }
+
+ // Now create the VM, using the resource group and NIC allocated above.
+ webserver.VM, err = compute.NewVirtualMachine(ctx, name+"-vm", &compute.VirtualMachineArgs{
+ ResourceGroupName: args.ResourceGroupName,
+ NetworkInterfaceIds: pulumi.StringArray{webserver.NetworkInterface.ID()},
+ VmSize: vmSize,
+ DeleteDataDisksOnTermination: pulumi.Bool(true),
+ DeleteOsDiskOnTermination: pulumi.Bool(true),
+ OsProfile: compute.VirtualMachineOsProfileArgs{
+ ComputerName: pulumi.String("hostname"),
+ AdminUsername: args.Username,
+ AdminPassword: args.Password,
+ CustomData: args.BootScript,
+ },
+ OsProfileLinuxConfig: compute.VirtualMachineOsProfileLinuxConfigArgs{
+ DisablePasswordAuthentication: pulumi.Bool(false),
+ },
+ StorageOsDisk: compute.VirtualMachineStorageOsDiskArgs{
+ CreateOption: pulumi.String("FromImage"),
+ Name: pulumi.String(name + "-osdisk1"),
+ },
+ StorageImageReference: compute.VirtualMachineStorageImageReferenceArgs{
+ Publisher: pulumi.String("canonical"),
+ Offer: pulumi.String("UbuntuServer"),
+ Sku: pulumi.String("16.04-LTS"),
+ Version: pulumi.String("latest"),
+ },
+ }, pulumi.Parent(webserver))
+ if err != nil {
+ return nil, err
+ }
+
+ return webserver, nil
+}
+
+func (ws *Webserver) GetIPAddress(ctx *pulumi.Context) pulumi.StringOutput {
+ // The public IP address is not allocated until the VM is running, so wait for that resource to create, and then
+ // lookup the IP address again to report its public IP.
+ ready := pulumi.All(ws.VM.ID(), ws.PublicIP.Name, ws.PublicIP.ResourceGroupName)
+ return ready.ApplyT(func(args []interface{}) (string, error) {
+ name := args[1].(string)
+ resourceGroupName := args[2].(string)
+ ip, err := network.LookupPublicIP(ctx, &network.GetPublicIPArgs{
+ Name: name,
+ ResourceGroupName: resourceGroupName,
+ })
+ if err != nil {
+ return "", err
+ }
+ return ip.IpAddress, nil
+ }).(pulumi.StringOutput)
+}

Port two Azure examples to Go. (#542)

And fix the Gopkg.toml files for AWS examples.