There is ways to create a Azure Search Service via ARM template (Example: https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-azure-search-create/azuredeploy.json).
What I want to know is there a way to define a specific index within the ARM template (fields, data sources, indexers etc)?
I know that there are REST services that you can use in order to create and modify indexes but I do not want a separate script/application to handle that after my resource group and Azure Search Service is created.
+1 to Don's comment. You will need to create the index either using the REST API or the .NET SDK. If you happen to be using PowerShell to create the service, you might find the following code helpful which calls the REST API using Invoke-RestMethod and a set of .JSON files that contain the schema for the index and some documents.
#------------------------#
# Setting up search index#
#------------------------#
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", 'application/json')
$headers.Add("api-key", $searchApiKey)
Write-Host
Write-Host "Creating Index..."
$schemaFile = "$(Split-Path $MyInvocation.MyCommand.Path)\zipcodes.schema"
$response = Invoke-RestMethod -TimeoutSec 10000 $searchServiceUrl"/indexes/zipcodes2?api-version=2015-02-28-Preview" -Method Put -Headers $headers -Body "$(get-content $schemaFile)"
Write-Host $response
$jsonFile = "$(Split-Path $MyInvocation.MyCommand.Path)\zipcodes1.json"
Write-Host
Write-Host "Adding Documents from $jsonFile..."
$response = Invoke-RestMethod -TimeoutSec 10000 $searchServiceUrl"/indexes/zipcodes2/docs/index?api-version=2015-02-28-Preview" -Method Post -Headers $headers -Body "$(get-content $jsonFile)"
Write-Host $response
No, you cannot create an index within an ARM template. The terminology I've read before is that ARM is for managing the Azure control plane.
Azure Search does not support managing indexes via ARM templates today. If this capability is important to you, please add an item on User Voice to help us prioritize it.
Related
I'm trying to invoke Azure REST API from Powershell to start/stop a classic service.
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer $($token.Token)")
$headers.Add("Content-Type", "application/json")
$response = Invoke-RestMethod "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$rscGrp/providers/Microsoft.ClassicCompute/domainNames/$serviceName/slots/production/$action?api-version=2020-02-01" -Method 'POST' -Headers $headers
$response | ConvertTo-Json
When $action="start", the command works perfectly and the service starts all instances as required.
However, when $action="stop", the command deletes the whole service all together. The whole deployment slot is deleted instead of simply stopping the instances.
Basically, I want it to behave exactly like clicking on the "stop" button in Azure Portal.
You can use this Rest API, to Power off the cloud service. Note that resources are still attached and you are getting charged for the resources
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/cloudServices/{cloudServiceName}/poweroff?api-version=2021-03-01
I have been working on creating New Tenant from API or Command Line in Azure Active Directory and I could not find a way to do it.
I have been also using Azure GraphAPI but it doesn't support this.
Is there any way from command or API that I can use to automate creation of new tenants?
I have researched on google and stackoverflow, but I didn't find any way to do it from command or API.
and is there any plan of Microsoft to provide such API in future? (edited)
There's no public, documented or supported (by MSFT) API available for this. That being said you might try using the portal internal API with something like this:
Invoke-WebRequest -Uri "https://main.iam.ad.ext.azure.com/api/Directories" `
-Method "POST" `
-Headers #{
"Accept-Language"="en"
"Authorization"="Bearer <azure ad access token issued for aud=74658136-14ec-4630-ad9b-26e160ff0fc6>"
} `
-ContentType "application/json" `
-Body "{`"companyName`":`"<company name>`",`"initialDomainPrefix`":`"<initial domain prefix (the one that will be appended to onmicrosoft.com)>`",`"countryCode`":`"<iso (2 letter) country code>`"}"
I know it's possible to get all packages contained in a single Artifact Feed using the link below:
https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/Feeds/{feedId}/packages?api-version=6.0-preview.1
I noticed in Azure DevOps that the search bar has the ability to look into ALL feeds inside a project. Thus, my question is: Is it possible to achieve the same functionality through the API, and get all packages from all feeds instead of one.
Is it possible to achieve the same functionality through the API, and get all packages from all feeds instead of one.
As far as I know, this is achievable.
You could use the Rest API -Feed Management - Get Feeds to get All feeds in Project level.
Then you could use the Rest API to get the packages. You can execute these two apis simultaneously through powershell.
Here is the Powershell sample:
$token = "PAT"
$url="https://feeds.dev.azure.com/{Organization Name}/{Project Name}/_apis/packaging/feeds?api-version=6.0-preview.1"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers #{Authorization = "Basic $token"} -Method Get -ContentType application/json
ForEach( $feedid in $response.value.id )
{
echo $feedid
$url1="https://feeds.dev.azure.com/{Organization Name}/{Project Name}/_apis/packaging/Feeds/$($feedid)/packages?api-version=6.0-preview.1"
$response1 = Invoke-RestMethod -Uri $url1 -Headers #{Authorization = "Basic $token"} -Method Get -ContentType application/json
Write-Host "Package = $($response1 | ConvertTo-Json -Depth 100)"
}
In this case, you can get alls feeds of project scope in a project, and then get all the packages in it.
By the way, if you want to get all organization scope feeds, you only need to delete the project parameter in the URL.
I have several azure devops pipeline files in one project. The files are all in a subdirectory and called azure-pipelines.yml.
Renaming: I can rename the pipelines in the UI to distinguish them... but I would like to skip that manual step and perform that in the yml. Is there a parameter for that - I cannot find it in the docs.
Workdirs: the pipelines start in the main directory. I can adjust the working directory of the script steps with workingDirectory thanks to the answer here. But can we also adjust that for the entire pipeline?
There is not a parameter for renaming the pipelines. There are two ways to rename the pipelines. One is to manually rename them from the UI. Another way is through build definition update rest api.
Below is an example in powershell scripts to rename the pipeline through rest api.
the scripts first get the build definition by build definition get api. Then assign a new name for the build definition, and update the definition with the new name.
$create = "https://dev.azure.com/{ORG}/{PROJ}/_apis/build/definitions/{DefinitionId}?api-version=5.1"
$PAT="{Person access token}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
$result = Invoke-RestMethod -Uri $create -Headers #{authorization = "Basic $base64AuthInfo"} -Method get
$result.name = "YamlPipeline-newName"
$updateBody= $result | ConvertTo-Json -Depth 100
$result7 = Invoke-RestMethod -Uri $create -Headers #{authorization = "Basic $base64AuthInfo"} -Method put -ContentType application/json -Body $updateBody
You cannot change the workingdirectory for the entire pipeline. You can change the workingdirectory inside the tasks.
And there are predefined variables you can use to refer to the places in the agents.
For below example:
$(Agent.BuildDirectory) is mapped to c:\agent_work\1
%(Build.ArtifactStagingDirectory) is mapped to c:\agent_work\1\a
$(Build.BinariesDirectory) is mapped to c:\agent_work\1\b
$(Build.SourcesDirectory) is mapped to c:\agent_work\1\s
You can also submit a feature request for above renaming pipeline and adjust workingdirectory for the entire pipeline(click Suggest a feature and choose Azure Devops) to Microsoft Development team. Hope they will consider supporting these feature in the future.
I have an automation account in Azure and I have a runbook in it. What I'm trying to do is to make an API call from this runbook. I'll need to login to some web service, get a session token and then use this session token to call some controller's methods.
So far I have only found some ways to call Azure runbooks through API (let's say from some backend c# code), but not vica versa. What I need to do is to call some c# methods FROM Azure runbook.
Is there a way to do it? If there is, how do I pass queries within my call?
What I'm expecting to see is something like:
$response = MakeApiCall -Url "www.someurl.com" -Body "some json for example"
Yes you can.
It's either
$Url = "https://my-url"
$Body = #{
field = "value"
}
Invoke-RestMethod -Method POST -Uri $url -Body $body -UseBasicParsing
or
Invoke-WebRequest
Invoke-RestMethod by default parses output, Invoke-WebRequest donesn't.