Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Go Azure examples to fnOutput form #1154

Merged
merged 11 commits into from
Jan 21, 2022
Prev Previous commit
Next Next commit
azure-go-appservice-docker updated azure-native dependency. changed i…
…mage to pull since the old image 404s. refactored to use fnOutput form
  • Loading branch information
Kyle Dixler committed Jan 19, 2022
commit 8c22bec2363245bced0510d68bec3e4051b3100c
37 changes: 35 additions & 2 deletions azure-go-appservice-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,42 @@ The example shows two scenarios:

```
$ pulumi stack output helloEndpoint
http:https://hello-app-91dfea.azurewebsites.net/hello
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the image to an image that exists so I updated the README with the expected outputs.

https:https://helloappecc2f992.azurewebsites.net
$ curl "$(pulumi stack output helloEndpoint)"
Hello, world!
<html>
<head>
<title>Welcome to Azure Container Instances!</title>
</head>
<style>
h1 {
color: darkblue;
font-family:arial, sans-serif;
font-weight: lighter;
}
</style>

<body>

<div align="center">
<h1>Welcome to Azure Container Instances!</h1>

<svg id="Layer_1" data-name="Layer 1" xmlns="http:https://www.w3.org/2000/svg" viewBox="0 0 49.8 49.9" width="250px" height="250px">
<title>ContainerInstances_rgb_UI</title>
<path d="M41.9,11.368A11.929,11.929,0,0,0,20.3,5.061a9.444,9.444,0,0,0-14.932,9.8A8.969,8.969,0,0,0,9.064,32H39.442A10.463,10.463,0,0,0,41.9,11.368Z" transform="translate(-0.1 -0.1)" fill="#fff"/>
<path d="M41.9,11.368A11.929,11.929,0,0,0,20.3,5.061a9.444,9.444,0,0,0-14.932,9.8A8.969,8.969,0,0,0,9.064,32H39.442A10.463,10.463,0,0,0,41.9,11.368Z" transform="translate(-0.1 -0.1)" fill="#27a9e1" opacity="0.6" style="isolation:isolate"/>
<path d="M13,22a1,1,0,0,0-1,1V49a1,1,0,0,0,1,1H37a1,1,0,0,0,1-1V23a1,1,0,0,0-1-1Z" transform="translate(-0.1 -0.1)" fill="#672a7a"/>
<path d="M26.95,16" transform="translate(-0.1 -0.1)" fill="none"/>
<path d="M34.95,20" transform="translate(-0.1 -0.1)" fill="none"/>
<polygon points="22.9 21.9 22.9 14.9 19.9 14.9 24.9 7.9 29.9 14.9 26.9 14.9 26.9 21.9 22.9 21.9" fill="#fff"/>
<path d="M26.95,16" transform="translate(-0.1 -0.1)" fill="#814a98"/>
<path d="M33,25H15V47H35V25ZM21,45H17V27h4Zm6,0H23V27h4Zm6,0H29V27h4Z" transform="translate(-0.1 -0.1)" fill="#b92025" opacity="0.3" style="isolation:isolate"/>
<path d="M33,25H15V47H35V25ZM21,45H17V27h4Zm6,0H23V27h4Zm6,0H29V27h4Z" transform="translate(-0.1 -0.1)" fill="#fff" style="isolation:isolate"/>
</svg>
</div>

</body>
</html>


$ pulumi stack output getStartedEndpoint
http:https://get-started-15da13.azurewebsites.net
Expand Down
4 changes: 2 additions & 2 deletions azure-go-appservice-docker/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/pulumi/examples/azure-go-appservice
go 1.15

require (
github.com/pulumi/pulumi-azure-native/sdk v1.0.0
github.com/pulumi/pulumi-azure-native/sdk v1.53.0
github.com/pulumi/pulumi-docker/sdk/v3 v3.0.0
github.com/pulumi/pulumi/sdk/v3 v3.0.0
github.com/pulumi/pulumi/sdk/v3 v3.20.0
)
9 changes: 9 additions & 0 deletions azure-go-appservice-docker/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ github.com/pulumi/pulumi-azure-native/sdk v0.7.1 h1:ss2Gm8tz+Z/5NG95tzZaNzR4wJE0
github.com/pulumi/pulumi-azure-native/sdk v0.7.1/go.mod h1:+sOZTR3B8SmjeJ+uiLjz9FCFj9VruMZf1lW846ZdKcE=
github.com/pulumi/pulumi-azure-native/sdk v1.0.0 h1:hkt1SRMuKPMgDzQrERbz/Ev9K0OtO4+C6t4gE/gyFM0=
github.com/pulumi/pulumi-azure-native/sdk v1.0.0/go.mod h1:+6SXTdCHr4vvAW7UUpYqJwXfF2nqDSVKHOs0zXOlfBY=
github.com/pulumi/pulumi-azure-native/sdk v1.53.0 h1:jrcGpA4NKH42yV9O76EVpSF8I93aeKB9Fae7M4kb1L0=
github.com/pulumi/pulumi-azure-native/sdk v1.53.0/go.mod h1:9uZoN23JHENKfngVUlZdFr1eRYXpRF8saW5eSASw0tY=
github.com/pulumi/pulumi-docker/sdk/v2 v2.3.0 h1:kFSIB16HVNW+TyOSG6ULr0S9PpsnRtP2SLA6esklL98=
github.com/pulumi/pulumi-docker/sdk/v2 v2.3.0/go.mod h1:J0I8pec653rvuAZNKpNxLj6ZuIKutcRDP+4iYUuD504=
github.com/pulumi/pulumi-docker/sdk/v3 v3.0.0 h1:torA+0p0G14PaEmK9RO2/bvXsWeuko5Y+en+dJsUNPU=
Expand All @@ -258,6 +260,10 @@ github.com/pulumi/pulumi/sdk/v2 v2.21.2/go.mod h1:fCFhRV6NmidWetmgDPA76efL+s0JqL
github.com/pulumi/pulumi/sdk/v3 v3.0.0-beta.1/go.mod h1:of2on912OvQZLA33FfNUcTEgRrTId7jvk9yFuvtaV88=
github.com/pulumi/pulumi/sdk/v3 v3.0.0 h1:zkragE05t1Rco/ymfqMU4UXdEmKMmOH0SXhUKQxujxQ=
github.com/pulumi/pulumi/sdk/v3 v3.0.0/go.mod h1:GBHyQ7awNQSRmiKp/p8kIKrGrMOZeA/k2czoM/GOqds=
github.com/pulumi/pulumi/sdk/v3 v3.20.0 h1:GBQ0sBepo3W2xQm/osMD6JDC02qiMQwK4q4Yi4bdkHk=
github.com/pulumi/pulumi/sdk/v3 v3.20.0/go.mod h1:AnbQmAhp0ezO/MhcVjqkhvoQnxZ0+79Xb035NcuKrtM=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af h1:gu+uRPtBe88sKxUCEXRoeCvVG90TJmwhiqRpvdhQFng=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
Expand Down Expand Up @@ -400,6 +406,8 @@ golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 h1:OjiUf46hAmXblsZdnoSXsEUSKU8r1UEzcL5RVZ4gO9Y=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2 h1:c8PlLMqBbOHoqtjteWm5/kbe6rNY2pbRfbIMVnepueo=
golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down Expand Up @@ -484,5 +492,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc h1:/hemPrYIhOhy8zYrNj+069zDB68us2sMGsfkFJO0iZs=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0 h1:ucqkfpjg9WzSUubAO62csmucvxl4/JeW3F4I4909XkM=
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
28 changes: 8 additions & 20 deletions azure-go-appservice-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
// The example uses a HelloWorld application written in Go.
// Image: https://hub.docker.com/r/microsoft/azure-appservices-go-quickstart/
//
imageInDockerHub := "microsoft/azure-appservices-go-quickstart"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this image was 404'ing

I replaced it with an nginx base image since it's about deploying an image from docker hub

imageInDockerHub := "mcr.microsoft.com/azuredocs/aci-helloworld"
helloApp, err := web.NewWebApp(ctx, "helloApp", &web.WebAppArgs{
ResourceGroupName: resourceGroup.Name,
ServerFarmId: plan.ID(),
Expand All @@ -57,7 +57,7 @@ func main() {
}

ctx.Export("helloEndpoint", helloApp.DefaultHostName.ApplyT(func(defaultHostName string) (string, error) {
return fmt.Sprintf("%v%v%v", "https://", defaultHostName, "/hello"), nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the nginx image doesn't have a /hello route

return fmt.Sprintf("%v%v", "https://", defaultHostName), nil
}).(pulumi.StringOutput))

//
Expand All @@ -75,25 +75,13 @@ func main() {
return err
}

credentials := pulumi.All(resourceGroup.Name, registry.Name).ApplyT(
func(args []interface{}) (*containerregistry.ListRegistryCredentialsResult, error) {
resourceGroupName := args[0].(string)
registryName := args[1].(string)
return containerregistry.ListRegistryCredentials(ctx, &containerregistry.ListRegistryCredentialsArgs{
ResourceGroupName: resourceGroupName,
RegistryName: registryName,
})
},
)
credentials := containerregistry.ListRegistryCredentialsOutput(ctx, containerregistry.ListRegistryCredentialsOutputArgs{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

RegistryName: registry.Name,
ResourceGroupName: resourceGroup.Name,
})

adminUsername := credentials.ApplyT(func(result interface{}) (string, error) {
credentials := result.(*containerregistry.ListRegistryCredentialsResult)
return *credentials.Username, nil
}).(pulumi.StringOutput)
adminPassword := credentials.ApplyT(func(result interface{}) (string, error) {
credentials := result.(*containerregistry.ListRegistryCredentialsResult)
return *credentials.Passwords[0].Value, nil
}).(pulumi.StringOutput)
adminUsername := credentials.Username().Elem()
adminPassword := credentials.Passwords().Index(pulumi.Int(0)).Value().Elem()

myImage, err := docker.NewImage(ctx, customImage, &docker.ImageArgs{
ImageName: registry.LoginServer.ApplyT(func(result string) (string, error) {
Expand Down