ERROR: (ResourceGroupNotFound) Resource group 'resource_group_name' could not be found.

41653606 0 Reputation points
2023-08-08T06:46:33.26+00:00

I am trying to create a NSG rule under a particular resource group in the Azure pipelines and the way I am trying to do it is as shown below and I get the following error (ERROR: (ResourceGroupNotFound) Resource group 'resource_group_name' could not be found) when I execute the pipeline. Is this is a matter of permission on the subscription level or am I doing something wrong with my pipeline?

task: AzureCLI@2
        displayName: 'Create NSG rule'
        inputs:
          azureSubscription: '@Azure / Management Group / eXtollo PROD / Owner'
          scriptType: 'bash'
          scriptLocation: 'inlineScript'
          inlineScript: |
            source_ip=$(curl -s ifconfig.me/ip)
            az network nsg rule create \
              --name DevopsAgentInbound \
              --nsg-name eu_aviatrix_network_security_group_prod \
              --resource-group eu_mgmt_resource_group_prod \
              --subscription GC3_eXtollo-networkhub-eu-prod \
              --priority 100 \
              --source-address-prefixes $source_ip \
              --destination-port-ranges 443 \
              --protocol '*'\
              --access Allow 
Community Center | Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Ramya Harinarthini_MSFT 5,366 Reputation points Microsoft Employee Moderator
    2023-08-08T07:28:02.16+00:00


    41653606
    Welcome to Microsoft Q&A, Thank you for posting your here!!

    This kind of error occurs usually occurs when you have not set Subscription context.

    Error Code: (ResourceGroupNotFound)

    Error Description: Resource group 'resource_group_name' could not be found.

    Make sure you are operating within the correct subscription context. If you have multiple subscriptions, ensure you are in the correct subscription that contains the desired resource group.

    To set the Subscription context from AZ CLI use the below command.

    az account set --subscription "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

    Reference Article: https://learn.microsoft.com/en-us/cli/azure/manage-azure-subscriptions-azure-cli#change-the-active-subscription

    You have an example here for setting up in YAML https://stackoverflow.com/questions/58356365/azure-devops-fill-azure-subscription-field-using-variables#:~:text=If%20you%20use%20YAML%20pipelines%20you%20could%20configure,every%20build%20you%20can%20override%20your%20azure%20subscription.

    Hope this helps!
    Kindly let us know if the above helps or you need further assistance on this issue.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.