Azure ARM Template Testing with Pester - azure

I have been following the link
Azure ARM Template Testing on how to carry out ARM testing with Pester.
Unfortunately, I'm unable to get a successful tests.
For example in the script the following code states the following:
It "Does Availability Set Have Correct SKU" {
$av = $deploymentOutput.validatedResources | Where-Object { $_.type -eq 'Microsoft.Compute/availabilitySets' }
$av.sku.name | Should Be **'Align'**
However, even though the result of the ARM template is 'Align' I get the following error.
error
Whereas I should be getting the following successful output:
success
For a complete look at the code it can be found here
Any guidance will greatly appreciated.
Regards

While this isnt a direct answer to your question, this is an indirect answer to your question :)
Just dont do this. Test-AzureRMResourceGroupDeployment doesnt do any real good. If you insist on using it you can always use a 1 liner to do that or use VSCode tasks or whatever to kick off this cough test cough.
There is really no point in validating if this particular resource type is the one that you expect, because you dont really change resource types in the resource after you created it. Also, if Test-AzureRMResourceGroupDeployment returns success doesnt mean your deployment will work. It only checks basic sanity. Just create a powershell script\task to deploy a template and kick it off automatically after commit. Pester adds nothing of value to this process, only complicates things.

Related

Deploying Azure sentinel analytics rules in bulk with Powershell

I am trying to deploy around 70 log analytics rules in to an environment's Azure Sentinel with Powershell so I don't have to do this manually one by one. I got the Analyticsrules.ps1 and rules.json which includes all the rules I want to deploy.
When I run it, I get this error: https://i.stack.imgur.com/nz9S4.png
"Cannot bind argument to parameter 'path' because it is null"
Does anyone know what I am doing wrong? I can show the json file as well but its really long.
As mentioned in the error, the path parameter is null.
Please make sure $env:Pipeline_Workspace and $artifactPath are not null.
$artifactPath = Join-Path $env:Pipeline_Workspace $artifactName
$rulesFilePath = Join-Path $artifactPath $RulesFile

Unable to utilise variable passed from previous step in a Azure release pipeline

I have an Azure release pipeline that I am using for a Windows Virtual Desktop deployment.
I have created a simple Powershell task to obtain some information about the existing session hosts available and capture it to a list which I have then set to a dynamic variable using
$sessions = "vm_name1 vm_name2 vm_name3"
write-host "##vso[task.setvariable variable=sessions;isOutput=true;]$sessions"
I can then retrieve this fine in later tasks by using
write-host $(taskreference.sessions)
result: vm_name1 vm_name2 vm_name3
However, I need to access be able to parse this variable $(sessions) to obtain the individual host names to be used in later steps of my release pipeline.
i.e. $vms = $(sessions).Split(" ")
$vms[0]
$vms[1]
etc etc
I have tried various methods to access and expand this variable but ultimately am struggling to get anything working as it will always return null. When using a Azure CLI task, I am able to successfully access the variable using the exact same code. I suspect this is something to do with how the tasks work during run time/compile time.
Is there any way that I could parse the variable properly to obtain the individual host names?
The one you described would work fine if the variable is passed in as a string parameter.
Else this might work.
$vms = "$(sessions)".Split(" ")
$vms[0]
$vms[1]

struggling to get 'deploy to azure button' to work

