/// <summary>
        /// Gets the Location of the managed instance.
        /// </summary>
        /// <param name="resourceGroupName">The resource group the managed instance is in</param>
        /// <param name="managedInstanceName">The name of the managed instance</param>
        /// <returns></returns>
        public string GetManagedInstanceLocation(string resourceGroupName, string managedInstanceName)
        {
            AzureSqlManagedInstanceAdapter managedInstanceAdapter = new AzureSqlManagedInstanceAdapter(Context);
            var managedInstance = managedInstanceAdapter.GetManagedInstance(resourceGroupName, managedInstanceName);

            return(managedInstance.Location);
        }
Exemple #2
0
        /// <summary>
        /// Generates the model from user input.
        /// </summary>
        /// <param name="model">This is null since the instance doesn't exist yet</param>
        /// <returns>The generated model from user input</returns>
        protected override IEnumerable <Model.AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlManagedInstanceModel> model)
        {
            List <Model.AzureSqlManagedInstanceModel> newEntity = new List <Model.AzureSqlManagedInstanceModel>();

            Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();

            if (string.Equals(this.ParameterSetName, NewBySkuNameParameterSet, System.StringComparison.OrdinalIgnoreCase))
            {
                Sku.Name = SkuName;
            }
            else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase))
            {
                string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
                Sku.Name = editionShort + "_" + ComputeGeneration;
            }

            newEntity.Add(new Model.AzureSqlManagedInstanceModel()
            {
                Location                 = this.Location,
                ResourceGroupName        = this.ResourceGroupName,
                FullyQualifiedDomainName = this.Name,
                AdministratorLogin       = this.AdministratorCredential.UserName,
                AdministratorPassword    = this.AdministratorCredential.Password,
                Tags            = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
                Identity        = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
                LicenseType     = this.LicenseType,
                StorageSizeInGB = this.StorageSizeInGB,
                SubnetId        = this.SubnetId,
                VCores          = this.VCore,
                Sku             = Sku,
                Collation       = this.Collation
            });
            return(newEntity);
        }
Exemple #3
0
        /// <summary>
        /// This method is responsible to call the right API in the communication layer that will eventually send the information in the
        /// object to the REST endpoint
        /// </summary>
        /// <param name="model">The model object with the data to be sent to the REST endpoints</param>
        protected override ManagedInstanceAdvancedDataSecurityPolicyModel PersistChanges(ManagedInstanceAdvancedDataSecurityPolicyModel model)
        {
            model.IsEnabled = true;

            if (DoNotConfigureVulnerabilityAssessment)
            {
                ModelAdapter.SetManagedInstanceAdvancedDataSecurity(model);
            }
            else
            {
                // Deploy arm template to enable VA - only if VA at server level is not defined
                var vaAdapter = new SqlVulnerabilityAssessmentAdapter(DefaultContext);
                var vaModel   = vaAdapter.GetVulnerabilityAssessmentSettings(ResourceGroupName, InstanceName, "", ApplyToType.ManagedInstance);

                if (string.IsNullOrEmpty(vaModel.StorageAccountName))
                {
                    var instanceAdapter = new AzureSqlManagedInstanceAdapter(DefaultContext);
                    var instanceModel   = instanceAdapter.GetManagedInstance(ResourceGroupName, InstanceName);
                    ModelAdapter.EnableInstanceAdsWithVa(ResourceGroupName, InstanceName, instanceModel.Location, DeploymentName);
                }
                else
                {
                    ModelAdapter.SetManagedInstanceAdvancedDataSecurity(model);
                }
            }

            return(model);
        }
