Use external parameters.json file not working with Azure CLI - azure

I am trying to pass parameters in via the parameter file in Azure Cli
The script below ignores my file
What am I doing wrong?
I have also tried ParameterTemplateFile as mentioned in another post here but that doesnt work either
templateFile="Path\template.json"
parameterFile="Path\parameters.json"
az deployment group create \
--name <NAME> \
--resource-group <RESOURCE GROUP>\
--template-file $templateFile \
--parameter-file $parameterFile

When running via Azure Cli I should have been using #parameters.json

Related

Azure CLI AKS creation with Application Gateway: how to show details?

I am attempting to reverse engineer this command so I can move it into Terraform:
az aks create --resource-group "..." --name "..." \
--network-plugin azure \
--enable-managed-identity \
-a ingress-gateway --appgw-name "myAksGateway" --appgw-subnet-id "..." \
--node-vm-size "..." \
--service-cidr "..." \
--vnet-subnet-id "..." \
--docker-bridge-address "..." \
--dns-service-ip "..." \
--generate-ssh-keys
Everything is going fine except for the Application Gateway part.
Is there any way to ask the Azure CLI to do a dry run and simply show me all the creation data it is using?
I looked at az aks create --help but it didn't have a dry run option.
The basics for azurerm_kubernetes_cluster are straight-forward, as is the azurerm_application_gateway; something is off and I want to see what it is doing under the covers to get it just right. There's some differences I am trying to get ironed out and it would be much easier to just see what it's doing.
I can't run az aks create --debug because of resource limits and the basic JSON output on the AKS resource isn't verbose enough for what I am looking for.
You can't get all the creating data from the CLI command even if you use the parameter --debug, it only shows you the REST API behind the CLI command. You can get all the steps to install the AGIC for the AKS cluster here. Then you can transfer all the steps into Terraform.

How can I install a webapp extension AspNetCoreRuntime.3.0.x86 using Azure CLI?

After installing the latest Az module in Powershell I can install the webapp extension AspNetCoreRuntime.3.0.x86 using the following command:
New-AzResource -ResourceGroupName '<resource-group>' -ResourceType 'Microsoft.Web/sites/siteextensions' -Name '<webapp-name>/AspNetCoreRuntime.3.0.x86' -ApiVersion '2018-02-01'
Now I want the same results using azure-cli:
az resource create --resource-group '<resource-group>' --resource-type 'Microsoft.Web/sites/siteextensions' --name '<webapp-name>/AspNetCoreRuntime.3.0.x86' --api-version '2018-02-01'
but when executed it requires an extra argument --properties but I cann't find any documentation regarding this argument. If I provide an empty json object the operation fails:
az : ERROR: Operation failed with status: 'Not Found'. Details: 404
Client Error: Not Found for url ....
How can I solve this problem using Azure CLI?
The --name should be --name '<webapp-name>/siteextensions/AspNetCoreRuntime.3.0.x86', also append --properties '{}'.
Try the sample as below, it works fine on my side.
az resource create --resource-group '<resource-group>' --resource-type 'Microsoft.Web/sites/siteextensions' --name '<webapp-name>/siteextensions/AspNetCoreRuntime.3.0.x86' --api-version '2018-02-01' --properties '{}'
Just try --properties {}
If their aren't actually any mandatory properties this will make CLI happy

Problem in Powershell with the --runtime command setting up Jenkins pipeline

I am trying to configure a Pipeline with Jenkins and deploying it to Azure. I am at the last step of a tutorial:
https://learn.microsoft.com/en-us/azure/jenkins/tutorial-jenkins-deploy-web-app-azure-app-service
This last step is as follows, i have to enter this in the Azure CLI:
az group create --name yourWebAppAzureResourceGroupName --location region
az appservice plan create --name appServicePlanName --resource-group rgname --is-linux
az webapp create --name webAppName --resource-group rgName --plan appServicePlanName --runtime "java|1.8|Tomcat|8.5"
The last command gives me the error:
'1.8' is not recognized as an internal or external command,
operable program or batch file.
So I thought maybe Tomcat is not installed on my Azure VM, which is a Linux machine. So I used the next tutorial to install Tomcat:
https://www.howtoforge.com/tutorial/how-to-install-apache-tomcat-8-5-on-ubuntu-16-04/
After this I tried to do the --runtime command again, but I still get the same error. I have no idea how to fix this. I hope someone can help me with this problem.
I tried to check the webapp list-runtimes and I get this list:
"java|1.8|Tomcat|8.5" is in here. I've tried all of the versions, but it did not work.
EDIT: It works in the Azure Cloud Shell, but then there is another error:
Linux Runtime 'java|1.8|Tomcat|8.5' is not supported.Please invoke 'list-runtimes' to cross check
I have tried all the runtime versions, but still this error. I have also tried it with double quotes
I bet you solved your problem already, but in case others find this and are using PowerShell to run Azure CLI commands. This is what worked for me.
The problem is in how PowerShell interprets the pipe, '|', character inside the --runtime parameter, when evaluating the whole line.
Add the --% to be beginning of the command to turn off PowerShell evaluation of expressions, as suggested in the code block here.
Note: this will also stop PowerShell from evaluating any variables inside the command. What you can do is move the --runtime to the end of the line to get around this problem, e.g. like this
az webapp create -g $rg -p $appPlanName -n $appName --deployment-local-git --% --runtime "DOTNETCORE|3.0"
ok, i got it, that list is for windows webapp, not linux. for linux use:
az webapp list-runtimes --linux
so working solution:
az webapp create --name yourWebAppName --resource-group yourWebAppAzureResourceGroupName --plan yourLinuxAppServicePlanName --runtime "TOMCAT|8.5-jre8"

