Azure CLI Bash - attaching an app insights resource to api managment - bash

I can create an api management instance
az apim create \
--name "$apimName" \
--resource-group "$resourceGroupName" \
--publisher-name 'Publisher' \
--publisher-email 'Myemail#email.com.au' \
--tags "${resourceTags[#]}"
and I can create an app insights instance
az monitor app-insights component create \
--app "${apimName}-appins" \
--location "australiaeast" \
--resource-group "$resourceGroupName" \
--tags "${resourceTags[#]}"
How do I attach the api insights to api management?

Try the command below, replace the values with yours.
az resource create --resource-type 'Microsoft.ApiManagement/service/loggers' -g '<apim-group-name>' -n '<apim-name>/loggers/<appinsight-name>' --properties '{
"loggerType":"applicationInsights",
"description": null,
"credentials": {
"instrumentationKey": "<Instrumentation-Key-of-your-appinsight>"
},
"isBuffered": true,
"resourceId": "/subscriptions/<subscription-id>/resourceGroups/<appinsight-group-name>/providers/microsoft.insights/components/<appinsight-name>"
}'

Related

Getting azure subscription accesToken without az installed (for authorizing private endpoint from snowflake)

I am trying to setup azure privatelink on several snowflake accounts and I am terraforming all of the steps like creating the private endpoints and authorizing the connection from snowflake side (I am following this tutorial).
In the docs they are using command: az account get-access-token --subscription <SubscriptionID> and than you copy the accessToken and this works for the authorization, but my problem is that I am running all of this in a CI/CD and I don't have az installed so the only way to get this token is with a bash script. I've tried using azure RestAPI:
TOKEN="$(curl -s -X POST \
-H "Accept: application/json" \
-d "subscription_id=${SUBSCRIPTION_ID}"\
-d "client_id=${CLIENT_ID}" \
-d "client_secret=${CLIENT_SECRET}" \
-d "grant_type=client_credentials" \
-d "resource=https://ossrdbms-aad.database.windows.net" \
"https://login.microsoftonline.com/${TENANT_ID}/oauth2/token" \
| jq -r .access_token)"
but this apparently gives a different access token (for azure ad) that is not working for the snowflake authorization.
Is there any Azure RestAPI command (similar to this curl command above) that gives the same output like: az account get-access-token --subscription <SubscriptionID> so I can use it in my script?

How to add Infrastructure Agent to Heroku applications

I am attempting to have the New Relic Infrastructure Agent monitor my heroku applications.
The documentation says to run the following:
docker run \
-d \
--name newrelic-infra \
--network=host \
--cap-add=SYS_PTRACE \
--privileged \
--pid=host \
-v "/:/host:ro" \
-v "/var/run/docker.sock:/var/run/docker.sock" \
-e NRIA_LICENSE_KEY=[Key]\
newrelic/infrastructure:latest
But where do I actually run or put this so it runs it on my Heroku apps?

azure devops, bash : 'az pipelines variable-group variable update'

az pipelines variable-group variable update \
--group-id X \
--name ${{parameter.Key}} \
--value ${{parameter.Value}} \
--org $(System.CollectionUri) \
--project $(System.TeamProject)
Is there an option to reach variable-group by name and not by group-id?
have option to reach variable group by name and not by group-id?
The answer is no.
According to the document az pipelines variable-group variable update:
az pipelines variable-group variable update --group-id
--name
[--detect {false, true}]
[--new-name]
[--org]
[--project]
[--prompt-value {false, true}]
[--secret {false, true}]
[--value]
Required Parameters
--group-id --id
Id of the variable group.
--name
Name of the variable.
The group-id is the Required Parameter.

Configure EMR Cluster for Fair Scheduling

I am trying to spin up an emr cluster with fair scheduling such that I can run multiple steps in parallel. I see that this is possible via pipeline (https://aws.amazon.com/about-aws/whats-new/2015/06/run-parallel-hadoop-jobs-on-your-amazon-emr-cluster-using-aws-data-pipeline/), but I already have cluster management / creating automated via an airflow job calling the awscli[1] so it would be great to just update my configurations.
aws emr create-cluster \
--applications Name=Spark Name=Ganglia \
--ec2-attributes "${EC2_PROPERTIES}" \
--service-role EMR_DefaultRole \
--release-label emr-5.8.0 \
--log-uri ${S3_LOGS} \
--enable-debugging \
--name ${CLUSTER_NAME} \
--region us-east-1 \
--instance-groups InstanceGroupType=MASTER,InstanceCount=1,InstanceType=m3.xlarge InstanceGroupType=CORE,InstanceCount=4,InstanceType=m3.xlarge)
I think it may be achieved using the --configurations (https://docs.aws.amazon.com/cli/latest/reference/emr/create-cluster.html) flag, but not sure of the correct env names
Yes, you are correct. You can use EMR configurations to achieve your goal. You can create a JSON file with something like below :
yarn-config.json:
[
{
"Classification": "yarn-site",
"Properties": {
"yarn.resourcemanager.scheduler.class": "org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler"
}
}
]
as per Hadoop Fair Scheduler docs
Then modify you AWS CLI as :
aws emr create-cluster \
--applications Name=Spark Name=Ganglia \
--ec2-attributes "${EC2_PROPERTIES}" \
--service-role EMR_DefaultRole \
--release-label emr-5.8.0 \
--log-uri ${S3_LOGS} \
--enable-debugging \
--name ${CLUSTER_NAME} \
--region us-east-1 \
--instance-groups \
--configurations file://yarn-config.json
InstanceGroupType=MASTER,InstanceCount=1,InstanceType=m3.xlarge
InstanceGroupType=CORE,InstanceCount=4,InstanceType=m3.xlarge)

How does "knife ec2 server create"'s expansion of --run-list work?

I'm unable to bootstrap my server because "knife ec2 server create" keeps expanding my runlist to "roles".
knife ec2 server create \
-V \
--run-list 'role[pgs]' \
--environment $1 \
--image $AMI \
--region $REGION \
--flavor $PGS_INSTANCE_TYPE \
--identity-file $SSH_KEY \
--security-group-ids $PGS_SECURITY_GROUP \
--subnet $PRIVATE_SUBNET \
--ssh-user ubuntu \
--server-connect-attribute private_ip_address \
--availability-zone $AZ \
--node-name pgs \
--tags VPC=$VPC
Consistently fails because 'roles[pgs]' is expanded to 'roles'. Why is this? Is there some escaping or alternative method I can use?
I'm currently working around this by bootstrapping with an empty run-list and then overriding the runlist by running chef-client once the node is registered.
This is a feature of bash. [] is a wildcard expander. You should can escape the brackets using "\".

Resources