Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-AzureRmResource followed by Set-AzureRmResource changing JSON data type #7930

Closed
jsheetzati opened this issue Nov 28, 2018 · 11 comments
Closed
Assignees
Milestone

Comments

@jsheetzati
Copy link

Description

We are using Get-AzureRmResource and Set-AzureRmResource to automate some logic app deployments. When running the script, Set-AzureRmResource is turning numeric and boolean data types into strings. This looks very similar to this issue: #5940

For example, in our logic app definition json file, we have the following chunk of json:

"expression": {
	"and": [
		{
			"equals": [
				"@outputs('SubmitParseCsvFileJob')['statusCode']",
				200
			]
		}
	]
}

After piping the resource into Set-AzureRmResource, we end up with the following in the Portal:

"expression": {
	"and": [
		{
			"equals": [
				"@outputs('SubmitParseCsvFileJob')['statusCode']",
				"200"
			]
		}
	]
}

This is just one example of a data type changing but it happens many times within the logic app definition when deploying in this manner.

Script/Steps for Reproduction

If you need the full script illustrating the issue, I am more than happy to provide.

$resource = Get-AzureRmResource ...
$definition = (Get-Content -Raw -Path "jsonFile.json") | ConvertFrom-Json
$resource.Properties.definition = $definition
$resource  | Set-AzureRmResource

Module Version

6.13.1

Environment Data

PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Debug Output

Very long.. can provided if needed.

@cormacpayne
Copy link
Member

@jsheetzati would you mind providing the debug output after running both commands with $DebugPreference = "Continue"? Feel free to paste the output in a gist and paste the link to the gist here if you don't want to clog this issue with information.

@jsheetzati
Copy link
Author

@cormacpayne I have the debug log that illustrates the issue for you. Unfortunately, due to contractual obligations, I am not able to share publicly. I can send you the gist link if that is okay with you. My email is in my profile. Thanks!

@jsheetzati
Copy link
Author

jsheetzati commented Dec 11, 2018

@cormacpayne I scrubbed the log to remove our personal information that we cannot share. I hope it helps. https://gist.github.com/jsheetzati/bfdf89ba9fd6391f4e22c532f3cd2e2d

Edit:
Specifically look at lines 36557 and Line 70911

"equals": [
  "@outputs('SubmitParseCsvFileJob')['statusCode']",
  200
]
"equals": [
  "@outputs('SubmitParseCsvFileJob')['statusCode']",
  "200"
]

@cormacpayne
Copy link
Member

@jsheetzati I'm unable to reproduce this when using the latest Az module -- one thing I would figure out is what the value of the Properties property on the $resource object is after this line is executed:

$definition = (Get-Content -Raw -Path "jsonFile.json") | ConvertFrom-Json

It may be the case that the jsonFile.json file has the certain numeric and boolean values as strings, or they are being converted to strings when executing ConvertFrom-Json. Would you mind verifying that the Properties property contains the correct value before it is piped to the Set-AzResource cmdlet?

@jsheetzati
Copy link
Author

Here is a sample json file + powershell script that I am running. Confirmed it is still an issue with Az 1.3.0. I added some logging on one of the properties right before SetAzResource. After SetAzResource, I retrieve the resource again and the type is now a string.

Output from running script with json file:
Updating JoeTest
Int32
Updated JoeTest
String
done

LogicApp,json

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Condition": {
                "actions": {
                    "Terminate": {
                        "inputs": {
                            "runError": {
                                "message": "Counter is string"
                            },
                            "runStatus": "Failed"
                        },
                        "runAfter": {},
                        "type": "Terminate"
                    }
                },
                "else": {
                    "actions": {
                        "Terminate_2": {
                            "inputs": {
                                "runStatus": "Succeeded"
                            },
                            "runAfter": {},
                            "type": "Terminate"
                        }
                    }
                },
                "expression": {
                    "and": [
                        {
                            "equals": [
                                "@variables('counter')",
                                "1"
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "If"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "counter",
                            "type": "Integer",
                            "value": 1
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Week",
                    "interval": 1
                },
                "type": "Recurrence"
            }
        }
    }
}

Powershell Script

$ResourceName = "LogicAppResourceName"
$ResourceGroupName = "ResourceGroup"
    

Write-Host "Updating $($ResourceName)"
$resource = Get-AzResource -ResourceGroupName $ResourceGroupName -name $ResourceName -ResourceType Microsoft.Logic/workflows 
if (!$resource) {
    throw "No resource found"
}
    
$definitionAsJson = (Get-Content -Raw -Path "LogicApp.json")
if (!$definitionAsJson) { 
    throw "Unable to read json file for $($logicApp)"
}

$definition = $definitionAsJson | ConvertFrom-Json

$resource.Properties.definition = $definition.definition

try {
    Write-Host $resource.Properties.definition.actions.Initialize_variable.inputs.variables[0].value.GetType().Name

    $resource | Set-AzResource -Force -ErrorAction Stop | Out-Null
    
    Write-Host "Updated $($resourceName)"
    
    $updateResource = Get-AzResource -ResourceGroupName $ResourceGroupName -name $ResourceName -ResourceType Microsoft.Logic/workflows 
    Write-Host $updateResource.Properties.definition.actions.Initialize_variable.inputs.variables[0].value.GetType().Name
} catch {
    throw $_
}
    

Write-Host "done"

@cormacpayne
Copy link
Member

@jsheetzati thanks for going through the work of getting this extra information. I was able to reproduce this exception and track down where the issue is coming from:

We will look at a fix for this in an upcoming release.

@jsheetzati
Copy link
Author

Awesome. Will this fix be applied to both Az and AzureRm?

@cormacpayne
Copy link
Member

@jsheetzati this fix would only be applied to Az.Resources -- we plan on updating AzureRM modules only in cases where a high priority bug fix is needed.

@cormacpayne
Copy link
Member

Fix for this issue can be found in PR #8593

@cormacpayne cormacpayne removed this from the 2019-02-26 milestone Feb 21, 2019
@jsheetzati
Copy link
Author

Sounds good. Thanks for resolving this!

@cormacpayne
Copy link
Member

The fix for this will be available in the upcoming release of Az (version 1.5.0 released on March 12th, 2019).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants