0

Azure Search does not give any scheduled scaling option so I try to make it by Automation account.

I followed AzSearch PowerShell command, but it does not work as I expected.

Set-AzureRmResource with ReplicaCount=2 parameter is not applied. Actually, it does not give any result message. What did I miss?

To reproduce my problem, you can import my runbook file at below link;

https://gist.github.com/YoungjaeKim/5cb66a666a3a864b7379aac0a400da40

Save the text file as AzureSearch-SetReplicaCount.graphrunbook and Import it to Automation account > Add a runbook menu.

Youngjae
  • 24,352
  • 18
  • 113
  • 198
  • man, graph runbooks are crap. you cant even tell what it does before importing. so have you tried your command manually? does it work? – 4c74356b41 Jun 16 '17 at 06:33
  • @4c74356b41 // well, I didn't try by raw PowerShell command yet. perhaps I have to do it by PS Command automation. – Youngjae Jun 16 '17 at 06:35
  • just try your command without a runbook, from your pc\laptop. and see if it works, start troubleshooting from there – 4c74356b41 Jun 16 '17 at 06:37
  • thanks for your comment – Youngjae Jun 16 '17 at 06:37
  • 1
    Scaling an Azure Search service is not instantaneous. After changing the replica count, you'll need to poll the search service using Get-AzureRmResource until its status indicates that it is in the "running" state instead of the "provisioning" state. I have no idea how to do this in a graph runbook. I concur with @4c74356b41 -- please try this directly in PowerShell first and let us know if it doesn't work. – Bruce Johnston Jun 16 '17 at 19:03

1 Answers1

0

Following commenters, I ended up by making PowerShell runbook.

I uploaded powershell source code to below link;

https://gallery.technet.microsoft.com/scriptcenter/Azure-Search-change-c0b49c4c

Let me attach the code as below;

<# 
    .DESCRIPTION 
        Scale Azure Search ReplicaCount 
        AzSearch command reference; https://learn.microsoft.com/en-us/azure/search/search-manage-powershell 

    .NOTES 
        AUTHOR: Youngjae Kim 
        LASTEDIT: June 19, 2017 
#> 

Param( 
 [string]$SubscriptionId, 
 [string]$ResourceGroupName, 
 [string]$AzSearchResourceName, 
 [int]$InstanceCount = 1 
) 


# 1. Acquire Automation account 
$connectionName = "AzureRunAsConnection" 
try 
{ 
    # Get the connection "AzureRunAsConnection " 
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName          

    "Logging in to Azure..." 
    Add-AzureRmAccount ` 
        -ServicePrincipal ` 
        -TenantId $servicePrincipalConnection.TenantId ` 
        -ApplicationId $servicePrincipalConnection.ApplicationId ` 
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint  
} 
catch { 
    if (!$servicePrincipalConnection) 
    { 
        $ErrorMessage = "Connection $connectionName not found. You must have Automation account. Reference: https://learn.microsoft.com/en-us/azure/automation/automation-role-based-access-control" 
        throw $ErrorMessage 
    } else{ 
        Write-Error -Message $_.Exception 
        throw $_.Exception 
    } 
} 

# 2. Select subscription 
Select-AzureRmSubscription -SubscriptionId $SubscriptionId 

# 3. Specify Azure Search Resource 
$resource = Get-AzureRmResource ` 
    -ResourceType "Microsoft.Search/searchServices" ` 
    -ResourceGroupName $ResourceGroupName ` 
    -ResourceName $AzSearchResourceName ` 
    -ApiVersion 2015-08-19 
Write-Output ($resource) 

# 4. Scale your service up 
# Note that this will only work if you made a non "free" service 
# This command will not return until the operation is finished 
Write-Output ("Updating InstanceCount to " + $InstanceCount + ". This can take 15 minutes or more...") 
$resource.Properties.ReplicaCount = $InstanceCount 
$resource | Set-AzureRmResource -Force -Confirm:$false 

# 5. Finish 
Write-Output ("End of Process to set InstanceCount = " + $InstanceCount + " for " + $AzSearchResourceName) 
Youngjae
  • 24,352
  • 18
  • 113
  • 198