I'm struggling to get a Deploy to Azure button to work and hoping someone can help,
my code in the readme.md looks like
[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/<url encoded link to raw template>
when I try the button it takes me to the deploy screen, only I get an error:
"(x) Error parsing template. Please ensure template is valid JSON. Invalid symbol at character position 4. (3 other errors)"
the template validates and works as expected when deployed manually through Deploy a Custom Template,
the raw uri to the template in our tfsgit repo returns the raw template as expected
(the raw uri uses msoft's pattern of https://dev.azure.com/{{organization}}/{{project}}/_apis/sourceProviders/{{providerName}}/filecontents?repository={{repository}}&path={{path}}&commitOrBranch={{commitOrBranch}}&api-version=5.0-preview.1)
I'm guessing might be some kind of authentification issue, I've tried basic auth with username:password#https://... or maybe it only works with github.com, either way I'm completely stuck
nothing I try seems to work, and azure won't show me the json it's trying to parse,
I was wondering if someone else has had a similar issue and would be able to point me in the right direction here
thanks in advance

Error "BadRequest" when calling Azure Function in ADF

I am creating an extensive data factory work flow that will create and fill a data warehouse for multiple customers automatic, however i'm running into an error. I am going to post the questions first, since the remaining info is a bit long. Keep in mind i'm new to data factory and JSON coding.
Questions & comments
How do i correctly pass the parameter through to an Execute Pipeline activity?
How do i add said parameter to an Azure Function activity?
The issue may lie with correctly passing the parameter through, or it may lie in picking it up - i can't seem to determine which one. If you spot an error with the current setup, dont hesitate to let me know - all help is appreciated
The Error
{
"errorCode": "BadRequest",
"message": "Operation on target FetchEntries failed: Call to provided Azure function
'' failed with status-'BadRequest' and message -
'{\"Message\":\"Please pass 'customerId' on the query string or in the request body\"}'.",
"failureType": "UserError",
"target": "ExecuteFullLoad"
}
The Setup:
The whole setup starts with a function call to get new customers from an online economic platform. It the writes them to a SQL table, from which they are processed and loaded into the final table, after which a new pipeline is executed. This process works perfectly. From there the following pipeline is executed:
As you can see it all works well until the ForEach loop tries to execute another pipeline, that contains an azure function that calls a .NET scripted function that fills said warehouse (complex i know). This azure function needs a customerid to retrieve tokens and load the data into the warehouse. I'm trying to pass those tokens from the InternalCustomerID lookup through the ForEach into the pipeline and into the function. The ForEach works actually, but fails "Because an inner activity failed".
The Execute Pipeline task contains the following settings, where i'm trying to pass the parameter through which comes from the foreach loop. This part of the process also works, since it executes twice (as it should in this test phase):
I dont know if it doesn't successfully pass the parameter through or it fails at adding it to the body of the azure function.
The child pipeline (FullLoad) contains the following parameters. I'm not sure if i should set a default value to be overwritten or how that actually works. The guides i've look at on the internet havent had a default value.
Finally there is the settings for the Azure function. I'm not sure what i need to write in order to correctly capture the parameter and/or what to fill in - if it's the header or the body regarding the error message. I know a post cannot be executed without a body.
If i run this specific funtion by hand (using the Function App part of portal.azure.com) it works fine, by using the following settings:
I viewed all of your detailed question and I think the key of the issue is the format of Azure Function Request Body.
I'm afraid this is incorrect. Please see my below steps based on your description:
Work Flow:
Inside ForEach Activity, only one Azure Function Activity:
The preview data of LookUp Activity:
Then the configuration of ForEach Activity: #activity('Lookup1').output.value
The configuration of Azure Function Activity: #json(concat('{"name":"',item().name,'"}'))
From the azure function, I only output the input data. Sample Output as below:
Tips: I saw your step is executing azure function in another pipeline and using Execute Pipeline Activity, (I don't know why you have to follow such steps), but I think it doesn't matter because you only need to focus on the Body format, if your acceptable format is JSON, you could use #json(....),if the acceptable format is String, you could use #cancat(....). Besides, you could check the sample from the ADF UI portal which uses pipeline().parameters

Liferay 6.2 Kaleo notification e-mail can't call operations of services

I'm developing a custom kaleo workflow with e-mail notifications. For notifications, I'm using Velocity and I would like to get some information from Liferay services. This is a small code sample that gives me problems:
#set ($resourceUtil = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleResourceLocalService"))
$resourceUtil
#set ($resourcePK = $getterUtil.getInteger($entryClassPK))
$resourcePK
#set ($resource = $resourceUtil.getJournalArticleResource($resourcePK))
$resource
If I use the previous code, the notification that I get is the following:
com.liferay.portlet.journal.service.impl.JournalArticleResourceLocalServiceImpl#3baa7cf0
6563724
$resource
As you can see, I get the correct JournalArticleResourceLocalService, I get the correct value for the resource PK, but when I call the operation to get the resource, I always get a null.
This is a sample with a resource but I've tried with some other lifeary services and I always get no response. This leads me to think that perhaps I've to enable some property or do something different to be able to call the service operations?
Any hiny will be appreciated. I'm using Liferay 6.2. The same code in Liferay 6.0 works fine...
Give a try with
com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil
instead of
com.liferay.portlet.journal.service.JournalArticleResourceLocalService
still, this is just my first advice looking just on code. If this won't solve your problem I will try test it later on my environment.

Resources