/// <summary> /// Creates a new resource group and deployment using the passed template file option which /// can be user customized or from gallery templates. /// </summary> /// <param name="parameters">The create parameters</param> /// <returns>The created resource group</returns> public virtual PSResourceGroup CreatePSResourceGroup(CreatePSResourceGroupParameters parameters) { bool createDeployment = !string.IsNullOrEmpty(parameters.GalleryTemplateIdentity) || !string.IsNullOrEmpty(parameters.TemplateFile); bool resourceExists = ResourceManagementClient.ResourceGroups.CheckExistence(parameters.ResourceGroupName).Exists; ResourceGroupExtended resourceGroup = null; Action createOrUpdateResourceGroup = () => { resourceGroup = CreateOrUpdateResourceGroup(parameters.ResourceGroupName, parameters.Location, parameters.Tag); WriteVerbose(string.Format("Created resource group '{0}' in location '{1}'", resourceGroup.Name, resourceGroup.Location)); if (createDeployment) { ExecuteDeployment(parameters); } }; if (resourceExists && !parameters.Force) { parameters.ConfirmAction(parameters.Force, ProjectResources.ResourceGroupAlreadyExists, ProjectResources.NewResourceGroupMessage, parameters.DeploymentName, createOrUpdateResourceGroup); resourceGroup = ResourceManagementClient.ResourceGroups.Get(parameters.ResourceGroupName).ResourceGroup; } else { createOrUpdateResourceGroup(); } return(resourceGroup.ToPSResourceGroup(this, true)); }
/// <summary> /// Updates a resource group. /// </summary> /// <param name="parameters">The create parameters</param> /// <returns>The created resource group</returns> public virtual PSResourceGroup UpdatePSResourceGroup(UpdatePSResourceGroupParameters parameters) { ResourceGroupExtended resourceGroup = ResourceManagementClient.ResourceGroups.Get(parameters.ResourceGroupName).ResourceGroup; resourceGroup = CreateOrUpdateResourceGroup(parameters.ResourceGroupName, resourceGroup.Location, parameters.Tag); WriteVerbose(string.Format("Updated resource group '{0}' in location '{1}'", resourceGroup.Name, resourceGroup.Location)); return(resourceGroup.ToPSResourceGroup(this, true)); }