private PSApplicationGateway CreateApplicationGateway()
        {
            var applicationGateway = new PSApplicationGateway();

            applicationGateway.Name = this.Name;
            applicationGateway.ResourceGroupName = this.ResourceGroupName;
            applicationGateway.Location          = this.Location;
            applicationGateway.Sku = this.Sku;

            if (this.SslPolicy != null)
            {
                applicationGateway.SslPolicy = new PSApplicationGatewaySslPolicy();
                applicationGateway.SslPolicy = this.SslPolicy;
            }

            if (this.GatewayIPConfigurations != null)
            {
                applicationGateway.GatewayIPConfigurations = this.GatewayIPConfigurations?.ToList();
            }

            if (this.SslCertificates != null)
            {
                applicationGateway.SslCertificates = this.SslCertificates?.ToList();
            }

            if (this.AuthenticationCertificates != null)
            {
                applicationGateway.AuthenticationCertificates = this.AuthenticationCertificates?.ToList();
            }

            if (this.TrustedRootCertificate != null)
            {
                applicationGateway.TrustedRootCertificates = this.TrustedRootCertificate?.ToList();
            }

            if (this.FrontendIPConfigurations != null)
            {
                applicationGateway.FrontendIPConfigurations = this.FrontendIPConfigurations?.ToList();
            }

            if (this.FrontendPorts != null)
            {
                applicationGateway.FrontendPorts = this.FrontendPorts?.ToList();
            }

            if (this.Probes != null)
            {
                applicationGateway.Probes = this.Probes?.ToList();
            }

            if (this.BackendAddressPools != null)
            {
                applicationGateway.BackendAddressPools = this.BackendAddressPools?.ToList();
            }

            if (this.BackendHttpSettingsCollection != null)
            {
                applicationGateway.BackendHttpSettingsCollection = this.BackendHttpSettingsCollection?.ToList();
            }

            if (this.HttpListeners != null)
            {
                applicationGateway.HttpListeners = this.HttpListeners?.ToList();
            }

            if (this.UrlPathMaps != null)
            {
                applicationGateway.UrlPathMaps = this.UrlPathMaps?.ToList();
            }

            if (this.RequestRoutingRules != null)
            {
                applicationGateway.RequestRoutingRules = this.RequestRoutingRules?.ToList();
            }

            if (this.RewriteRuleSet != null)
            {
                applicationGateway.RewriteRuleSets = this.RewriteRuleSet?.ToList();
            }

            if (this.RedirectConfigurations != null)
            {
                applicationGateway.RedirectConfigurations = this.RedirectConfigurations?.ToList();
            }

            if (this.WebApplicationFirewallConfiguration != null)
            {
                applicationGateway.WebApplicationFirewallConfiguration = this.WebApplicationFirewallConfiguration;
            }

            if (!string.IsNullOrEmpty(this.FirewallPolicyId))
            {
                applicationGateway.FirewallPolicy    = new PSResourceId();
                applicationGateway.FirewallPolicy.Id = this.FirewallPolicyId;
            }

            if (this.AutoscaleConfiguration != null)
            {
                applicationGateway.AutoscaleConfiguration = this.AutoscaleConfiguration;
            }

            if (this.EnableHttp2.IsPresent)
            {
                applicationGateway.EnableHttp2 = true;
            }

            if (this.EnableFIPS.IsPresent)
            {
                applicationGateway.EnableFips = true;
            }

            if (this.Zone != null)
            {
                applicationGateway.Zones = this.Zone?.ToList();
            }

            if (this.UserAssignedIdentityId != null)
            {
                applicationGateway.Identity = new PSManagedServiceIdentity
                {
                    Type = MNM.ResourceIdentityType.UserAssigned,
                    UserAssignedIdentities = new Dictionary <string, PSManagedServiceIdentityUserAssignedIdentitiesValue>
                    {
                        { this.UserAssignedIdentityId, new PSManagedServiceIdentityUserAssignedIdentitiesValue() }
                    }
                };
            }
            else if (this.Identity != null)
            {
                applicationGateway.Identity = this.Identity;
            }

            if (this.CustomErrorConfiguration != null)
            {
                applicationGateway.CustomErrorConfigurations = this.CustomErrorConfiguration?.ToList();
            }

            // Normalize the IDs
            ApplicationGatewayChildResourceHelper.NormalizeChildIds(applicationGateway, this.ResourceGroupName, this.Name);

            // Map to the sdk object
            var appGwModel = NetworkResourceManagerProfile.Mapper.Map <MNM.ApplicationGateway>(applicationGateway);

            appGwModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            // Execute the Create ApplicationGateway call
            this.ApplicationGatewayClient.CreateOrUpdate(this.ResourceGroupName, this.Name, appGwModel);

            var getApplicationGateway = this.GetApplicationGateway(this.ResourceGroupName, this.Name);

            return(getApplicationGateway);
        }
        private PSApplicationGateway CreateApplicationGateway()
        {
            var applicationGateway = new PSApplicationGateway();

            applicationGateway.Name = this.Name;
            applicationGateway.ResourceGroupName = this.ResourceGroupName;
            applicationGateway.Location          = this.Location;
            applicationGateway.Sku = this.Sku;

            if (this.GatewayIPConfigurations != null)
            {
                applicationGateway.GatewayIPConfigurations = this.GatewayIPConfigurations;
            }

            if (this.SslCertificates != null)
            {
                applicationGateway.SslCertificates = this.SslCertificates;
            }

            if (this.FrontendIPConfigurations != null)
            {
                applicationGateway.FrontendIPConfigurations = this.FrontendIPConfigurations;
            }

            if (this.FrontendPorts != null)
            {
                applicationGateway.FrontendPorts = this.FrontendPorts;
            }

            if (this.Probes != null)
            {
                applicationGateway.Probes = this.Probes;
            }

            if (this.BackendAddressPools != null)
            {
                applicationGateway.BackendAddressPools = this.BackendAddressPools;
            }

            if (this.BackendHttpSettingsCollection != null)
            {
                applicationGateway.BackendHttpSettingsCollection = this.BackendHttpSettingsCollection;
            }

            if (this.HttpListeners != null)
            {
                applicationGateway.HttpListeners = this.HttpListeners;
            }

            if (this.UrlPathMaps != null)
            {
                applicationGateway.UrlPathMaps = this.UrlPathMaps;
            }

            if (this.RequestRoutingRules != null)
            {
                applicationGateway.RequestRoutingRules = this.RequestRoutingRules;
            }

            // Normalize the IDs
            ApplicationGatewayChildResourceHelper.NormalizeChildResourcesId(applicationGateway);

            // Map to the sdk object
            var appGwModel = Mapper.Map <MNM.ApplicationGateway>(applicationGateway);

            appGwModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            // Execute the Create ApplicationGateway call
            this.ApplicationGatewayClient.CreateOrUpdate(this.ResourceGroupName, this.Name, appGwModel);

            var getApplicationGateway = this.GetApplicationGateway(this.ResourceGroupName, this.Name);

            return(getApplicationGateway);
        }
