ansible-collections / azure

Development area for Azure Collections
https://galaxy.ansible.com/azure/azcollection
GNU General Public License v3.0
245 stars 327 forks source link

Support for Data Collecion Rules / Data Collection Rule Associations #1656

Open Klaas- opened 1 month ago

Klaas- commented 1 month ago
SUMMARY

I am currently looking at automating data collection rules and associations via ansible, it does not seem that this is possible yet

ISSUE TYPE
COMPONENT NAME

data-collection-rules https://learn.microsoft.com/en-us/rest/api/monitor/data-collection-rules/create?view=rest-monitor-2023-03-11&tabs=HTTP data-collection-rule-associations https://learn.microsoft.com/en-us/rest/api/monitor/data-collection-rule-associations/create?view=rest-monitor-2023-03-11&tabs=HTTP

ADDITIONAL INFORMATION
azure.azcollection.data_collection_rule_associations:
  [auth settings common to all modules]
  association_name:  "The name of the association. The name is case insensitive." # this seems to always be name of rule concatenated with "-association" 
  scope: subscriptions/NNNN/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVm # ie your VM id for example
  data_collection_endpoint_id: "The resource ID of the data collection endpoint that is to be associated"
  data_collection_rule_id:  "The resource ID of the data collection rule that is to be associated."
  #description: "Description of the association." # I have not figured out where this comes out again, it does not seem to be in the get response :) 

same for the rule creation see request body here: https://learn.microsoft.com/en-us/rest/api/monitor/data-collection-rules/create?view=rest-monitor-2023-03-11&tabs=HTTP#request-body
Klaas- commented 1 month ago

Workaround using azure_rm_deployment (not idempotent):

- name: Create Data Collection Rule Association for new VM
  azure.azcollection.azure_rm_deployment:
    resource_group: "{{ resource_group_name }}"
    name: "{{ inventory_hostname_short }}_data_collection_rule_association"
    location: westus
    template:
      $schema: "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
      contentVersion: "1.0.0.0"
      resources:
        - type: Microsoft.Insights/dataCollectionRuleAssociations
          apiVersion: 2022-06-01
          name: "{{ dcr_name }}-association"
          scope: "{{ vm_id }}"
          properties:
            dataCollectionRuleId: "{{ drc_id }}"