{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-powershell/issues/3937","repository_url":"https://api.github.com/repos/Azure/azure-powershell","labels_url":"https://api.github.com/repos/Azure/azure-powershell/issues/3937/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-powershell/issues/3937/comments","events_url":"https://api.github.com/repos/Azure/azure-powershell/issues/3937/events","html_url":"https://github.com/Azure/azure-powershell/issues/3937","id":227509938,"number":3937,"title":"Publish-AzureRmVmDscConfiguration remembers current subscription for the entire session","user":{"login":"brantb","id":150953,"avatar_url":"https://avatars1.githubusercontent.com/u/150953?v=3","gravatar_id":"","url":"https://api.github.com/users/brantb","html_url":"https://github.com/brantb","followers_url":"https://api.github.com/users/brantb/followers","following_url":"https://api.github.com/users/brantb/following{/other_user}","gists_url":"https://api.github.com/users/brantb/gists{/gist_id}","starred_url":"https://api.github.com/users/brantb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brantb/subscriptions","organizations_url":"https://api.github.com/users/brantb/orgs","repos_url":"https://api.github.com/users/brantb/repos","events_url":"https://api.github.com/users/brantb/events{/privacy}","received_events_url":"https://api.github.com/users/brantb/received_events","type":"User","site_admin":false},"labels":[{"id":334528495,"url":"https://api.github.com/repos/Azure/azure-powershell/labels/Investigate","name":"Investigate","color":"0052cc","default":false},{"id":187436091,"url":"https://api.github.com/repos/Azure/azure-powershell/labels/Team","name":"Team","color":"DDDDDD","default":false}],"state":"open","locked":false,"assignee":{"login":"shahabhijeet","id":20732208,"avatar_url":"https://avatars1.githubusercontent.com/u/20732208?v=3","gravatar_id":"","url":"https://api.github.com/users/shahabhijeet","html_url":"https://github.com/shahabhijeet","followers_url":"https://api.github.com/users/shahabhijeet/followers","following_url":"https://api.github.com/users/shahabhijeet/following{/other_user}","gists_url":"https://api.github.com/users/shahabhijeet/gists{/gist_id}","starred_url":"https://api.github.com/users/shahabhijeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shahabhijeet/subscriptions","organizations_url":"https://api.github.com/users/shahabhijeet/orgs","repos_url":"https://api.github.com/users/shahabhijeet/repos","events_url":"https://api.github.com/users/shahabhijeet/events{/privacy}","received_events_url":"https://api.github.com/users/shahabhijeet/received_events","type":"User","site_admin":false},"assignees":[{"login":"shahabhijeet","id":20732208,"avatar_url":"https://avatars1.githubusercontent.com/u/20732208?v=3","gravatar_id":"","url":"https://api.github.com/users/shahabhijeet","html_url":"https://github.com/shahabhijeet","followers_url":"https://api.github.com/users/shahabhijeet/followers","following_url":"https://api.github.com/users/shahabhijeet/following{/other_user}","gists_url":"https://api.github.com/users/shahabhijeet/gists{/gist_id}","starred_url":"https://api.github.com/users/shahabhijeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shahabhijeet/subscriptions","organizations_url":"https://api.github.com/users/shahabhijeet/orgs","repos_url":"https://api.github.com/users/shahabhijeet/repos","events_url":"https://api.github.com/users/shahabhijeet/events{/privacy}","received_events_url":"https://api.github.com/users/shahabhijeet/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2017-05-09T21:55:16Z","updated_at":"2017-05-12T00:20:19Z","closed_at":null,"body":"### Cmdlet(s)\r\nPublish-AzureRmVmDscConfiguration\r\n\r\n### PowerShell Version\r\n5.1.15063.138\r\n\r\n### Module Version\r\n```\r\nName            Version\r\n----            -------\r\nAzureRM.Compute 2.9.0\r\nAzureRM.profile 2.8.0\r\n```\r\n\r\n### OS Version\r\n10.0.15063.138 (Windows 10)\r\n\r\n### Description\r\nThe current Azure subscription at the time `Publish-AzureRmVMDscConfiguration` is first run in a session becomes \"sticky\" and subsequent calls to `Set-AzureRmContext` do not change the subscription used by subsequent calls to `Publish-AzureRmVMDscConfiguration`.\r\n\r\n\r\nAssumptions:\r\n\r\n* You have an Azure account with two subscriptions:\r\n  * Subscription A (ID: AAAAAAA-AAAA-4AAA-AAAA-AAAAAAAAAAAA)\r\n  * Subscription B (ID: BBBBBBB-BBBB-4BBB-BBBB-BBBBBBBBBBBB) \r\n* A storage account named `dscstorage` exists in Subscription B in a resource group named `dscstorage-rg`\r\n\r\n### Steps to reproduce:\r\n\r\n```powershell\r\n# 1. Create an empty DSC configuration\r\nPS> \"Configuration Empty { Node localhost {} }\" | Out-File empty.ps1\r\n# 2. Log in to Azure\r\nPS> Login-AzureRmAccount\r\n\r\nEnvironment           : AzureCloud\r\nAccount               : <your account>\r\nTenantId              : <tenant>\r\nSubscriptionId        : AAAAAAA-AAAA-4AAA-AAAA-AAAAAAAAAAAA\r\nSubscriptionName      : SubscriptionA\r\nCurrentStorageAccount :\r\n\r\n# 3. Execute Publish-AzureRmVMDscConfiguration targeting a storage account that does not exist in SubscriptionA.\r\nPS> Publish-AzureRmVMDscConfiguration -ConfigurationPath empty.ps1 -StorageAccountName ignore -ResourceGroupName ignore\r\n# Error:\r\nPublish-AzureRmVMDscConfiguration : Resource group 'dscstorage-rg' could not be found.\r\n\r\n# 4. Change the active subscription\r\nPS> Set-AzureRmContext -SubscriptionName SubscriptionB\r\n\r\nEnvironment           : AzureCloud\r\nAccount               : <your account>\r\nTenantId              : <tenant>\r\nSubscriptionId        : BBBBBBB-BBBB-4BBB-BBBB-BBBBBBBBBBBB\r\nSubscriptionName      : SubscriptionB\r\nCurrentStorageAccount :\r\n\r\n# 5. Run the same command again:\r\nPS> Publish-AzureRmVMDscConfiguration -ConfigurationPath empty.ps1 -StorageAccountName ignore -ResourceGroupName ignore\r\n# Error:\r\nPublish-AzureRmVMDscConfiguration : Resource group 'dscstorage-rg' could not be found.\r\n```\r\n\r\nIf step 3 is omitted, step 5 succeeds.\r\n\r\n### Debug output\r\n\r\nRunning step 5 with with `-Debug` reveals a problem: The cmdlet is attempting to do a `fetchKeys` from Subscription A and not Subscription B (see the 'Absolute Uri' in the output), which returns HTTP 404.\r\n\r\n```\r\nDEBUG: ============================ HTTP REQUEST ============================\r\n\r\nHTTP Method:\r\nPOST\r\n\r\nAbsolute Uri:\r\nhttps://management.azure.com/subscriptions/AAAAAAA-AAAA-4AAA-AAAA-AAAAAAAAAAAA/resourceGroups/dscstorage-rg/providers/Microsoft.Stora\r\nge/storageAccounts/dscstorage/listKeys?api-version=2015-06-15\r\n\r\nHeaders:\r\nx-ms-client-request-id        : eef7dbd7-fa49-44aa-8236-55467d7e85c4\r\naccept-language               : en-US\r\n\r\nBody:\r\n\r\n\r\nDEBUG: ============================ HTTP RESPONSE ============================\r\n\r\nStatus Code:\r\nNotFound\r\n\r\nHeaders:\r\nPragma                        : no-cache\r\nx-ms-failure-cause            : gateway\r\nx-ms-request-id               : 23c333fd-4b07-4c66-855e-de296e0c59ac\r\nx-ms-correlation-request-id   : 23c333fd-4b07-4c66-855e-de296e0c59ac\r\nx-ms-routing-request-id       : CANADACENTRAL:20170509T214825Z:23c333fd-4b07-4c66-855e-de296e0c59ac\r\nStrict-Transport-Security     : max-age=31536000; includeSubDomains\r\nCache-Control                 : no-cache\r\nDate                          : Tue, 09 May 2017 21:48:24 GMT\r\n\r\nBody:\r\n{\r\n  \"error\": {\r\n    \"code\": \"ResourceGroupNotFound\",\r\n    \"message\": \"Resource group 'dscstorage' could not be found.\"\r\n  }\r\n}\r\n}\r\n\r\nPublish-AzureRmVMDscConfiguration : Resource group 'dscstorage' could not be found.\r\nAt line:1 char:1\r\n+ Publish-AzureRmVMDscConfiguration -ConfigurationPath .\\empty.ps1 -Sto ...\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n    + CategoryInfo          : CloseError: (:) [Publish-AzureRmVMDscConfiguration], CloudException\r\n    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Extension.DSC.PublishAzureVMDscConfigurationCommand\r\n\r\nDEBUG: AzureQoSEvent: CommandName - Publish-AzureRmVMDscConfiguration; IsSuccess - False; Duration - 00:00:00.8824174; Exception -\r\nMicrosoft.Rest.Azure.CloudException: Resource group 'dscstorage' could not be found.\r\n   at Microsoft.Azure.Management.Storage.StorageAccountsOperations.<ListKeysWithHttpMessagesAsync>d__11.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Azure.Management.Storage.StorageAccountsOperationsExtensions.<ListKeysAsync>d__13.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Microsoft.Azure.Management.Storage.StorageAccountsOperationsExtensions.ListKeys(IStorageAccountsOperations operations, String\r\n resourceGroupName, String accountName)\r\n   at Microsoft.Azure.Commands.Compute.Extension.DSC.DscExtensionCmdletCommonBase.GetStorageCredentials(AzureRMCmdlet cmdlet,\r\nString resourceGroupName, String storageAccountName) in\r\nD:\\workspace\\powershell-sign\\src\\ResourceManager\\Compute\\Commands.Compute\\Extension\\DSC\\DscExtensionCmdletCommonBase.cs:line 34\r\n   at Microsoft.Azure.Commands.Compute.Extension.DSC.PublishAzureVMDscConfigurationCommand.ExecuteCmdlet() in\r\nD:\\workspace\\powershell-sign\\src\\ResourceManager\\Compute\\Commands.Compute\\Extension\\DSC\\PublishAzureVMDscConfigurationCommand.cs:li\r\nne 143\r\n   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() in\r\nD:\\workspace\\powershell-sign\\src\\Common\\Commands.Common\\AzurePSCmdlet.cs:line 642;\r\n```\r\n\r\nWorkaround: Open a new PowerShell session whenever you need to operate on a different subscription."},"comment":{"url":"https://api.github.com/repos/Azure/azure-powershell/issues/comments/300950757","html_url":"https://github.com/Azure/azure-powershell/issues/3937#issuecomment-300950757","issue_url":"https://api.github.com/repos/Azure/azure-powershell/issues/3937","id":300950757,"user":{"login":"markcowl","id":1054056,"avatar_url":"https://avatars2.githubusercontent.com/u/1054056?v=3","gravatar_id":"","url":"https://api.github.com/users/markcowl","html_url":"https://github.com/markcowl","followers_url":"https://api.github.com/users/markcowl/followers","following_url":"https://api.github.com/users/markcowl/following{/other_user}","gists_url":"https://api.github.com/users/markcowl/gists{/gist_id}","starred_url":"https://api.github.com/users/markcowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markcowl/subscriptions","organizations_url":"https://api.github.com/users/markcowl/orgs","repos_url":"https://api.github.com/users/markcowl/repos","events_url":"https://api.github.com/users/markcowl/events{/privacy}","received_events_url":"https://api.github.com/users/markcowl/received_events","type":"User","site_admin":false},"created_at":"2017-05-12T00:20:19Z","updated_at":"2017-05-12T00:20:19Z","body":"@brantb Looking at the code, it appears that the cmdlet is incorrectly caching a storage management client, so that, the first timeyou call Publish or Set DSC Extension cmdlets in a session, it will retain that same client throughout the session, which caches the subscription, regardless of whether you login or switch subscriptions later in the session.\r\n\r\nLet me know if this sounds like your scenario.  If so, we'll assign to the compute team to fix - at the very least they should be creating a new storage client whenever the subscription changes."}}
{"actor":{"display_login":"markcowl"}}