Ejemplo n.º 3
0
        private PSApplicationGateway CreateApplicationGateway()
        {
            var applicationGateway = new PSApplicationGateway();

            applicationGateway.Name = this.Name;
            applicationGateway.ResourceGroupName = this.ResourceGroupName;
            applicationGateway.Location          = this.Location;
            applicationGateway.Sku = this.Sku;

            if (this.SslPolicy != null)
            {
                applicationGateway.SslPolicy = new PSApplicationGatewaySslPolicy();
                applicationGateway.SslPolicy = this.SslPolicy;
            }

            if (this.GatewayIPConfigurations != null)
            {
                applicationGateway.GatewayIPConfigurations = this.GatewayIPConfigurations;
            }

            if (this.SslCertificates != null)
            {
                applicationGateway.SslCertificates = this.SslCertificates;
            }

            if (this.AuthenticationCertificates != null)
            {
                applicationGateway.AuthenticationCertificates = this.AuthenticationCertificates;
            }

            if (this.TrustedRootCertificate != null)
            {
                applicationGateway.TrustedRootCertificates = this.TrustedRootCertificate;
            }

            if (this.FrontendIPConfigurations != null)
            {
                applicationGateway.FrontendIPConfigurations = this.FrontendIPConfigurations;
            }

            if (this.FrontendPorts != null)
            {
                applicationGateway.FrontendPorts = this.FrontendPorts;
            }

            if (this.Probes != null)
            {
                applicationGateway.Probes = this.Probes;
            }

            if (this.BackendAddressPools != null)
            {
                applicationGateway.BackendAddressPools = this.BackendAddressPools;
            }

            if (this.BackendHttpSettingsCollection != null)
            {
                applicationGateway.BackendHttpSettingsCollection = this.BackendHttpSettingsCollection;
            }

            if (this.HttpListeners != null)
            {
                applicationGateway.HttpListeners = this.HttpListeners;
            }

            if (this.UrlPathMaps != null)
            {
                applicationGateway.UrlPathMaps = this.UrlPathMaps;
            }

            if (this.RequestRoutingRules != null)
            {
                applicationGateway.RequestRoutingRules = this.RequestRoutingRules;
            }

            if (this.RedirectConfigurations != null)
            {
                applicationGateway.RedirectConfigurations = this.RedirectConfigurations;
            }

            if (this.WebApplicationFirewallConfiguration != null)
            {
                applicationGateway.WebApplicationFirewallConfiguration = this.WebApplicationFirewallConfiguration;
            }

            if (this.AutoscaleConfiguration != null)
            {
                applicationGateway.AutoscaleConfiguration = this.AutoscaleConfiguration;
            }

            if (this.EnableHttp2.IsPresent)
            {
                applicationGateway.EnableHttp2 = true;
            }

            if (this.EnableFIPS.IsPresent)
            {
                applicationGateway.EnableFips = true;
            }

            if (this.Zone != null)
            {
                applicationGateway.Zones = this.Zone;
            }

            // Normalize the IDs
            ApplicationGatewayChildResourceHelper.NormalizeChildResourcesId(applicationGateway);

            // Map to the sdk object
            var appGwModel = NetworkResourceManagerProfile.Mapper.Map <MNM.ApplicationGateway>(applicationGateway);

            appGwModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            // Execute the Create ApplicationGateway call
            this.ApplicationGatewayClient.CreateOrUpdate(this.ResourceGroupName, this.Name, appGwModel);

            var getApplicationGateway = this.GetApplicationGateway(this.ResourceGroupName, this.Name);

            return(getApplicationGateway);
        }
        public static void NormalizeChildResourcesId(PSApplicationGateway applicationGateway)
        {
            // Normalize GatewayIpConfiguration
            if (applicationGateway.GatewayIpConfigurations != null)
            {
                foreach (var gatewayIpConfig in applicationGateway.GatewayIpConfigurations)
                {
                    gatewayIpConfig.Id = string.Empty;
                }
            }

            // Normalize SslCertificates
            if (applicationGateway.SslCertificates != null)
            {
                foreach (var sslCertificate in applicationGateway.SslCertificates)
                {
                    sslCertificate.Id = string.Empty;
                }
            }

            // Normalize FrontendIpConfiguration
            if (applicationGateway.FrontendIpConfigurations != null)
            {
                foreach (var frontendIpConfiguration in applicationGateway.FrontendIpConfigurations)
                {
                    frontendIpConfiguration.Id = string.Empty;
                }
            }

            // Normalize FrontendPort
            if (applicationGateway.FrontendPorts != null)
            {
                foreach (var frontendPort in applicationGateway.FrontendPorts)
                {
                    frontendPort.Id = string.Empty;
                }
            }

            // Normalize BackendAddressPool
            if (applicationGateway.BackendAddressPools != null)
            {
                foreach (var backendAddressPool in applicationGateway.BackendAddressPools)
                {
                    backendAddressPool.Id = string.Empty;
                }
            }

            // Normalize BackendHttpSettings
            if (applicationGateway.BackendHttpSettingsCollection != null)
            {
                foreach (var backendHttpSettings in applicationGateway.BackendHttpSettingsCollection)
                {
                    backendHttpSettings.Id = string.Empty;
                }
            }

            // Normalize HttpListener
            if (applicationGateway.HttpListeners != null)
            {
                foreach (var httpListener in applicationGateway.HttpListeners)
                {
                    httpListener.Id = string.Empty;

                    httpListener.FrontendPort.Id = NormalizeApplicationGatewayNameChildResourceIds(
                        httpListener.FrontendPort.Id,
                        applicationGateway.ResourceGroupName,
                        applicationGateway.Name);

                    if (null != httpListener.FrontendIpConfiguration)
                    {
                        httpListener.FrontendIpConfiguration.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            httpListener.FrontendIpConfiguration.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }

                    if (null != httpListener.SslCertificate)
                    {
                        httpListener.SslCertificate.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            httpListener.SslCertificate.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }
                }
            }

            // Normalize RequestRoutingRule
            if (applicationGateway.RequestRoutingRules != null)
            {
                foreach (var requestRoutingRule in applicationGateway.RequestRoutingRules)
                {
                    requestRoutingRule.Id = string.Empty;

                    requestRoutingRule.HttpListener.Id = NormalizeApplicationGatewayNameChildResourceIds(
                        requestRoutingRule.HttpListener.Id,
                        applicationGateway.ResourceGroupName,
                        applicationGateway.Name);

                    requestRoutingRule.BackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
                        requestRoutingRule.BackendAddressPool.Id,
                        applicationGateway.ResourceGroupName,
                        applicationGateway.Name);

                    requestRoutingRule.BackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
                        requestRoutingRule.BackendHttpSettings.Id,
                        applicationGateway.ResourceGroupName,
                        applicationGateway.Name);
                }
            }
        }
        public static void NormalizeChildResourcesId(PSApplicationGateway applicationGateway)
        {
            // Normalize GatewayIpConfiguration
            if (applicationGateway.GatewayIPConfigurations != null)
            {
                foreach (var gatewayIpConfig in applicationGateway.GatewayIPConfigurations)
                {
                    gatewayIpConfig.Id = string.Empty;
                }
            }

            // Normalize SslCertificates
            if (applicationGateway.SslCertificates != null)
            {
                foreach (var sslCertificate in applicationGateway.SslCertificates)
                {
                    sslCertificate.Id = string.Empty;
                }
            }

            // Normalize AuthenticationCertificates
            if (applicationGateway.AuthenticationCertificates != null)
            {
                foreach (var authCertificate in applicationGateway.AuthenticationCertificates)
                {
                    authCertificate.Id = string.Empty;
                }
            }

            // Normalize TrustedRootCertificates
            if (applicationGateway.TrustedRootCertificates != null)
            {
                foreach (var trustedRootCertificate in applicationGateway.TrustedRootCertificates)
                {
                    trustedRootCertificate.Id = string.Empty;
                }
            }

            // Normalize FrontendIpConfiguration
            if (applicationGateway.FrontendIPConfigurations != null)
            {
                foreach (var frontendIpConfiguration in applicationGateway.FrontendIPConfigurations)
                {
                    frontendIpConfiguration.Id = string.Empty;
                }
            }

            // Normalize FrontendPort
            if (applicationGateway.FrontendPorts != null)
            {
                foreach (var frontendPort in applicationGateway.FrontendPorts)
                {
                    frontendPort.Id = string.Empty;
                }
            }

            // Normalize BackendAddressPool
            if (applicationGateway.BackendAddressPools != null)
            {
                foreach (var backendAddressPool in applicationGateway.BackendAddressPools)
                {
                    backendAddressPool.Id = string.Empty;
                }
            }

            // Normalize Probe
            if (applicationGateway.Probes != null)
            {
                foreach (var probe in applicationGateway.Probes)
                {
                    probe.Id = string.Empty;
                }
            }

            // Normalize BackendHttpSettings
            if (applicationGateway.BackendHttpSettingsCollection != null)
            {
                foreach (var backendHttpSettings in applicationGateway.BackendHttpSettingsCollection)
                {
                    backendHttpSettings.Id = string.Empty;

                    if (null != backendHttpSettings.Probe)
                    {
                        backendHttpSettings.Probe.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            backendHttpSettings.Probe.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }

                    if (null != backendHttpSettings.AuthenticationCertificates)
                    {
                        foreach (var authCert in backendHttpSettings.AuthenticationCertificates)
                        {
                            authCert.Id = NormalizeApplicationGatewayNameChildResourceIds(
                                authCert.Id,
                                applicationGateway.ResourceGroupName,
                                applicationGateway.Name);
                        }
                    }

                    if (null != backendHttpSettings.TrustedRootCertificates)
                    {
                        foreach (var trustedRootCert in backendHttpSettings.TrustedRootCertificates)
                        {
                            trustedRootCert.Id = NormalizeApplicationGatewayNameChildResourceIds(
                                trustedRootCert.Id,
                                applicationGateway.ResourceGroupName,
                                applicationGateway.Name);
                        }
                    }
                }
            }

            // Normalize HttpListener
            if (applicationGateway.HttpListeners != null)
            {
                foreach (var httpListener in applicationGateway.HttpListeners)
                {
                    httpListener.Id = string.Empty;

                    httpListener.FrontendPort.Id = NormalizeApplicationGatewayNameChildResourceIds(
                        httpListener.FrontendPort.Id,
                        applicationGateway.ResourceGroupName,
                        applicationGateway.Name);

                    if (null != httpListener.FrontendIpConfiguration)
                    {
                        httpListener.FrontendIpConfiguration.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            httpListener.FrontendIpConfiguration.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }

                    if (null != httpListener.SslCertificate)
                    {
                        httpListener.SslCertificate.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            httpListener.SslCertificate.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }
                }
            }

            // Normalize UrlPathMap
            if (applicationGateway.UrlPathMaps != null)
            {
                foreach (var urlPathMap in applicationGateway.UrlPathMaps)
                {
                    urlPathMap.Id = string.Empty;

                    if (null != urlPathMap.DefaultBackendAddressPool)
                    {
                        urlPathMap.DefaultBackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            urlPathMap.DefaultBackendAddressPool.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }
                    if (null != urlPathMap.DefaultBackendHttpSettings)
                    {
                        urlPathMap.DefaultBackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            urlPathMap.DefaultBackendHttpSettings.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }
                    if (null != urlPathMap.DefaultRedirectConfiguration)
                    {
                        urlPathMap.DefaultRedirectConfiguration.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            urlPathMap.DefaultRedirectConfiguration.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }

                    foreach (var pathRule in urlPathMap.PathRules)
                    {
                        if (null != pathRule.BackendAddressPool)
                        {
                            pathRule.BackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
                                pathRule.BackendAddressPool.Id,
                                applicationGateway.ResourceGroupName,
                                applicationGateway.Name);
                        }

                        if (null != pathRule.BackendHttpSettings)
                        {
                            pathRule.BackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
                                pathRule.BackendHttpSettings.Id,
                                applicationGateway.ResourceGroupName,
                                applicationGateway.Name);
                        }

                        if (null != pathRule.RedirectConfiguration)
                        {
                            pathRule.RedirectConfiguration.Id = NormalizeApplicationGatewayNameChildResourceIds(
                                pathRule.RedirectConfiguration.Id,
                                applicationGateway.ResourceGroupName,
                                applicationGateway.Name);
                        }
                    }
                }
            }

            // Normalize RequestRoutingRule
            if (applicationGateway.RequestRoutingRules != null)
            {
                foreach (var requestRoutingRule in applicationGateway.RequestRoutingRules)
                {
                    requestRoutingRule.Id = string.Empty;

                    requestRoutingRule.HttpListener.Id = NormalizeApplicationGatewayNameChildResourceIds(
                        requestRoutingRule.HttpListener.Id,
                        applicationGateway.ResourceGroupName,
                        applicationGateway.Name);

                    if (null != requestRoutingRule.BackendAddressPool)
                    {
                        requestRoutingRule.BackendAddressPool.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            requestRoutingRule.BackendAddressPool.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }

                    if (null != requestRoutingRule.BackendHttpSettings)
                    {
                        requestRoutingRule.BackendHttpSettings.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            requestRoutingRule.BackendHttpSettings.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }

                    if (null != requestRoutingRule.UrlPathMap)
                    {
                        requestRoutingRule.UrlPathMap.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            requestRoutingRule.UrlPathMap.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }

                    if (null != requestRoutingRule.RedirectConfiguration)
                    {
                        requestRoutingRule.RedirectConfiguration.Id = NormalizeApplicationGatewayNameChildResourceIds(
                            requestRoutingRule.RedirectConfiguration.Id,
                            applicationGateway.ResourceGroupName,
                            applicationGateway.Name);
                    }
                }

                // Normalize RedirectConfiguration
                if (applicationGateway.RedirectConfigurations != null)
                {
                    foreach (var redirectConfiguration in applicationGateway.RedirectConfigurations)
                    {
                        redirectConfiguration.Id = string.Empty;

                        if (null != redirectConfiguration.TargetListener)
                        {
                            redirectConfiguration.TargetListener.Id = NormalizeApplicationGatewayNameChildResourceIds(
                                redirectConfiguration.TargetListener.Id,
                                applicationGateway.ResourceGroupName,
                                applicationGateway.Name);
                        }
                    }
                }
            }
        }