Exemple #4
0
        /// <summary>
        /// Generates the model from user input.
        /// </summary>
        /// <param name="model">This is null since the instance doesn't exist yet</param>
        /// <returns>The generated model from user input</returns>
        protected override IEnumerable <Model.AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlManagedInstanceModel> model)
        {
            List <Model.AzureSqlManagedInstanceModel> newEntity = new List <Model.AzureSqlManagedInstanceModel>();

            Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();

            if (string.Equals(this.ParameterSetName, NewBySkuNameParameterSet, System.StringComparison.OrdinalIgnoreCase))
            {
                Sku.Name = SkuName;
            }
            else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(this.ParameterSetName, NewByInstancePoolParentObjectParameterSet, System.StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(this.ParameterSetName, NewByInstancePoolResourceIdParameterSet, System.StringComparison.OrdinalIgnoreCase))
            {
                string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
                Sku.Name = editionShort + "_" + ComputeGeneration;
            }

            newEntity.Add(new AzureSqlManagedInstanceModel()
            {
                Location                 = this.Location,
                ResourceGroupName        = this.ResourceGroupName,
                FullyQualifiedDomainName = this.Name,
                AdministratorPassword    = (this.AdministratorCredential != null) ? this.AdministratorCredential.Password : null,
                AdministratorLogin       = (this.AdministratorCredential != null) ? this.AdministratorCredential.UserName : null,
                Tags        = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
                Identity    = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, null),
                LicenseType = this.LicenseType,
                // `-StorageSizeInGB 0` as a parameter to this cmdlet means "use default".
                // For non-MI database, we can just pass in 0 and the server will treat 0 as default.
                // However this is (currently) not the case for MI. We need to convert the 0 to null
                // here in client before sending to the server.
                StorageSizeInGB                  = SqlSkuUtils.ValueIfNonZero(this.StorageSizeInGB),
                SubnetId                         = this.SubnetId,
                VCores                           = this.VCore,
                Sku                              = Sku,
                Collation                        = this.Collation,
                PublicDataEndpointEnabled        = this.PublicDataEndpointEnabled,
                ProxyOverride                    = this.ProxyOverride,
                TimezoneId                       = this.TimezoneId,
                DnsZonePartner                   = this.DnsZonePartner,
                InstancePoolName                 = this.InstancePoolName,
                MinimalTlsVersion                = this.MinimalTlsVersion,
                RequestedBackupStorageRedundancy = this.BackupStorageRedundancy,
                MaintenanceConfigurationId       = this.MaintenanceConfigurationId,
                PrimaryUserAssignedIdentityId    = this.PrimaryUserAssignedIdentityId,
                KeyId                            = this.KeyId,
                Administrators                   = new Management.Sql.Models.ManagedInstanceExternalAdministrator()
                {
                    AzureADOnlyAuthentication = (this.EnableActiveDirectoryOnlyAuthentication.IsPresent) ? (bool?)true : null,
                    Login = this.ExternalAdminName,
                    Sid   = this.ExternalAdminSID
                },
                ZoneRedundant    = this.ZoneRedundant.IsPresent ? this.ZoneRedundant.ToBool() : (bool?)null,
                ServicePrincipal = ResourceServicePrincipalHelper.GetServicePrincipalObjectFromType(this.ServicePrincipalType ?? null)
            });;
            return(newEntity);
        }
 public void GetInstanceSkuPrefix()
 {
     Assert.Equal(
         "GP",
         AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix("GeneralPurpose"));
     Assert.Equal(
         "BC",
         AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix("BusinessCritical"));
 }
