public async Task WhatIfAtSubscriptionScope_ModifyResources_ReturnsModifyChanges() { // Arrange. var deployment = new Deployment( new DeploymentProperties(DeploymentMode.Incremental) { Template = SubscriptionTemplate, Parameters = "{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}".Replace("'", "\"") }) { Location = "westus2" }; var deploymentWhatIf = new DeploymentWhatIf( new DeploymentWhatIfProperties(DeploymentMode.Incremental) { Template = SubscriptionTemplateWestEurope, Parameters = "{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}".Replace("'", "\""), WhatIfSettings = new DeploymentWhatIfSettings() { ResultFormat = WhatIfResultFormat.FullResourcePayloads } } ) { Location = "westus2" }; var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync("SDK-test", ResourceGroup)).Value; var deploy = await DeploymentsOperations.StartCreateOrUpdateAtSubscriptionScopeAsync(NewDeploymentName(), deployment); await WaitForCompletionAsync(deploy); // Act. var rawResult = await DeploymentsOperations.StartWhatIfAtSubscriptionScopeAsync(NewDeploymentName(), deploymentWhatIf); var result = (await WaitForCompletionAsync(rawResult)).Value; // Assert. Assert.AreEqual("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.IsNotEmpty(result.Changes); WhatIfChange policyChange = result.Changes.FirstOrDefault(change => change.ResourceId.EndsWith("Microsoft.Authorization/policyDefinitions/policy2")); Assert.NotNull(policyChange); Assert.True(policyChange.ChangeType == ChangeType.Deploy || policyChange.ChangeType == ChangeType.Modify); Assert.NotNull(policyChange.Delta); Assert.IsNotEmpty(policyChange.Delta); WhatIfPropertyChange policyRuleChange = policyChange.Delta .FirstOrDefault(propertyChange => propertyChange.Path.Equals("properties.policyRule.if.equals")); Assert.NotNull(policyRuleChange); Assert.AreEqual(PropertyChangeType.Modify, policyRuleChange.PropertyChangeType); Assert.AreEqual("northeurope", policyRuleChange.Before); Assert.AreEqual("westeurope", policyRuleChange.After); }
public PSWhatIfPropertyChange(WhatIfPropertyChange whatIfPropertyChange) { this.whatIfPropertyChange = whatIfPropertyChange; this.before = new Lazy <JToken>(() => whatIfPropertyChange.Before.ToJToken()); this.after = new Lazy <JToken>(() => whatIfPropertyChange.After.ToJToken()); this.children = new Lazy <IList <PSWhatIfPropertyChange> >(() => whatIfPropertyChange.Children?.Select(pc => new PSWhatIfPropertyChange(pc)).ToList()); }
public void WhatIfAtSubscriptionScope_ModifyResources_ReturnsModifyChanges() { using (MockContext context = MockContext.Start(this.GetType())) { // Arrange. ResourceManagementClient client = this.GetResourceManagementClient(context); var deployment = new Deployment { Location = "westus2", Properties = new DeploymentProperties { Mode = DeploymentMode.Incremental, Template = SubscriptionTemplate, Parameters = JObject.Parse("{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}"), } }; // Change "northeurope" to "westeurope". JObject newTemplate = JObject.Parse(SubscriptionTemplate); newTemplate["resources"][0]["properties"]["policyRule"]["if"]["equals"] = "westeurope"; var deploymentWhatIf = new DeploymentWhatIf { Location = "westus2", Properties = new DeploymentWhatIfProperties { Mode = DeploymentMode.Incremental, Template = newTemplate, Parameters = JObject.Parse("{ 'storageAccountName': {'value': 'whatifnetsdktest1'}}"), WhatIfSettings = new DeploymentWhatIfSettings(WhatIfResultFormat.FullResourcePayloads) } }; client.ResourceGroups.CreateOrUpdate("SDK-test", ResourceGroup); client.Deployments.CreateOrUpdateAtSubscriptionScope(NewDeploymentName(), deployment); // Act. WhatIfOperationResult result = client.Deployments .WhatIfAtSubscriptionScope(NewDeploymentName(), deploymentWhatIf); // Assert. Assert.Equal("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.NotEmpty(result.Changes); WhatIfChange policyChange = result.Changes.FirstOrDefault(change => change.ResourceId.EndsWith("Microsoft.Authorization/policyDefinitions/policy2")); Assert.NotNull(policyChange); Assert.True(policyChange.ChangeType == ChangeType.Deploy || policyChange.ChangeType == ChangeType.Modify); Assert.NotNull(policyChange.Delta); Assert.NotEmpty(policyChange.Delta); WhatIfPropertyChange policyRuleChange = policyChange.Delta .FirstOrDefault(propertyChange => propertyChange.Path.Equals("properties.policyRule.if.equals")); Assert.NotNull(policyRuleChange); Assert.Equal(PropertyChangeType.Modify, policyRuleChange.PropertyChangeType); Assert.Equal("northeurope", policyRuleChange.Before); Assert.Equal("westeurope", policyRuleChange.After); } }
public void WhatIf_ModifyResources_ReturnsModifyChanges() { using (MockContext context = MockContext.Start(this.GetType())) { // Arrange. ResourceManagementClient client = this.GetResourceManagementClient(context); var deployment = new Deployment { Properties = new DeploymentProperties { Mode = DeploymentMode.Incremental, Template = ResourceGroupTemplate, Parameters = ResourceGroupTemplateParameters, } }; // Modify account type: Standard_LRS => Standard_GRS. JObject newTemplate = JObject.Parse(ResourceGroupTemplate); newTemplate["resources"][0]["properties"]["accountType"] = "Standard_GRS"; var deploymentWhatIf = new DeploymentWhatIf { Properties = new DeploymentWhatIfProperties { Mode = DeploymentMode.Incremental, Template = newTemplate, Parameters = ResourceGroupTemplateParameters, WhatIfSettings = new DeploymentWhatIfSettings(WhatIfResultFormat.FullResourcePayloads) } }; string resourceGroupName = NewResourceGroupName(); client.ResourceGroups.CreateOrUpdate(resourceGroupName, ResourceGroup); client.Deployments.CreateOrUpdate(resourceGroupName, NewDeploymentName(), deployment); // Act. WhatIfOperationResult result = client.Deployments .WhatIf(resourceGroupName, NewDeploymentName(), deploymentWhatIf); // Assert. Assert.Equal("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.NotEmpty(result.Changes); WhatIfChange storageAccountChange = result.Changes.FirstOrDefault(change => change.ResourceId.EndsWith("Microsoft.Storage/storageAccounts/tianotest102")); Assert.NotNull(storageAccountChange); Assert.Equal(ChangeType.Modify, storageAccountChange.ChangeType); Assert.NotNull(storageAccountChange.Delta); Assert.NotEmpty(storageAccountChange.Delta); WhatIfPropertyChange accountTypeChange = storageAccountChange.Delta .FirstOrDefault(propertyChange => propertyChange.Path.Equals("properties.accountType")); Assert.NotNull(accountTypeChange); Assert.Equal("Standard_LRS", accountTypeChange.Before); Assert.Equal("Standard_GRS", accountTypeChange.After); } }
public async Task WhatIf_ModifyResources_ReturnsModifyChanges() { // Arrange. JsonElement jsonParameter = JsonSerializer.Deserialize <JsonElement>(ResourceGroupTemplateParameters); if (!jsonParameter.TryGetProperty("parameters", out JsonElement parameter)) { parameter = jsonParameter; } var deployment = new Deployment(new DeploymentProperties(DeploymentMode.Incremental) { Template = ResourceGroupTemplate, ParametersJson = parameter }); // Modify account type: Standard_LRS => Standard_GRS. var deploymentWhatIf = new DeploymentWhatIf( new DeploymentWhatIfProperties(DeploymentMode.Incremental) { Template = ResourceGroupTemplateGRS, ParametersJson = parameter, WhatIfSettings = new DeploymentWhatIfSettings() { ResultFormat = WhatIfResultFormat.FullResourcePayloads } } ); string resourceGroupName = NewResourceGroupName(); var resourcegroup = (await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, ResourceGroup)).Value; var deploy = await DeploymentsOperations.StartCreateOrUpdateAsync(resourceGroupName, NewDeploymentName(), deployment); await WaitForCompletionAsync(deploy); // Act. var rawResult = await DeploymentsOperations.StartWhatIfAsync(resourceGroupName, NewDeploymentName(), deploymentWhatIf); var result = (await WaitForCompletionAsync(rawResult)).Value; // Assert. Assert.AreEqual("Succeeded", result.Status); Assert.NotNull(result.Changes); Assert.IsNotEmpty(result.Changes); WhatIfChange storageAccountChange = result.Changes.FirstOrDefault(change => change.ResourceId.EndsWith("Microsoft.Storage/storageAccounts/ramokaSATestAnother1")); Assert.NotNull(storageAccountChange); Assert.AreEqual(ChangeType.Modify, storageAccountChange.ChangeType); Assert.NotNull(storageAccountChange.Delta); Assert.IsNotEmpty(storageAccountChange.Delta); WhatIfPropertyChange accountTypeChange = storageAccountChange.Delta .FirstOrDefault(propertyChange => propertyChange.Path.Equals("properties.accountType")); Assert.NotNull(accountTypeChange); Assert.AreEqual("Standard_LRS", accountTypeChange.Before); Assert.AreEqual("Standard_GRS", accountTypeChange.After); }