azure icon indicating copy to clipboard operation
azure copied to clipboard

azure_rm_adserviceprincipal_info returns a empty list

Open paulczar opened this issue 2 years ago • 3 comments

SUMMARY

I'm trying to do the equivalent of this az ad sp list --filter "displayname eq 'Azure Red Hat OpenShift RP'" --query "[?appDisplayName=='Azure Red Hat OpenShift RP'].{objectId: objectId}" -o tsv.

however when I run the following I get an empty list .. which means I can't use a jmesquery or similar to find the correct service principal.

 - name: list service principals
   azure.azcollection.azure_rm_adserviceprincipal_info:
     tenant: "{{ azr_tenant_id }}"
   register: _sp

paulczar avatar Feb 10 '22 21:02 paulczar

@paulczar In this module, if you want to obtain AD SP information, at least one app_id or object_id should be configured. Can you try it on? Thank you very much!

 - name: list service principals
   azure.azcollection.azure_rm_adserviceprincipal_info:
     tenant: "{{ azr_tenant_id }}"
     app_id: "{{ app_id }}"
   register: _sp

or
 - name: list service principals
   azure.azcollection.azure_rm_adserviceprincipal_info:
     tenant: "{{ azr_tenant_id }}"
     object_id: "{{ obuect_id }}"
   register: _sp

Fred-sun avatar Feb 22 '22 13:02 Fred-sun

Here's the problem though, I don't know the app_id or object_id. The scenario is that I want to see if a SP already exists (to ensure creating one is idempotent, but also to determine what to delete when I want to clean up my environment).

I want to be able to do something like this (ignore the syntax errors):

- name: list service principals
   azure.azcollection.azure_rm_adserviceprincipal_info:
     tenant: "{{ azr_tenant_id }}"
     filter: "displayname eq 'Azure Red Hat OpenShift RP'"
   register: _sp

- name: delete ARO service principals
  azure.azcollection.azure_rm_adserviceprincipal:
     tenant: "{{ azr_tenant_id }}"
     app_id: "{{ item.app_id }}"
  with_items: _sp.serviceprincipals

paulczar avatar Feb 24 '22 15:02 paulczar

@paulczar This is a good suggestion and we will discuss internally whether to add filter or return all service pricipals under tenant_id. Thank you very much!

Fred-sun avatar Mar 02 '22 02:03 Fred-sun

#1325 Fixes

Fred-sun avatar Dec 01 '23 01:12 Fred-sun