Skip to content

Commit c305d86

Browse files
authored
Merge pull request #3 from UpboundCare/add-target-api
Implement Target API
2 parents f215ad2 + 0a7c6d5 commit c305d86

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

example/composition-with-mgmt-groups.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ spec:
1616
kind: Input
1717
query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
1818
managementGroups: ["example"]
19+
target: "status.azResourceGraphQueryResult"
1920
credentials:
2021
- name: azure-creds
2122
source: Secret

example/composition.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec:
1515
apiVersion: azresourcegraph.fn.crossplane.io/v1alpha1
1616
kind: Input
1717
query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
18+
target: "status.azResourceGraphQueryResult"
1819
credentials:
1920
- name: azure-creds
2021
source: Secret

fn.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import (
1717
"github.com/crossplane/function-sdk-go/response"
1818
)
1919

20-
// TargetXRStatusField is the target field to write the query result to
21-
const TargetXRStatusField = "status.azResourceGraphQueryResult"
22-
2320
// AzureQueryInterface defines the methods required for querying Azure resources.
2421
type AzureQueryInterface interface {
2522
azQuery(ctx context.Context, azureCreds map[string]string, in *v1beta1.Input) (armresourcegraph.ClientResourcesResponse, error)
@@ -104,6 +101,8 @@ func (f *Function) RunFunction(ctx context.Context, req *fnv1.RunFunctionRequest
104101
return rsp, nil
105102
}
106103

104+
TargetXRStatusField := in.Target
105+
107106
err = dxr.Resource.SetValue(TargetXRStatusField, &results.Data)
108107
if err != nil {
109108
response.Fatal(rsp, errors.Wrapf(err, "cannot set field %s to %s for %s", TargetXRStatusField, results.Data, dxr.Resource.GetKind()))

fn_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ func TestRunFunction(t *testing.T) {
117117
"apiVersion": "azresourcegraph.fn.crossplane.io/v1alpha1",
118118
"kind": "Input",
119119
"query": "Resources| count",
120-
"managementGroups": ["test"]
120+
"managementGroups": ["test"],
121+
"target": "status.azResourceGraphQueryResult"
121122
}`),
122123
Observed: &fnv1.State{
123124
Composite: &fnv1.Resource{

input/v1beta1/input.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ type Input struct {
2424

2525
// Query to Azure Resource Graph API
2626
Query string `json:"query"`
27+
2728
// Azure management groups against which to execute the query. Example: [ 'mg1', 'mg2' ]
2829
// +optional
2930
ManagementGroups []*string `json:"managementGroups,omitempty"`
31+
32+
// Target where to store the Query Result
33+
Target string `json:"target"`
3034
}

package/input/azresourcegraph.fn.crossplane.io_inputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ spec:
4747
query:
4848
description: Query to Azure Resource Graph API
4949
type: string
50+
target:
51+
description: Target where to store the Query Result
52+
type: string
5053
required:
5154
- query
55+
- target
5256
type: object
5357
served: true
5458
storage: true

0 commit comments

Comments
 (0)