From 3542fae64d2eac4911a27d9ac5040771c925e4c6 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 30 Sep 2021 00:38:29 -0400 Subject: [PATCH] Fix tag filtering (#1) It turns out you can't filter on both resource type and tags at the same time, which means checking type needs to happen in code. Additionally, you can't request provisioning state because populating $expand also does bad things when using tags in filters. --- plugin/const.go | 1 - plugin/plugin.go | 10 +++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/plugin/const.go b/plugin/const.go index 1da7c8f..3287e24 100644 --- a/plugin/const.go +++ b/plugin/const.go @@ -9,7 +9,6 @@ const ( constCredsLastRotatedTime = "creds_last_rotated_time" constSecretId = "secret_id" constTenantId = "tenant_id" - constProvisioningState = "provisioningState" constDefaultFilter = "resourceType eq 'Microsoft.Compute/virtualMachines'" constMsComputeService = "Microsoft.Compute" constVirtualMachinesResource = "virtualMachines" diff --git a/plugin/plugin.go b/plugin/plugin.go index f899a5d..40c6c3d 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -333,7 +333,7 @@ func (p *AzurePlugin) ListHosts(ctx context.Context, req *pb.ListHostsRequest) ( // List values matching the filter; ask for provisioning state information // to ensure we are seeing only fully provisioned machines { - iter, err := resClient.ListComplete(ctx, filter, constProvisioningState, nil) + iter, err := resClient.ListComplete(ctx, filter, "", nil) if err != nil { return nil, fmt.Errorf("error listing resources: %w", err) } @@ -345,12 +345,8 @@ func (p *AzurePlugin) ListHosts(ctx context.Context, req *pb.ListHostsRequest) ( if val.ID == nil { // something went wrong, likely iterator has advanced beyond the end continue } - if val.ProvisioningState == nil { - continue - } - switch *val.ProvisioningState { - case string(resources.ProvisioningStateSucceeded): - default: + if val.Type == nil || *val.Type != "Microsoft.Compute/virtualMachines" { + // no point continuing if we can't validate that it's a VM continue } resourceInfos = append(resourceInfos, val)