Skip to content

Commit f8b9e06

Browse files
author
Vivek Lakshmanan
authored
Merge pull request pulumi#988 from pulumi/vl/AzureGoCallSDK
Add an example to call Azure SDK Client from Go
2 parents cfeb2c4 + 837641c commit f8b9e06

File tree

6 files changed

+550
-0
lines changed

6 files changed

+550
-0
lines changed

azure-go-call-azure-sdk/Pulumi.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: azure-go-call-azure-sdk
2+
runtime: go
3+
description: An example of integrating an Azure SDK call to a Pulumi program.

azure-go-call-azure-sdk/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)
2+
3+
# Demo of Integrating the native Azure Pulumi provider with the Microsoft Azure SDK
4+
5+
The native Azure Pulumi provider exposes the entire resource model of Azure Resource Manager. Each resource can be created, updated, deleted, or refreshed (read).
6+
7+
However, Azure API has many endpoints that don't map to our resource model. For examples, finding resources given some filter criteria is not supported directly.
8+
9+
However, you can easily integrate an Azure SDK call inside your Pulumi program using the same programming language. We provide a helper function `authorization.GetClientToken()` that returns a valid authentication token for the same login context that the Pulumi provider is using.
10+
11+
This example demonstrates how to use such integration to lookup a role definition ID based on its name and scope. It then creates a role assignment for the resulting definition to allow pulling container images from a registry.
12+
13+
## Running the App
14+
15+
1. Create a new stack:
16+
17+
```
18+
$ pulumi stack init dev
19+
```
20+
21+
1. Login to Azure CLI (you will be prompted to do this during deployment if you forget this step):
22+
23+
```
24+
$ az login
25+
```
26+
27+
1. Set the Azure region location to use:
28+
29+
```
30+
$ pulumi config set azure-native:location WestUS
31+
```
32+
33+
1. Run `pulumi up` to preview and deploy changes:
34+
35+
```
36+
$ pulumi up
37+
Previewing changes:
38+
...
39+
Performing changes:
40+
...
41+
Resources:
42+
~ 1 updated
43+
3 unchanged
44+
```

azure-go-call-azure-sdk/go.mod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module azure-go-call-azure-sdk
2+
3+
go 1.16
4+
5+
require (
6+
github.com/Azure/azure-sdk-for-go v53.4.0+incompatible
7+
github.com/Azure/go-autorest/autorest v0.11.18
8+
github.com/Azure/go-autorest/autorest/adal v0.9.13
9+
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
10+
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
11+
github.com/pulumi/pulumi-azure-native/sdk v1.2.0
12+
github.com/pulumi/pulumi/sdk/v3 v3.0.0
13+
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
14+
)

0 commit comments

Comments
 (0)