webapp: Error when creating resource group from bash script in Azure Cloud Shell
Describe the bug Error when creating resource group from bash script in Azure Cloud Shell
Command: az group create --location centralus --name myResourceGroup
Error: Parameter 'resource_group_name' must conform to the following pattern: '^[-\w.()]+$'. Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 337, in execute six.reraise(*sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 311, in execute result = cmd(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 171, in call return super(AzCliCommand, self).call(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/knack/commands.py", line 109, in call return self.handler(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 421, in default_command_handler result = op(**command_args) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/resource/custom.py", line 452, in create_resource_group return rcf.resource_groups.create_or_update(rg_name, parameters) File "/opt/az/lib/python3.6/site-packages/azure/mgmt/resource/resources/v2017_05_10/operations/resource_groups_operations.py", line 123, in create_or_update 'resourceGroupName': self.serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w.()]+$'), File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 579, in url data = self.validate(data, name, required=True, **kwargs) File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 659, in validate raise ValidationError(key, name, value) msrest.exceptions.ValidationError: Parameter 'resource_group_name' must conform to the following pattern: '^[-\w.()]+$'.
*To Reproduce Grab sample script from https://docs.microsoft.com/en-us/azure/app-service/scripts/app-service-cli-deploy-local-git and run it as a bash script in Azure Cloud Shell.
myusername@Azure:~/clouddrive/quickstart$ bash webappdeployment.sh
az group create --location centralus --name myResourceGroup
When the script runs the above line fails.
Expected behavior az group create --location centralus --name myResourceGroup The command works fine if it is executed manually.
Environment summary Azure Cloud Shell
Additional context Problem running script in Bash
The name "myResourceGroup" does conform to the required pattern and I am able to create that resource group without issue. You might try running the command with --debug to see if the name being sent to the service is changed.
Assigning to webapps team since it looks like, if there is an issue, it is with their sample script. cc/ @panchagnula
The resource name group is an example. Try the script using a valid resource name group and it will fail
On Thu, Jul 5, 2018, 8:35 AM Travis Prescott [email protected] wrote:
The name "myResourceGroup" does conform to the required pattern and I am able to create that resource group without issue. You might try running the command with --debug to see if the name being sent to the service is changed.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Azure/azure-cli/issues/6721#issuecomment-402723814, or mute the thread https://github.com/notifications/unsubscribe-auth/AWOXNqrqvwKwYtbmERqUsRqG7ejcIe2hks5uDhYqgaJpZM4VCY-Y .
The example resource group name in the script is valid
@asote how exactly are you running the script did you copy the whole script & just paste in cloudshell? i tried it & script failed with other errors expected - however was able to create a RG with the name myResourceGroup. @cephalin as FYI.
@asote what resource group name did you actually try? It might very well not be valid. The one used in the example is valid and I run into no issues creating it.
@tjprescott This is the content of webappdeployment.sh
#!/bin/bash
az group create --location 'centralus' --name 'asResourceGroup'
This is what happens when I run the script in Azure Cloud Shell
antonio@Azure:~/clouddrive/quickstart$ bash webappdeployment.sh Parameter 'resource_group_name' must conform to the following pattern: '^[-\w\.\(\)]+$'. Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 337, in execute six.reraise(*sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 311, in execute result = cmd(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 170, in call return super(AzCliCommand, self).call(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/knack/commands.py", line 109, in call return self.handler(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 421, in default_command_handler result = op(**command_args) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/resource/custom.py", line 488, in create_resource_group return rcf.resource_groups.create_or_update(rg_name, parameters) File "/opt/az/lib/python3.6/site-packages/azure/mgmt/resource/resources/v2018_05_01/operations/resource_groups_operations.py", line 121, in create_or_update 'resourceGroupName': self.serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w.()]+$'), File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 579, in url data = self.validate(data, name, required=True, **kwargs) File "/opt/az/lib/python3.6/site-packages/msrest/serialization.py", line 659, in validate raise ValidationError(key, name, value) msrest.exceptions.ValidationError: Parameter 'resource_group_name' must conform to the following pattern: '^[-\w\.\(\)]+$'.
antonio@Azure:~/clouddrive/quickstart$ az --version azure-cli (2.0.40)
acr (2.0.28) acs (2.1.2) advisor (0.5.1) ams (0.1.1) appservice (0.1.36) backup (1.1.2) batch (3.2.4) batchai (0.3.1) billing (0.1.8) cdn (0.0.14) cloud (2.0.15) cognitiveservices (0.1.13) command-modules-nspkg (2.0.1) configure (2.0.17) consumption (0.3.1) container (0.2.0) core (2.0.40) cosmosdb (0.1.21) dla (0.1.0) dls (0.0.22) dms (0.0.1) eventgrid (0.1.12) eventhubs (0.1.3) extension (0.1.0) feedback (2.1.3) find (0.2.11) interactive (0.3.24) iot (0.1.21) keyvault (2.0.23) lab (0.0.22) maps (0.2.0) monitor (0.1.8) network (2.1.5) nspkg (3.0.2) policyinsights (0.1.0) profile (2.0.27) rdbms (0.2.5) redis (0.2.14) reservations (0.2.1) resource (2.0.32) role (2.0.26) servicebus (0.1.2) servicefabric (0.0.12) sql (2.0.27) storage (2.0.35) vm (2.0.35)
Extensions: webapp (0.2.6)
Python location '/opt/az/bin/python3' Extensions directory '/home/antonio/.azure/cliextensions'
Python (Linux) 3.6.1 (default, Jun 28 2018, 16:28:57) [GCC 5.4.0 20160609]
Legal docs and information: aka.ms/AzureCliLegal
And if you try it without the quotes?
Closing as we are unable to repro.
Just had this and was caused by using CRLF endings in my bash script file.
I changed them to LF and the problem was solved.
I figured it out by echoing a variable and seeing it had a \r on the end.
I'm following the guide and I get this error. I haven't set "resource_group_name" to begin with. I have no idea how to change CRLF to LF endings.
Reading further, it says "The az webapp up command does the following actions: Create a default resource group."
So the default resource group that 'az webapp' creates does not conform to the pattern?
@ronaldgreeff are you running the az web app up command? What error are you getting? This thread talks of a couple of errors.
I have no idea how to change CRLF to LF endings.
There are multiple ways to do this but the easiest is to open the file in a suitable editor, I use VSCode, and then access the file properties and change the line endings.
In VSCode this can be done from the bottom status bar for a file:

Just change CRLF to LF and save the file.
@panchagnula - the error is the error which this thread is about. I use " az webapp up --name
So if I'm not mistaken, Azure issues a 'resource group name' that fail Azure's own validation for naming conventions.... 🤦
@sebastianrogers - thanks. I have tried "az webapp up" without any files in the directory, so I don't actually think my issue is with any files.
@ronaldgreeff its not the files but the script your using to run the commands, check it's end of line encoding.
@ronaldgreeff I can see how the error message from the backend make you believe that Azure is failing its own validation. Looking at the Guide you have referred to - it gives you a sample to download & run the command from this directory. Please try that.
Also, few things you can try
- Please type the command out instead of Copy pasting - the script copied might have line encoding
- Run the command with --dryrun to see what RG values the command will be using
- If up command is creating a new RG then this is not the format it follows 'cloud-shell-storage-northeurope' , I can assure this RG was not created by the az webapp up command.
- you can try to debug this further by running the command by running with --debug flag
If you still have problems with the command, please share more information like
- The version to azure-cli you are using
- the error details you see when you run the command with --debug, (please feel free to remove any info or details you might not be comfortable sharing)