Exemple #6
0
        /// <summary>
        /// Constructs the model to send to the update API
        /// </summary>
        /// <param name="model">The result of the get operation</param>
        /// <returns>The model to send to the update</returns>
        protected override IEnumerable <AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <AzureSqlManagedInstanceModel> model)
        {
            AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name, "administrators/activedirectory");

            Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();

            // Get current edition and family
            string currentEdition           = existingInstance.Sku.Tier;
            string currentComputeGeneration = existingInstance.Sku.Family;

            // If either edition or compute generation are set, get the new sku
            if (this.Edition != null || this.ComputeGeneration != null)
            {
                string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(!string.IsNullOrWhiteSpace(Edition) ? this.Edition : currentEdition);
                Sku.Name   = editionShort + "_" + (!string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration);
                Sku.Tier   = !string.IsNullOrWhiteSpace(this.Edition) ? this.Edition : null;
                Sku.Family = !string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration;
            }
            else
            {
                Sku = existingInstance.Sku;
            }

            // Construct a new entity so we only send the relevant data to the Managed instance
            List <AzureSqlManagedInstanceModel> updateData = new List <AzureSqlManagedInstanceModel>();

            updateData.Add(model.FirstOrDefault());
            updateData[0].ResourceGroupName        = this.ResourceGroupName;
            updateData[0].ManagedInstanceName      = this.Name;
            updateData[0].FullyQualifiedDomainName = this.Name;
            updateData[0].Location = model.FirstOrDefault().Location;
            updateData[0].Sku      = Sku;
            updateData[0].AdministratorPassword = this.AdministratorPassword;
            updateData[0].LicenseType           = this.LicenseType ?? updateData[0].LicenseType;
            updateData[0].StorageSizeInGB       = this.StorageSizeInGB ?? model.FirstOrDefault().StorageSizeInGB;
            updateData[0].VCores = this.VCore ?? updateData[0].VCores;
            updateData[0].PublicDataEndpointEnabled = this.PublicDataEndpointEnabled ?? updateData[0].PublicDataEndpointEnabled;
            updateData[0].ProxyOverride             = this.ProxyOverride ?? this.ProxyOverride;
            updateData[0].Tags                             = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);
            updateData[0].Identity                         = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, model.FirstOrDefault().Identity);
            updateData[0].InstancePoolName                 = this.InstancePoolName ?? updateData[0].InstancePoolName;
            updateData[0].MinimalTlsVersion                = this.MinimalTlsVersion ?? updateData[0].MinimalTlsVersion;
            updateData[0].MaintenanceConfigurationId       = this.MaintenanceConfigurationId ?? updateData[0].MaintenanceConfigurationId;
            updateData[0].AdministratorLogin               = model.FirstOrDefault().AdministratorLogin;
            updateData[0].PrimaryUserAssignedIdentityId    = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId;
            updateData[0].KeyId                            = this.KeyId ?? updateData[0].KeyId;
            updateData[0].SubnetId                         = this.SubnetId ?? model.FirstOrDefault().SubnetId;
            updateData[0].ZoneRedundant                    = this.ZoneRedundant.IsPresent ? this.ZoneRedundant.ToBool() : (bool?)null;
            updateData[0].RequestedBackupStorageRedundancy = this.BackupStorageRedundancy ?? updateData[0].CurrentBackupStorageRedundancy;
            updateData[0].ServicePrincipal                 = ResourceServicePrincipalHelper.GetServicePrincipalObjectFromType(this.ServicePrincipalType ?? null);
            return(updateData);
        }
