Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Custom Resource Tagging Feature #404

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,106 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
return
}

$tagKeys = $csvItem.TAG_KEY
$tagValues = $csvItem.TAG_VALUE
$tagDict = @{}

if ([string]::IsNullOrEmpty($tagKeys) -or [string]::IsNullOrEmpty($tagValues)) {
$processor.Logger.LogTrace("Tag Key/Value not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "Tag Key/Value not mentioned for: '$($sourceMachineName)'"
}
else{
$tagKeys = $tagKeys -split ","
$tagValues = $tagValues -split ","
# check if the count is equal for keys and values
if ($tagKeys.Count -ne $tagValues.Count) {
$processor.Logger.LogTrace("Tag Key/Value count mismatch for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "Tag Key/Value count mismatch for: '$($sourceMachineName)'"
return
}
else{
for ($i = 0; $i -lt $tagKeys.Count; $i++) {
$tagDict.Add($tagKeys[$i], $tagValues[$i])
}
$params.Add("Tag", $tagDict)
}
}

$vmTagKeys = $csvItem.VM_TAG_KEY
$vmTagValues = $csvItem.VM_TAG_VALUE
$vmTagDict = @{}

if ([string]::IsNullOrEmpty($vmTagKeys) -or [string]::IsNullOrEmpty($vmTagValues)) {
$processor.Logger.LogTrace("VM Tag Key/Value not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "VM Tag Key/Value not mentioned for: '$($sourceMachineName)'"
}
else{
$vmTagKeys = $vmTagKeys -split ","
$vmTagValues = $vmTagValues -split ","
# check if the count is equal for keys and values
if ($vmTagKeys.Count -ne $vmTagValues.Count) {
$processor.Logger.LogTrace("VM Tag Key/Value count mismatch for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "VM Tag Key/Value count mismatch for: '$($sourceMachineName)'"
return
}
else{
for ($i = 0; $i -lt $vmTagKeys.Count; $i++) {
$vmTagDict.Add($vmTagKeys[$i], $vmTagValues[$i])
}
$params.Add("VmTag", $vmTagDict)
}
}

$diskTagKeys = $csvItem.DISK_TAG_KEY
$diskTagValues = $csvItem.DISK_TAG_VALUE
$diskTagDict = @{}

if ([string]::IsNullOrEmpty($diskTagKeys) -or [string]::IsNullOrEmpty($diskTagValues)) {
$processor.Logger.LogTrace("Disk Tag Key/Value not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "Disk Tag Key/Value not mentioned for: '$($sourceMachineName)'"
}
else{
$diskTagKeys = $diskTagKeys -split ","
$diskTagValues = $diskTagValues -split ","
# check if the count is equal for keys and values
if ($diskTagKeys.Count -ne $diskTagValues.Count) {
$processor.Logger.LogTrace("Disk Tag Key/Value count mismatch for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "Disk Tag Key/Value count mismatch for: '$($sourceMachineName)'"
return
}
else{
for ($i = 0; $i -lt $diskTagKeys.Count; $i++) {
$diskTagDict.Add($diskTagKeys[$i], $diskTagValues[$i])
}
$params.Add("DiskTag", $diskTagDict)
}
}

$nicTagKey = $csvItem.NIC_TAG_KEY
$nicTagValue = $csvItem.NIC_TAG_VALUE
$nicTagDict = @{}

if ([string]::IsNullOrEmpty($nicTagKey) -or [string]::IsNullOrEmpty($nicTagValue)) {
$processor.Logger.LogTrace("NIC Tag Key/Value not mentioned for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "NIC Tag Key/Value not mentioned for: '$($sourceMachineName)'"
}
else{
$nicTagKey = $nicTagKey -split ","
$nicTagValue = $nicTagValue -split ","
# check if the count is equal for keys and values
if ($nicTagKey.Count -ne $nicTagValue.Count) {
$processor.Logger.LogTrace("NIC Tag Key/Value count mismatch for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "NIC Tag Key/Value count mismatch for: '$($sourceMachineName)'"
return
}
else{
for ($i = 0; $i -lt $nicTagKey.Count; $i++) {
$nicTagDict.Add($nicTagKey[$i], $nicTagValue[$i])
}
$params.Add("NicTag", $nicTagDict)
}
}

#Code added to accommodate for Target Subscription if the replicated machine is suppose to land in a different Target subscription
$targetSubscriptionID = $csvItem.TARGET_SUBSCRIPTION_ID
if ([string]::IsNullOrEmpty($targetSubscriptionID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,106 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
$params.Add("TargetResourceGroupID", $Target_RG.ResourceId)
}
}

$updateTagKey = $csvItem.UPDATED_TAG_KEY
$updateTagValue = $csvItem.UPDATED_TAG_VALUE
$updateTagOperation = $csvItem.UPDATED_TAG_OPERATION
$updateTagDict = @{}
if ([string]::IsNullOrEmpty($updateTagKey) -or [string]::IsNullOrEmpty($updateTagValue) -or [string]::IsNullOrEmpty($updateTagOperation)) {
$processor.Logger.LogTrace("UPDATED_TAG_KEY or UPDATED_TAG_VALUE or UPDATED_TAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
}
else {
$updateTagKeys = $updateTagKey.Split(",")
$updateTagValues = $updateTagValue.Split(",")

if ($updateTagKeys.Count -ne $updateTagValues.Count) {
$processor.Logger.LogTrace("UPDATED_TAG_KEY and UPDATED_TAG_VALUE count is not same for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "UPDATED_TAG_KEY and UPDATED_TAG_VALUE count is not same for: '$($sourceMachineName)'"
return
}
else {
for ($i=0; $i -lt $updateTagKeys.Count; $i++) {
$updateTagDict.Add($updateTagKeys[$i], $updateTagValues[$i])
}
$params.Add("UpdateTag", $updateTagDict)
$params.Add("UpdateTagOperation", $updateTagOperation)
}
}

$updateVmTagKey = $csvItem.UPDATED_VMTAG_KEY
$updateVmTagValue = $csvItem.UPDATED_VMTAG_VALUE
$updateVmTagOperation = $csvItem.UPDATED_VMTAG_OPERATION
$updateVmTagDict = @{}
if ([string]::IsNullOrEmpty($updateVmTagKey) -or [string]::IsNullOrEmpty($updateVmTagValue) -or [string]::IsNullOrEmpty($updateVmTagOperation)) {
$processor.Logger.LogTrace("UPDATED_VM_TAG_KEY or UPDATED_VM_TAG_VALUE or UPDATED_VMTAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
}
else {
$updateVmTagKeys = $updateVmTagKey.Split(",")
$updateVmTagValues = $updateVmTagValue.Split(",")

if ($updateVmTagKeys.Count -ne $updateVmTagValues.Count) {
$processor.Logger.LogTrace("UPDATED_VM_TAG_KEY and UPDATED_VM_TAG_VALUE count is not same for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "UPDATED_VM_TAG_KEY and UPDATED_VM_TAG_VALUE count is not same for: '$($sourceMachineName)'"
return
}
else {
for ($i=0; $i -lt $updateVmTagKeys.Count; $i++) {
$updateVmTagDict.Add($updateVmTagKeys[$i], $updateVmTagValues[$i])
}
$params.Add("UpdateVmTag", $updateVmTagDict)
$params.Add("UpdateVmTagOperation", $updateVmTagOperation)
}
}

$updateDiskTagKey = $csvItem.UPDATED_DISKTAG_KEY
$updateDiskTagValue = $csvItem.UPDATED_DISKTAG_VALUE
$updateDiskTagOperation = $csvItem.UPDATED_DISKTAG_OPERATION
$updateDiskTagDict = @{}
if ([string]::IsNullOrEmpty($updateDiskTagKey) -or [string]::IsNullOrEmpty($updateDiskTagValue) -or [string]::IsNullOrEmpty($updateDiskTagOperation)) {
$processor.Logger.LogTrace("UPDATED_DISKTAG_KEY or UPDATED_DISKTAG_VALUE or UPDATED_DISKTAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
}
else {
$updateDiskTagKeys = $updateDiskTagKey.Split(",")
$updateDiskTagValues = $updateDiskTagValue.Split(",")

if ($updateDiskTagKeys.Count -ne $updateDiskTagValues.Count) {
$processor.Logger.LogTrace("UPDATED_DISKTAG_KEY and UPDATED_DISKTAG_VALUE count is not same for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "UPDATED_DISKTAG_KEY and UPDATED_DISKTAG_VALUE count is not same for: '$($sourceMachineName)'"
return
}
else {
for ($i=0; $i -lt $updateDiskTagKeys.Count; $i++) {
$updateDiskTagDict.Add($updateDiskTagKeys[$i], $updateDiskTagValues[$i])
}
$params.Add("UpdateDiskTag", $updateDiskTagDict)
$params.Add("UpdateDiskTagOperation", $updateDiskTagOperation)
}
}

$updateNicTagKey = $csvItem.UPDATED_NICTAG_KEY
$updateNicTagValue = $csvItem.UPDATED_NICTAG_VALUE
$updateNicTagOperation = $csvItem.UPDATED_NICTAG_OPERATION
$updateNicTagDict = @{}
if ([string]::IsNullOrEmpty($updateNicTagKey) -or [string]::IsNullOrEmpty($updateNicTagValue) -or [string]::IsNullOrEmpty($updateNicTagOperation)) {
$processor.Logger.LogTrace("UPDATED_NICTAG_KEY or UPDATED_NICTAG_VALUE or UPDATED_NICTAG_OPERATION is not mentioned for: '$($sourceMachineName)'")
}
else {
$updateNicTagKeys = $updateNicTagKey.Split(",")
$updateNicTagValues = $updateNicTagValue.Split(",")

if ($updateNicTagKeys.Count -ne $updateNicTagValues.Count) {
$processor.Logger.LogTrace("UPDATED_NICTAG_KEY and UPDATED_NICTAG_VALUE count is not same for: '$($sourceMachineName)'")
$reportItem.AdditionalInformation = "UPDATED_NICTAG_KEY and UPDATED_NICTAG_VALUE count is not same for: '$($sourceMachineName)'"
return
}
else {
for ($i=0; $i -lt $updateNicTagKeys.Count; $i++) {
$updateNicTagDict.Add($updateNicTagKeys[$i], $updateNicTagValues[$i])
}
$params.Add("UpdateNicTag", $updateNicTagDict)
$params.Add("UpdateNicTagOperation", $updateNicTagOperation)
}
}


#Get the Target VirtualNetwork Name where we want to provision the VM in Azure
Expand Down Expand Up @@ -302,9 +402,6 @@ Function ProcessItemImpl($processor, $csvItem, $reportItem) {
}
#endregion




# Start replication for a discovered VM in an Azure Migrate project
$processor.Logger.LogTrace( "Starting Update Job for source '$($sourceMachineName)'")
$UpdateJob = Set-AzMigrateServerReplication @params
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AZMIGRATEPROJECT_SUBSCRIPTION_ID,AZMIGRATEPROJECT_RESOURCE_GROUP_NAME,AZMIGRATEPROJECT_NAME,SOURCE_MACHINE_NAME,AZMIGRATEASSESSMENT_NAME,AZMIGRATEGROUP_NAME,SQL_SERVER_LICENSE_TYPE,TARGET_SUBSCRIPTION_ID,TARGET_RESOURCE_GROUP_NAME,TARGET_VNET_NAME,TARGET_SUBNET_NAME,TARGET_MACHINE_NAME,TARGET_MACHINE_SIZE,LICENSE_TYPE,OS_DISK_ID,TARGET_DISKTYPE,AVAILABILITYZONE_NUMBER,AVAILABILITYSET_NAME,TURNOFF_SOURCESERVER,TESTMIGRATE_VNET_NAME,UPDATED_TARGET_RESOURCE_GROUP_NAME,UPDATED_TARGET_VNET_NAME,UPDATED_TARGET_MACHINE_NAME,UPDATED_TARGET_MACHINE_SIZE,UPDATED_AVAILABILITYZONE_NUMBER,UPDATED_AVAILABILITYSET_NAME,UPDATED_NIC1_ID,UPDATED_TARGET_NIC1_SELECTIONTYPE,UPDATED_TARGET_NIC1_SUBNET_NAME,UPDATED_TARGET_NIC1_IP,UPDATED_NIC2_ID,UPDATED_TARGET_NIC2_SELECTIONTYPE,UPDATED_TARGET_NIC2_SUBNET_NAME,UPDATED_TARGET_NIC2_IP,OK_TO_UPDATE,OK_TO_MIGRATE,OK_TO_USE_ASSESSMENT,OK_TO_TESTMIGRATE,OK_TO_RETRIEVE_REPLICATIONSTATUS,OK_TO_CLEANUP,OK_TO_TESTMIGRATE_CLEANUP
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,srcrg-ecy,ECYPROJ,testvm-cvm3,,srcrg-ecy,PAYG,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,sv-target-ecy-rg,vnet-name,default,testvm-1,,NoLicenseType,,,,,Y,vnet-ecy,,,testvm-sv-1,,,,,,,,,,,,Y,Y,Y,Y,Y,Y,Y
AZMIGRATEPROJECT_SUBSCRIPTION_ID,AZMIGRATEPROJECT_RESOURCE_GROUP_NAME,AZMIGRATEPROJECT_NAME,SOURCE_MACHINE_NAME,AZMIGRATEASSESSMENT_NAME,AZMIGRATE_APPLIANCE_NAME,AZMIGRATEGROUP_NAME,SQL_SERVER_LICENSE_TYPE,TAG_KEY,TAG_VALUE,VM_TAG_KEY,VM_TAG_VALUE,DISK_TAG_KEY,DISK_TAG_VALUE,NIC_TAG_KEY,NIC_TAG_VALUE,TARGET_SUBSCRIPTION_ID,TARGET_RESOURCE_GROUP_NAME,TARGET_VNET_NAME,TARGET_SUBNET_NAME,TARGET_MACHINE_NAME,TARGET_MACHINE_SIZE,LICENSE_TYPE,OS_DISK_ID,DATA_DISK1_ID,DATA_DISK2_ID,TARGET_DISKTYPE,AVAILABILITYZONE_NUMBER,AVAILABILITYSET_NAME,TURNOFF_SOURCESERVER,TESTMIGRATE_VNET_NAME,UPDATED_TAG_KEY,UPDATED_TAG_VALUE,UPDATED_TAG_OPERATION,UPDATED_VMTAG_KEY,UPDATED_VMTAG_VALUE,UPDATED_VMTAG_OPERATION,UPDATED_DISKTAG_KEY,UPDATED_DISKTAG_VALUE,UPDATED_DISKTAG_OPERATION,UPDATED_NICTAG_KEY,UPDATED_NICTAG_VALUE,UPDATED_NICTAG_OPERATION,UPDATED_TARGET_RESOURCE_GROUP_NAME,UPDATED_TARGET_VNET_NAME,UPDATED_TARGET_MACHINE_NAME,UPDATED_TARGET_DISK_NAME,UPDATED_TARGET_OS_DISK_NAME,UPDATED_TARGET_DATA_DISK1_NAME,UPDATED_TARGET_DATA_DISK2_NAME,UPDATED_TARGET_MACHINE_SIZE,UPDATED_AVAILABILITYZONE_NUMBER,UPDATED_AVAILABILITYSET_NAME,UPDATED_NIC1_ID,UPDATED_TARGET_NIC1_NAME,UPDATED_TARGET_NIC1_SELECTIONTYPE,UPDATED_TARGET_NIC1_SUBNET_NAME,UPDATED_TARGET_NIC1_IP,UPDATED_NIC2_ID,UPDATED_TARGET_NIC2_NAME,UPDATED_TARGET_NIC2_SELECTIONTYPE,UPDATED_TARGET_NIC2_SUBNET_NAME,UPDATED_TARGET_NIC2_IP,OK_TO_UPDATE,OK_TO_MIGRATE,OK_TO_USE_ASSESSMENT,OK_TO_TESTMIGRATE,OK_TO_RETRIEVE_REPLICATIONSTATUS,OK_TO_CLEANUP,OK_TO_TESTMIGRATE_CLEANUP
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,srcrg-ecy,ECYPROJ,testvm-cvm3,,sv-app-2,srcrg-ecy,PAYG,,,"vm-tag-1,vm-tag-2","vm-tag-val-1,vm-tag-val-2","d1,d2","d1-val,d2-val",n1,n1-val,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,sv-target-ecy-rg,vnet-ecy,default,testvm-1,,NoLicenseType,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,,,,Y,vnet-ecy,,,,"up-vm-1,up-vm-2","up-vm-value-1,up-vm-value-2",Replace,disk-1,disk-1-tag,Merge,,,,,,testvm-sv-1,,,,,,,,,nic-name-updated,,,,,,,,,Y,Y,Y,Y,Y,Y,Y