Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network flowlog create does not appear to use supplied location #1814

Open
hctagalong opened this issue Jan 28, 2025 · 0 comments
Open

Network flowlog create does not appear to use supplied location #1814

hctagalong opened this issue Jan 28, 2025 · 0 comments
Labels
medium_priority Medium priority work in In trying to solve, or in working with contributors

Comments

@hctagalong
Copy link

SUMMARY

When attempting to create an Azure network flowlog using azure.azcollection.azure_rm_networkflowlog, the location parameter does not appear to be honored.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

azure_rm_networkflowlog

ANSIBLE VERSION
/usr/lib/python3.11/site-packages/paramiko/pkey.py:82: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "cipher": algorithms.TripleDES,
/usr/lib/python3.11/site-packages/paramiko/transport.py:256: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from this module in 48.0.0.
  "class": algorithms.TripleDES,
ansible [core 2.14.5]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.10 (main, Sep 11 2024, 21:23:52) [GCC 12.2.1 20220924] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
Collection         Version
------------------ -------
azure.azcollection 2.7.0  
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT

Azure

STEPS TO REPRODUCE

Setup:

  • My NetworkWatcherRG resource group was created in Central US.
  • I have NetworkWatchers in both Central US and NorthCentral US.
  • Looping over my 3 vNets where 2 are located in Central US and 1 is located in NorthCentral US, only the 2 in Central US are created and the 3rd throws this error:
    "msg": "Error creating Flow Log vnet-northcentralus-dev-myflowlog-1_flowlog - (InvalidFlowLogTargetResource) Target resource /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-ncsu-my-resource-group-1/providers/Microsoft.Network/virtualNetworks/vnet-northcentralus-dev-myflowlog-1 passed for the flow log is invalid.\nCode: InvalidFlowLogTargetResource\nMessage: Target resource /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-ncsu-my-resource-group-1/providers/Microsoft.Network/virtualNetworks/vnet-northcentralus-dev-myflowlog-1 passed for the flow log is invalid."}

As a test, using the azCLI, I can successfully create the flowlog for the vNet in NorthCentral. azCLI command used:
az network watcher flow-log create --location northcentralus --resource-group rg-ncus-my-resource-group-1 --name vnet-northcentralus-dev-myflowlog-1_flowlog --vnet vnet-northcentralus-dev-myflowlog-1 --storage-account /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-northcentralus-networkwatcher-myresources-1/providers/Microsoft.Storage/storageAccounts/strnorthcentralusnw

After the test validating that using azCLI will create the desired flowlog, when I rerun my playbook, I observe a different error that implies that the flowlog is attempting to be created in centralus even when northcentralus is specified as the location in my vars file:
"msg": "Error creating Flow Log vnet-northcentralus-dev-myflowlog-1_flowlog - (InvalidResourceLocation) The resource 'NetworkWatcher_northcentralus/vnet-northcentralus-dev-myflowlog-1_flowlog' already exists in location 'northcentralus' in resource group 'NetworkWatcherRG'. A resource with the same name cannot be created in location 'centralus'. Please select a new resource name.\nCode: InvalidResourceLocation\nMessage: The resource 'NetworkWatcher_northcentralus/vnet-northcentralus-dev-myflowlog-1_flowlog' already exists in location 'northcentralus' in resource group 'NetworkWatcherRG'. A resource with the same name cannot be created in location 'centralus'. Please select a new resource name."}

Example playbook task:

- name: Enable vNet flowlog
  azure.azcollection.azure_rm_networkflowlog:
    subscription_id: "{{item['subscription'] }}"
    location: "{{ item['region'] }}"
    resource_group: "{{ networkwatcher_default_rg_name }}"
    network_watcher_name: "{{ networkwatcher_default_name_prefix }}_{{ item['region'] }}"
    name: "{{ item['name'] }}_flowlog"
    enabled: "{{ item['flowlogs_enable'] }}"
    retention_policy:
      days: "{{ item['flowlogs_retention_days'] }}"
      enabled: "{{ item['flowlogs_retention_enable'] }}"
    storage_id: "/subscriptions/{{ nw_auxiliary_resources_subscription }}/resourceGroups/rg-{{ nw_auxiliary_resources_rg_region }}-{{ nw_auxiliary_resources_rg_basename }}/providers/Microsoft.Storage/storageAccounts/str{{ item['region'] }}nw"
    target_resource_id: "/subscriptions/{{ item['subscription'] }}/resourceGroups/{{ item['resource_group'] }}/providers/Microsoft.Network/virtualNetworks/{{ item['name'] }}"
  loop: "{{ vnets }}"

Example vars:

networkwatcher_default_name_prefix: NetworkWatcher
networkwatcher_default_rg_name: NetworkWatcherRG
nw_auxiliary_resources_subscription: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
nw_auxiliary_resources_rg_region: northcentralus
nw_auxiliary_resources_rg_basename: networkwatcher-myresources-1

vnets:
- name: vnet-centralus-dev-myflowlog-1
  region: centralus
  subscription: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  resource_group: rg-cus-my-resource-group-1
  flowlogs_enable: true
  flowlogs_retention_enable: true
  flowlogs_retention_days: 15
- name: vnet-centralus-dev-myflowlog-2
  region: centralus
  subscription: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  resource_group: rg-cus-my-resource-group-1
  flowlogs_enable: true
  flowlogs_retention_enable: true
  flowlogs_retention_days: 15
- name: vnet-northcentralus-dev-myflowlog-1
  region: northcentralus
  subscription: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  resource_group: rg-ncus-my-resource-group-1
  flowlogs_enable: true
  flowlogs_retention_enable: true
  flowlogs_retention_days: 15
EXPECTED RESULTS

Upon successful playbook run, I expect to have 3 network flow logs where 2 are created in centralus and 1 is created in northcentralus.

ACTUAL RESULTS

The flow logs for Central US are created as expected. The third flow log encounters the following error:
"msg": "Error creating Flow Log vnet-northcentralus-dev-myflowlog-1_flowlog - (InvalidFlowLogTargetResource) Target resource /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-ncsu-my-resource-group-1/providers/Microsoft.Network/virtualNetworks/vnet-northcentralus-dev-myflowlog-1 passed for the flow log is invalid.\nCode: InvalidFlowLogTargetResource\nMessage: Target resource /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg-ncsu-my-resource-group-1/providers/Microsoft.Network/virtualNetworks/vnet-northcentralus-dev-myflowlog-1 passed for the flow log is invalid."}

Error output noted above.
@Fred-sun Fred-sun added medium_priority Medium priority work in In trying to solve, or in working with contributors labels Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority work in In trying to solve, or in working with contributors
Projects
None yet
Development

No branches or pull requests

2 participants