Exemple #7
0
        /// <summary>
        /// Constructs the model to send to the update API
        /// </summary>
        /// <param name="model">The result of the get operation</param>
        /// <returns>The model to send to the update</returns>
        protected override IEnumerable <AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <AzureSqlManagedInstanceModel> model)
        {
            AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name);

            Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();

            // Get current edition and family
            string currentEdition           = existingInstance.Sku.Tier;
            string currentComputeGeneration = existingInstance.Sku.Family;

            // If either edition or compute generation are set, get the new sku
            if (this.Edition != null || this.ComputeGeneration != null)
            {
                string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(!string.IsNullOrWhiteSpace(Edition) ? this.Edition : currentEdition);
                Sku.Name   = editionShort + "_" + (!string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration);
                Sku.Tier   = !string.IsNullOrWhiteSpace(this.Edition) ? this.Edition : null;
                Sku.Family = !string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration;
            }
            else
            {
                Sku = existingInstance.Sku;
            }

            // Construct a new entity so we only send the relevant data to the Managed instance
            List <AzureSqlManagedInstanceModel> updateData = new List <AzureSqlManagedInstanceModel>();

            updateData.Add(new AzureSqlManagedInstanceModel()
            {
                ResourceGroupName        = this.ResourceGroupName,
                ManagedInstanceName      = this.Name,
                FullyQualifiedDomainName = this.Name,
                Location = model.FirstOrDefault().Location,
                Sku      = Sku,
                AdministratorPassword = this.AdministratorPassword,
                LicenseType           = this.LicenseType,
                StorageSizeInGB       = this.StorageSizeInGB ?? model.FirstOrDefault().StorageSizeInGB,
                VCores = this.VCore,
                PublicDataEndpointEnabled = this.PublicDataEndpointEnabled,
                ProxyOverride             = this.ProxyOverride,
                Tags                          = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
                Identity                      = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, model.FirstOrDefault().Identity),
                InstancePoolName              = this.InstancePoolName,
                MinimalTlsVersion             = this.MinimalTlsVersion,
                MaintenanceConfigurationId    = this.MaintenanceConfigurationId,
                AdministratorLogin            = model.FirstOrDefault().AdministratorLogin,
                PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId,
                KeyId                         = this.KeyId
            });
            return(updateData);
        }
        /// <summary>
        /// Generates the model from user input.
        /// </summary>
        /// <param name="model">This is null since the instance doesn't exist yet</param>
        /// <returns>The generated model from user input</returns>
        protected override IEnumerable <Model.AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlManagedInstanceModel> model)
        {
            List <Model.AzureSqlManagedInstanceModel> newEntity = new List <Model.AzureSqlManagedInstanceModel>();

            Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();

            if (string.Equals(this.ParameterSetName, NewBySkuNameParameterSet, System.StringComparison.OrdinalIgnoreCase))
            {
                Sku.Name = SkuName;
            }
            else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(this.ParameterSetName, NewByInstancePoolParentObjectParameterSet, System.StringComparison.OrdinalIgnoreCase) ||
                     string.Equals(this.ParameterSetName, NewByInstancePoolResourceIdParameterSet, System.StringComparison.OrdinalIgnoreCase))
            {
                string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
                Sku.Name = editionShort + "_" + ComputeGeneration;
            }

            newEntity.Add(new AzureSqlManagedInstanceModel()
            {
                Location                 = this.Location,
                ResourceGroupName        = this.ResourceGroupName,
                FullyQualifiedDomainName = this.Name,
                AdministratorLogin       = this.AdministratorCredential.UserName,
                AdministratorPassword    = this.AdministratorCredential.Password,
                Tags        = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
                Identity    = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
                LicenseType = this.LicenseType,
                // `-StorageSizeInGB 0` as a parameter to this cmdlet means "use default".
                // For non-MI database, we can just pass in 0 and the server will treat 0 as default.
                // However this is (currently) not the case for MI. We need to convert the 0 to null
                // here in client before sending to the server.
                StorageSizeInGB           = SqlSkuUtils.ValueIfNonZero(this.StorageSizeInGB),
                SubnetId                  = this.SubnetId,
                VCores                    = this.VCore,
                Sku                       = Sku,
                Collation                 = this.Collation,
                PublicDataEndpointEnabled = this.PublicDataEndpointEnabled,
                ProxyOverride             = this.ProxyOverride,
                TimezoneId                = this.TimezoneId,
                DnsZonePartner            = this.DnsZonePartner,
                InstancePoolName          = this.InstancePoolName
            });
            return(newEntity);
        }
Exemple #9
0
        /// <summary>
        /// Constructs the model to send to the update API
        /// </summary>
        /// <param name="model">The result of the get operation</param>
        /// <returns>The model to send to the update</returns>
        protected override IEnumerable <AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <AzureSqlManagedInstanceModel> model)
        {
            AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name);

            Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();

            if (Edition != null)
            {
                string computeGeneration = existingInstance.Sku.Name.Contains(Constants.ComputeGenerationGen4) ? Constants.ComputeGenerationGen4 : Constants.ComputeGenerationGen5;
                string editionShort      = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
                Sku.Name = editionShort + "_" + computeGeneration;
                Sku.Tier = Edition;
            }
            else
            {
                Sku = null;
            }

            // Construct a new entity so we only send the relevant data to the Managed instance
            List <AzureSqlManagedInstanceModel> updateData = new List <AzureSqlManagedInstanceModel>();

            updateData.Add(new AzureSqlManagedInstanceModel()
            {
                ResourceGroupName        = this.ResourceGroupName,
                ManagedInstanceName      = this.Name,
                FullyQualifiedDomainName = this.Name,
                Location = model.FirstOrDefault().Location,
                Sku      = Sku,
                AdministratorPassword = this.AdministratorPassword,
                LicenseType           = this.LicenseType,
                StorageSizeInGB       = this.StorageSizeInGB ?? model.FirstOrDefault().StorageSizeInGB,
                VCores = this.VCore,
                PublicDataEndpointEnabled = this.PublicDataEndpointEnabled,
                ProxyOverride             = this.ProxyOverride,
                Tags             = TagsConversionHelper.CreateTagDictionary(Tag, validate: true),
                Identity         = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent),
                InstancePoolName = this.InstancePoolName
            });
            return(updateData);
        }