How to automate renewal of ssl certificate for application gateway azure with automation account ?

Anonymous
2022-11-02T09:33:38.02+00:00

Powershell

param(      
    [string]$LESERVER = 'LE_STAGE',      
    [string]$DomainName = 'www.abc.tk',      
    [string]$contact = 'mail_id',      
    [string]$webappname = 'Apgw',      
    [string]$resourcegroupname = 'test',      
    [string]$oldcert = 'test',      
    [string]$newcert = 'test1'      
)  
  
$conn = Get-AutomationConnection -Name AzureRunAsConnection;  
  
$azParams = @{      
  AZSubscriptionId='sub_id'      
  AZTenantId='TenantId'      
  AZAppUsername='AppUsername'      
  AZCertThumbprint='Thumbprint'      
}  
  
# Requesting the Certificate      
Set-PAServer $LESERVER  
  
New-PACertificate $DomainName -AcceptTOS -Contact $contact -DnsPlugin Azure -PluginArgs $azParams -Verbose -force -ErrorAction Stop  
  
# Request the Certificate      
Set-PAServer $LESERVER  
  
$new_ssl_cert = New-PACertificate $DomainName -AcceptTOS -Contact $contact -DnsPlugin Azure -PluginArgs $azParams -Verbose -force -ErrorAction Stop  
  
# Decoding the Certificate Password      
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($new_ssl_cert.PfxPass)  
  
$PfxPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)      
  
  
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)  
  
# Connecting the Azure using the creds of the Managed Identity      
Connect-AzAccount -ServicePrincipal -SubscriptionId 'SubscriptionId' -Tenant 'Tenant' -ApplicationId 'ApplicationId' -CertificateThumbprint 'Thumbprint' | Out-Null  
  
# The subscription hosting the DNS Zone of example.de      
$subs = 'Microsoft Partner Network'  
  
# Setting the subscription       
Select-AzSubscription -Subscription $subs | Out-Null      
  
$appgw = Get-AzApplicationGateway `      
  -ResourceGroupName $resourcegroupname `      
  -Name $webappname    
  
set-AzApplicationGatewaySSLCertificate -Name test -ApplicationGateway $appgw -CertificateFile $new_ssl_cert.PfxFile -Password $PfxPassword  
  
Set-AzApplicationGateway -ApplicationGateway $appgw  
  
Get-AzApplicationGateway -Name "Apgw" -ResourceGroupName "test"  

===============================================================

I am using above script for automate the SSL renewal for application gateway and using this script acme _challenge also validate and updated on DNS zone after validation all certificate also created but application gateway is not update SSL cert (letsencrypt).

Azure Application Gateway
Azure Application Gateway
An Azure service that provides a platform-managed, scalable, and highly available application delivery controller as a service.
1,217 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,368 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-08-02T10:13:31.5933333+00:00

    Hi @Marwa Abouawad , did you get any response ?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.