Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/composition-with-mgmt-groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions example/composition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()))
Expand Down
3 changes: 2 additions & 1 deletion fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 4 additions & 0 deletions input/v1beta1/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
4 changes: 4 additions & 0 deletions package/input/azresourcegraph.fn.crossplane.io_inputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading