Skip to content

Commit

Permalink
Revert to working version of the script
Browse files Browse the repository at this point in the history
  • Loading branch information
ebronson68 committed Sep 3, 2024
1 parent d74590a commit 57fc47e
Showing 1 changed file with 10 additions and 42 deletions.
52 changes: 10 additions & 42 deletions .github/workflows/update-addns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,51 +80,19 @@ jobs:
timeout-minutes: 15
shell: pwsh
run: |
$RecordExists = $false
$RecordChanged = $false
try {
Write-Host "Adding CNAME Record: ${{ env.hostName }} -> ${{ env.aksIngress }}"
Add-DnsServerResourceRecordCName -Name "${{ env.hostName }}" -HostNameAlias "${{ env.aksIngress}}" -ZoneName "${{ env.domainName }}" -ComputerName ${{ secrets.domainController }}
Write-Host "Adding CNAME Record"
Add-DnsServerResourceRecordCName -Name "${{ env.hostName }}" -HostNameAlias "${{ env.aksIngress}}" -ZoneName "${{ env.domainName }}" -ComputerName ${{ secrets.domainController }}
}
catch {
Write-Host "Record Already Exists"
$RecordExists = $true
Write-Host "Record Already Exists"
}
Write-Host "Retrieving DNS Record"
$existingRecord = Get-DnsServerResourceRecord -ZoneName "${{ env.domainName }}" -ComputerName ${{ secrets.domainController }} | Where-Object { $_.HostName -eq "${{ env.hostName }}" -and $_.RecordType -eq 'CName' }
if ($existingRecord) {
if ($existingRecord.RecordData.HostNameAlias -ne "${{ env.aksIngress }}") {
Write-Host "Existing record differs from desired record. Updating..."
$RecordChanged = $true
} else {
Write-Host "Existing record matches the desired record. No update needed."
}
} else {
Write-Host "No existing record found. Adding new record..."
$RecordChanged = $true
}
if ($RecordChanged) {
try {
Write-Host "Updating CNAME Record"
Remove-DnsServerResourceRecord -ZoneName "${{ env.domainName }}" -Name "${{ env.hostName }}" -RecordType 'CName' -ComputerName ${{ secrets.domainController }} -Force
Add-DnsServerResourceRecordCName -Name "${{ env.hostName }}" -HostNameAlias "${{ env.aksIngress}}" -ZoneName "${{ env.domainName }}" -ComputerName ${{ secrets.domainController }}
}
catch {
Write-Host "Failed to update the record"
}
}
if (!$RecordExists -or $RecordChanged) {
try {
Write-Host "Syncing DNS Zone"
Sync-DnsServerZone -Name "${{ env.domainName }}" -ComputerName ${{ secrets.domainController }}
}
catch {
Write-Host "Skipping zone sync. Zone is currently being synced."
}
Get-DnsServerResourceRecord -ZoneName "${{ env.domainName }}" -ComputerName ${{ secrets.domainController }} | Where-Object HostName -eq "${{ env.aksIngress }}" | Format-List
try {
Write-Host "Syncing DNS Zone"
Sync-DnsServerZone -Name "${{ env.domainName }}" -ComputerName ${{ secrets.domainController }}
}
catch {
Write-Host "Skipping zone sync. Zone is currently being synced."
}

0 comments on commit 57fc47e

Please sign in to comment.