Creating application insights with azure cli

I would like to create application insights using AZURE CLI. I can't find any documentation on this topic. Is it possible?
The link provided by Rohit works
az resource create \
--resource-group $RESOURCE_GROUP \
--resource-type "Microsoft.Insights/components" \
--name $NAMESPACE_PREFIX-appinsights \
--location $PRIMARY_LOCATION \
--properties '{"Application_Type":"web"}'
https://github.com/Azure/azure-cli/issues/5543#issuecomment-365001620
The az monitor app-insights component provide commands for creating, inspecting modifying, and deleting application insights components from the command line.
Use: az monitor app-insights component create
az monitor app-insights component create --app
--location
--resource-group
[--application-type]
[--ingestion-access {Disabled, Enabled}]
[--kind]
[--query-access {Disabled, Enabled}]
[--retention-time]
[--tags]
[--workspace]
If you need to associate the generated instrumentation key with another resource, such as a function app, you can use grep and xargs as follows:
# Creates insights component for monitoring. Note generated instrumentation key
# is set in function app.
az resource create \
--resource-group ${RESOURCE_GROUP_NAME} \
--resource-type "Microsoft.Insights/components" \
--name ${FUNCTION_APP_NAME} \
--location ${LOCATION} \
--properties '{"Application_Type":"web"}' \
| grep -Po "\"InstrumentationKey\": \K\".*\"" \
| xargs -I % az functionapp config appsettings set \
--name ${FUNCTION_APP_NAME} \
--resource-group ${RESOURCE_GROUP_NAME} \
--settings "APPINSIGHTS_INSTRUMENTATIONKEY = %"
Application Insights is an extensible Application Performance Management (APM) service for web developers on multiple platforms. You can use it to monitor your live web application. You can get more details about Application Insights.
It belongs to the Azure Monitor. You can find appropriate CLI command from az monitor. Hope this will be helpful.

Azure CLI 2: how to provide parameters in az group deployment create command?

I am using Azure CLI 2.0 on a windows machine and I am trying to create a Docker VM using this Microsoft documentation:
az group deployment create --resource-group myResourceGroup \
--parameters '{"newStorageAccountName": {"value": "mystorageaccount"},
"adminUsername": {"value": "azureuser"},
"adminPassword": {"value": "P#ssw0rd!"},
"dnsNameForPublicIP": {"value": "mypublicdns"}}' \
--template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/docker-simple-on-ubuntu/azuredeploy.json
Putting everything in one line results in an "unrecognized arguments" error. Replacing the parameter single quotes by double quotes results in an "Expecting property name enclosed in double quotes" error and removing the parameters option gives an expected "Deployment template validation failed" error. What is the correct way to provide the parameter value?
Please try this script:
az group deployment create --resource-group jason --parameters "{\"newStorageAccountName\": {\"value\": \"jasondisks321\"},\"adminUsername\": {\"value\": \"jason\"},\"adminPassword\": {\"value\": \"122130869#qq\"},\"dnsNameForPublicIP\": {\"value\": \"jasontest321\"}}" --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/docker-simple-on-ubuntu/azuredeploy.json
It works for me.
In cli 2.0, we can use --help to find the command help:
C:\windows\system32>az group deployment create --help
Examples
Create a deployment from a remote template file.
az group deployment create -g MyResourceGroup --template-uri
https://myresource/azuredeploy.json --parameters #myparameters.json
Create a deployment from a local template file and use parameter values in a string.
az group deployment create -g MyResourceGroup --template-file azuredeploy.json --parameters
"{\"location\": {\"value\": \"westus\"}}"
You can add you parameters in the following format:
--parameters '{ "adminUsername": {"value":"username"}}'
At time of writing, parameters can now simply be provided from file or inline as per the provided example from --help:
az group deployment create -g MyResourceGroup --template-file azuredeploy.json --parameters #params.json --parameters https://mysite/params.json --parameters MyValue=This MyArray=#array.json
This is what i have tried with single quote('') instead of double quote ("") and it worked for me.
az group deployment create --name TempGroup --resource-group insightsrg --parameters '{\"actionGroupName\": {\"value\": \"jsonActionGroup\"},\"actionGroupShortName\": {\"value\": \"JAG\"}}' --template-file "C:\HM\ARM\policy\actiongroup\actiongroup.json"
Kindly find an attached screenshot for reference.

Resources