diff --git a/example/composition-with-mgmt-groups.yaml b/example/composition-with-mgmt-groups.yaml index d8879c5..51ad33c 100644 --- a/example/composition-with-mgmt-groups.yaml +++ b/example/composition-with-mgmt-groups.yaml @@ -16,6 +16,7 @@ spec: kind: Input query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc" managementGroups: ["example"] + target: "status.azResourceGraphQueryResult" credentials: - name: azure-creds source: Secret diff --git a/example/composition.yaml b/example/composition.yaml index 471f2e0..dbd38b1 100644 --- a/example/composition.yaml +++ b/example/composition.yaml @@ -15,6 +15,7 @@ spec: apiVersion: azresourcegraph.fn.crossplane.io/v1alpha1 kind: Input query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc" + target: "status.azResourceGraphQueryResult" credentials: - name: azure-creds source: Secret diff --git a/fn.go b/fn.go index b9b1cf3..4a6a217 100644 --- a/fn.go +++ b/fn.go @@ -17,9 +17,6 @@ import ( "github.com/crossplane/function-sdk-go/response" ) -// TargetXRStatusField is the target field to write the query result to -const TargetXRStatusField = "status.azResourceGraphQueryResult" - // AzureQueryInterface defines the methods required for querying Azure resources. type AzureQueryInterface interface { 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 return rsp, nil } + TargetXRStatusField := in.Target + err = dxr.Resource.SetValue(TargetXRStatusField, &results.Data) if err != nil { response.Fatal(rsp, errors.Wrapf(err, "cannot set field %s to %s for %s", TargetXRStatusField, results.Data, dxr.Resource.GetKind())) diff --git a/fn_test.go b/fn_test.go index f7846c8..c57c219 100644 --- a/fn_test.go +++ b/fn_test.go @@ -117,7 +117,8 @@ func TestRunFunction(t *testing.T) { "apiVersion": "azresourcegraph.fn.crossplane.io/v1alpha1", "kind": "Input", "query": "Resources| count", - "managementGroups": ["test"] + "managementGroups": ["test"], + "target": "status.azResourceGraphQueryResult" }`), Observed: &fnv1.State{ Composite: &fnv1.Resource{ diff --git a/input/v1beta1/input.go b/input/v1beta1/input.go index aaff1db..46097e6 100644 --- a/input/v1beta1/input.go +++ b/input/v1beta1/input.go @@ -24,7 +24,11 @@ type Input struct { // Query to Azure Resource Graph API Query string `json:"query"` + // Azure management groups against which to execute the query. Example: [ 'mg1', 'mg2' ] // +optional ManagementGroups []*string `json:"managementGroups,omitempty"` + + // Target where to store the Query Result + Target string `json:"target"` } diff --git a/package/input/azresourcegraph.fn.crossplane.io_inputs.yaml b/package/input/azresourcegraph.fn.crossplane.io_inputs.yaml index b765bba..ec63055 100644 --- a/package/input/azresourcegraph.fn.crossplane.io_inputs.yaml +++ b/package/input/azresourcegraph.fn.crossplane.io_inputs.yaml @@ -47,8 +47,12 @@ spec: query: description: Query to Azure Resource Graph API type: string + target: + description: Target where to store the Query Result + type: string required: - query + - target type: object served: true storage: true