|
1 | | -# function-template-go |
2 | | -[](https://github.com/crossplane/function-template-go/actions/workflows/ci.yml) |
| 1 | +# function-azresourcegraph |
| 2 | +[](https://github.com/UpboundCare/function-azresourcegraph/actions/workflows/ci.yml) |
3 | 3 |
|
4 | | -A template for writing a [composition function][functions] in [Go][go]. |
| 4 | +A function to query [Azure Resource Graph][azresourcegraph] |
5 | 5 |
|
6 | | -To learn how to use this template: |
| 6 | +## Usage |
7 | 7 |
|
8 | | -* [Follow the guide to writing a composition function in Go][function guide] |
9 | | -* [Learn about how composition functions work][functions] |
10 | | -* [Read the function-sdk-go package documentation][package docs] |
| 8 | +See [examples][examples] |
11 | 9 |
|
12 | | -If you just want to jump in and get started: |
| 10 | +Example pipeline step: |
13 | 11 |
|
14 | | -1. Replace `function-template-go` with your function in `go.mod`, |
15 | | - `package/crossplane.yaml`, and any Go imports. (You can also do this |
16 | | - automatically by running the `./init.sh <function-name>` script.) |
17 | | -1. Update `input/v1beta1/` to reflect your desired input (and run `go generate`) |
18 | | -1. Add your logic to `RunFunction` in `fn.go` |
19 | | -1. Add tests for your logic in `fn_test.go` |
20 | | -1. Update this file, `README.md`, to be about your function! |
21 | | - |
22 | | -This template uses [Go][go], [Docker][docker], and the [Crossplane CLI][cli] to |
23 | | -build functions. |
24 | | - |
25 | | -```shell |
26 | | -# Run code generation - see input/generate.go |
27 | | -$ go generate ./... |
| 12 | +```yaml |
| 13 | + pipeline: |
| 14 | + - step: query-azresourcegraph |
| 15 | + functionRef: |
| 16 | + name: function-azresourcegraph |
| 17 | + input: |
| 18 | + apiVersion: azresourcegraph.fn.crossplane.io/v1alpha1 |
| 19 | + kind: Input |
| 20 | + query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc" |
| 21 | + credentials: |
| 22 | + - name: azure-creds |
| 23 | + source: Secret |
| 24 | + secretRef: |
| 25 | + namespace: upbound-system |
| 26 | + name: azure-account-creds |
| 27 | +``` |
28 | 28 |
|
29 | | -# Run tests - see fn_test.go |
30 | | -$ go test ./... |
| 29 | +The Azure Credentials Secret structure is fully compatible with the standard |
| 30 | +[Azure Official Provider][azop] |
31 | 31 |
|
32 | | -# Build the function's runtime image - see Dockerfile |
33 | | -$ docker build . --tag=runtime |
| 32 | +Example XR status after e2e query: |
34 | 33 |
|
35 | | -# Build a function package - see package/crossplane.yaml |
36 | | -$ crossplane xpkg build -f package --embed-runtime-image=runtime |
| 34 | +```yaml |
| 35 | +apiVersion: example.crossplane.io/v1 |
| 36 | +kind: XR |
| 37 | +metadata: |
| 38 | +... |
| 39 | +status: |
| 40 | + azResourceGraphQueryResult: |
| 41 | + - id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vm-zxqnj-s2jdb/providers/Microsoft.Compute/virtualMachines/us-vm-zxqnj-2h59v |
| 42 | + location: centralus |
| 43 | + name: us-vm-zxqnj-2h59v |
| 44 | + type: microsoft.compute/virtualmachines |
| 45 | + - id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vm-lzbpt-tdv2h/providers/Microsoft.Compute/virtualMachines/us-vm-lzbpt-fgcds |
| 46 | + location: centralus |
| 47 | + name: us-vm-lzbpt-fgcds |
| 48 | + type: microsoft.compute/virtualmachines |
| 49 | + - id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vac-dr27h-ttsq5/providers/Microsoft.Compute/virtualMachines/us-vac-dr27h-t7dhd |
| 50 | + location: centralus |
| 51 | + name: us-vac-dr27h-t7dhd |
| 52 | + type: microsoft.compute/virtualmachines |
| 53 | + - id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/my-vm-mm59z/providers/Microsoft.Compute/virtualMachines/my-vm-jm8g2 |
| 54 | + location: swedencentral |
| 55 | + name: my-vm-jm8g2 |
| 56 | + type: microsoft.compute/virtualmachines |
| 57 | + - id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/javid-labs/providers/Microsoft.Compute/virtualMachines/devstack-test |
| 58 | + location: westus2 |
| 59 | + name: devstack-test |
| 60 | + type: microsoft.compute/virtualmachines |
37 | 61 | ``` |
38 | 62 |
|
39 | | -[functions]: https://docs.crossplane.io/latest/concepts/composition-functions |
40 | | -[go]: https://go.dev |
41 | | -[function guide]: https://docs.crossplane.io/knowledge-base/guides/write-a-composition-function-in-go |
42 | | -[package docs]: https://pkg.go.dev/github.com/crossplane/function-sdk-go |
43 | | -[docker]: https://www.docker.com |
44 | | -[cli]: https://docs.crossplane.io/latest/cli |
| 63 | +
|
| 64 | +[azresourcegraph]: https://learn.microsoft.com/en-us/azure/governance/resource-graph/ |
| 65 | +[azop]: https://marketplace.upbound.io/providers/upbound/provider-family-azure/latest |
| 66 | +[examples]: ./example |
0 commit comments