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
improved azure-go-aks example
  • Loading branch information
Kyle Dixler committed Jan 21, 2022
commit b740088095e26279cd435063d10feac1598dca77
38 changes: 16 additions & 22 deletions azure-go-aks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,6 @@ import (
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func getKubeconfig(ctx *pulumi.Context, cluster *containerservice.ManagedCluster, resourceGroup *resources.ResourceGroup) pulumi.Output {
kubeconfig := pulumi.All(cluster.Name, resourceGroup.Name, resourceGroup.ID()).ApplyT(func(args interface{}) (string, error) {
clusterName := args.([]interface{})[0].(string)
resourceGroupName := args.([]interface{})[1].(string)
creds, err := containerservice.ListManagedClusterUserCredentials(ctx, &containerservice.ListManagedClusterUserCredentialsArgs{
ResourceGroupName: resourceGroupName,
ResourceName: clusterName,
})
if err != nil {
return "", err
}
encoded := creds.Kubeconfigs[0].Value
kubeconfig, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
return "", err
}
return string(kubeconfig), nil
})
return kubeconfig
}

func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Create an Azure Resource Group
Expand Down Expand Up @@ -120,7 +99,22 @@ func main() {
return err
}

ctx.Export("kubeconfig", getKubeconfig(ctx, cluster, resourceGroup))
creds := containerservice.ListManagedClusterUserCredentialsOutput(ctx,
containerservice.ListManagedClusterUserCredentialsOutputArgs{
ResourceGroupName: resourceGroup.Name,
ResourceName: cluster.Name,
})

kubeconfig := creds.Kubeconfigs().Index(pulumi.Int(0)).Value().
ApplyT(func(encoded string) string {
kubeconfig, err := base64.StdEncoding.DecodeString(encoded)
Copy link
Member

Choose a reason for hiding this comment

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

Looking good I'm just paranoid about go runtime errors , sometimes Go compiles but throws a runtime error; running this would be invaluable (unless it's included in CI).

if err != nil {
return ""
}
return string(kubeconfig)
})

ctx.Export("kubeconfig", kubeconfig)

return nil
})
Expand Down