Created
December 19, 2024 12:22
-
-
Save gerrited/213caedd779af482359c376d0e1e9a41 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!(Test-Path -Path "Drift")) | |
{ | |
mkdir drift | |
} | |
az resource list --query '[].{Name:name, Type:type, ResourceGroup:resourceGroup}' --output json > drift/azure_resources.json | |
terraform show -json > drift/terraform_state.json | |
# Read the Azure resources JSON file | |
$azureResources = Get-Content -Path "drift/azure_resources.json" | ConvertFrom-Json | |
# Read the Terraform state JSON file | |
$tfState = Get-Content -Path "drift/terraform_state.json" | ConvertFrom-Json | |
# Extract names of resources from both files | |
$tfResourceNames = $tfState.resources | ForEach-Object { $_.name } | |
# Find resources present in Azure but not in Terraform | |
$manuallyCreated = $azureResources | Where-Object { $_.Name -notin $tfResourceNames } | |
# # Output the manually created resources | |
# Write-Output "Manually created resources:" | |
# $manuallyCreated | ForEach-Object { | |
# [PSCustomObject]@{ | |
# Name = $_.Name | |
# Type = $_.Type | |
# } | |
# } | |
$manuallyCreated > drift/comparison.txt | |
if (Test-Path -Path "Drift/accepted-drift.txt") | |
{ | |
$diff = Compare-Object -ReferenceObject (Get-Content -Path drift/accepted-drift.txt) -DifferenceObject (Get-Content -Path drift/comparison.txt) | Out-String | |
if ($diff.Length -ne 0){ | |
Write-Output "NOT Equal: `n`n$diff" | |
Exit 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment