protected override void Render(AzureDeploymentTemplate template, IHaveInfrastructure <JsonDefinedInfrastructure> elementWithInfrastructure, IAzureInfrastructureEnvironment environment,
                                       string resourceGroup, string location)
        {
            var resourcesTemplate = JObject.Parse(elementWithInfrastructure.Infrastructure.Template);

            Merge(template.Parameters, resourcesTemplate);

            if (elementWithInfrastructure.Infrastructure.Parameters != null)
            {
                Merge(template.ParameterValues, JObject.Parse(elementWithInfrastructure.Infrastructure.Parameters));
            }

            var variables = resourcesTemplate["variables"] as JObject;

            if (variables != null)
            {
                foreach (var v in variables)
                {
                    template.Variables.Add(v.Key, v.Value.ToString());
                }
            }

            var resources = resourcesTemplate["resources"] as JArray;

            if (resources != null)
            {
                foreach (var resource in resources)
                {
                    template.Resources.Add((JObject)resource);
                }
            }
        }
예제 #2
0
        protected override void Render(AzureDeploymentTemplate template,
                                       IHaveInfrastructure <DeviceProvisioningService> elementWithInfrastructure,
                                       IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
        {
            var dps = elementWithInfrastructure.Infrastructure;

            template.Resources.Add(PostProcess(new JObject
            {
                ["type"]       = "Microsoft.Devices/provisioningServices",
                ["name"]       = dps.Name,
                ["apiVersion"] = dps.ApiVersion,
                ["location"]   = location,
                ["properties"] = new JObject
                {
                    ["iotHubs"] = new JArray(dps.IotHubs.Select(iothub =>
                                                                new JObject
                    {
                        ["name"]             = iothub.Url,
                        ["connectionString"] = iothub.OwnerConnectionString.Value.ToString(),
                        ["location"]         = location
                    }))
                },
                ["dependsOn"] = new JArray(dps.IotHubs.Select(iothub => iothub.ResourceIdReference).ToArray())
            }));
        }
 protected override void Render(AzureDeploymentTemplate template, IHaveInfrastructure <KeyVault> elementWithInfrastructure, IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
 {
     template.Resources.Add(new JObject
     {
         ["type"]       = "Microsoft.KeyVault/vaults",
         ["name"]       = elementWithInfrastructure.Infrastructure.Name,
         ["apiVersion"] = "2015-06-01",
         ["location"]   = location,
         ["properties"] = new JObject
         {
             ["enabledForDeployment"]         = false,
             ["enabledForTemplateDeployment"] = false,
             ["enabledForDiskEncryption"]     = false,
             ["accessPolicies"] = new JArray(
                 environment.AdministratorUserIds.Select(s => new JObject
             {
                 ["tenantId"]    = environment.Tenant,
                 ["objectId"]    = s,
                 ["permissions"] = new JObject
                 {
                     ["keys"]    = new JArray("Get", "List", "Update", "Create", "Import", "Delete", "Backup", "Restore"),
                     ["secrets"] = new JArray("All")
                 }
             })
                 .Cast <object>().ToArray()
                 ),
             ["tenantId"] = environment.Tenant,
             ["sku"]      = new JObject
             {
                 ["name"]   = "Standard",
                 ["family"] = "A"
             }
         }
     });
 }
예제 #4
0
        protected override void Render(AzureDeploymentTemplate template,
                                       IHaveInfrastructure <FunctionAppService> elementWithInfrastructure,
                                       IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
        {
            var appServicePlan = AppServicePlan(elementWithInfrastructure, location);

            if (appServicePlan != null)
            {
                template.Resources.Add(PostProcess(appServicePlan));
            }

            var functionApp = Template(
                "Microsoft.Web/sites",
                elementWithInfrastructure.Infrastructure.Name,
                location,
                ApiVersion
                );

            if (appServicePlan != null)
            {
                AddHiddenRelatedToAppServicePlan(elementWithInfrastructure, functionApp);
            }

            functionApp["properties"] = Properties(elementWithInfrastructure);
            AddSubResources(elementWithInfrastructure, functionApp);

            AddDependsOn(elementWithInfrastructure, location, functionApp);
            AddIdentity(elementWithInfrastructure, functionApp);
            functionApp["kind"] = "functionapp";

            template.Resources.Add(PostProcess(functionApp));
        }
        protected virtual JArray HttpListeners(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
        {
            return(new JArray(elementWithInfrastructure.Infrastructure.Listeners.Select(p =>
            {
                var properties = new JObject
                {
                    ["FrontendIPConfiguration"] = new JObject
                    {
                        ["Id"] = $"[concat({elementWithInfrastructure.Infrastructure.ResourceIdReferenceContent}, '/frontendIPConfigurations/{p.Ip.Name}')]"
                    },
                    ["FrontendPort"] = new JObject
                    {
                        ["Id"] = $"[concat({elementWithInfrastructure.Infrastructure.ResourceIdReferenceContent}, '/frontendPorts/{p.Port.Name}')]"
                    },
                    ["Protocol"] = p.Protocol
                };

                if (!string.IsNullOrEmpty(p.HostName))
                {
                    properties["HostName"] = p.HostName;
                }
                if (p is ApplicationGateway.HttpsListener h)
                {
                    properties["RequireServerNameIndication"] = h.RequireServerNameIndication.ToString().ToLowerInvariant();
                }

                return new JObject
                {
                    ["name"] = p.Name,
                    ["properties"] = properties
                };
            })));
        }
        protected override void Render(AzureDeploymentTemplate template, IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure,
                                       IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
        {
            var gateway = Template(
                "Microsoft.Network/applicationGateways",
                elementWithInfrastructure.Infrastructure.Name,
                location,
                "2018-08-01");

            gateway["zones"] = new JArray();

            gateway["dependsOn"] = new JArray(
                elementWithInfrastructure.Infrastructure.PublicIpAddress.Infrastructure.ResourceIdReference,
                elementWithInfrastructure.Infrastructure.VirtualNetwork.Infrastructure.ResourceIdReference);

            gateway["properties"] = new JObject
            {
                ["sku"] = Sku(elementWithInfrastructure, environment),
                ["gatewayIPConfigurations"]  = GatewayIPConfigurations(elementWithInfrastructure, environment),
                ["frontendIPConfigurations"] = FrontendIPConfigurations(elementWithInfrastructure, environment),
                ["frontendPorts"]            = FrontendPorts(elementWithInfrastructure, environment),
                ["probes"] = Probes(elementWithInfrastructure, environment),
                ["backendAddressPools"]           = BackendPools(elementWithInfrastructure, environment),
                ["backendHttpSettingsCollection"] = BackendHttpSettings(elementWithInfrastructure, environment),
                ["httpListeners"]       = HttpListeners(elementWithInfrastructure, environment),
                ["urlPathMaps"]         = UrlPathMaps(elementWithInfrastructure, environment),
                ["requestRoutingRules"] = RequestRoutingRules(elementWithInfrastructure, environment),
                ["webApplicationFirewallConfiguration"] = WebApplicationFirewallConfiguration(elementWithInfrastructure, environment)
            };

            template.Resources.Add(PostProcess(gateway));
        }
예제 #7
0
        protected override void Render(AzureDeploymentTemplate template,
                                       IHaveInfrastructure <VirtualNetwork> elementWithInfrastructure,
                                       IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
        {
            var network = Template(
                "Microsoft.Network/virtualNetworks",
                elementWithInfrastructure.Infrastructure.Name,
                location,
                "2018-08-01");

            network["properties"] = new JObject
            {
                ["addressSpace"] = new JObject
                {
                    ["addressPrefixes"] = new JArray(elementWithInfrastructure.Infrastructure.Prefix)
                },
                ["subnets"] = new JArray(elementWithInfrastructure.Infrastructure.Subnets.Select(subnet => new JObject
                {
                    ["name"]       = subnet.Name,
                    ["properties"] = new JObject
                    {
                        ["addressPrefix"] = subnet.Prefix
                    }
                }))
            };

            template.Resources.Add(PostProcess(network));
        }
        protected override JObject Properties(IHaveInfrastructure <AppService> elementWithInfrastructure)
        {
            var properties = base.Properties(elementWithInfrastructure);

            properties["clientAffinityEnabled"] = false;
            return(properties);
        }
예제 #9
0
        protected override void Render(AzureDeploymentTemplate template, IHaveInfrastructure<IoTHub> elementWithInfrastructure,
            IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
        {
            var hub = elementWithInfrastructure.Infrastructure;

            template.Resources.Add(PostProcess(new JObject
            {
                ["apiVersion"] = hub.ApiVersion,
                ["type"] = "Microsoft.Devices/iotHubs",
                ["name"] = hub.Name,
                ["location"] = location,
                ["sku"] = new JObject
                {
                    ["name"] = "F1",
                    ["capacity"] = 1
                }
            }));

            foreach (var consumerGroup in hub.ConsumerGroups)
            {
                template.Resources.Add(PostProcess(new JObject
                {
                    ["apiVersion"] = hub.ApiVersion,
                    ["type"] = "Microsoft.Devices/iotHubs/eventhubEndpoints/ConsumerGroups",
                    ["name"] = $"{hub.Name}/events/{consumerGroup}",
                    ["dependsOn"] = new JArray
                    {
                        hub.ResourceIdReference
                    }
                }));
            }
        }
        protected override void Render(
            AzureDeploymentTemplate template,
            IHaveInfrastructure <WebAppService> elementWithInfrastructure,
            IAzureInfrastructureEnvironment environment,
            string resourceGroup,
            string location)
        {
            var name = elementWithInfrastructure.Infrastructure.Name;

            template.Resources.Add(PostProcess(AppServicePlan(elementWithInfrastructure, location)));

            var appService = new JObject
            {
                ["type"]       = "Microsoft.Web/sites",
                ["name"]       = name,
                ["apiVersion"] = ApiVersion,
                ["location"]   = location,
                ["properties"] = Properties(elementWithInfrastructure),
            };

            AddHiddenRelatedToAppServicePlan(elementWithInfrastructure, appService);
            AddSubResources(elementWithInfrastructure, appService);
            AddDependsOn(elementWithInfrastructure, location, appService);
            AddIdentity(elementWithInfrastructure, appService);
            template.Resources.Add(PostProcess(appService));
        }
 protected virtual JObject Sku(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
 {
     return(new JObject
     {
         ["name"] = "WAF_Medium",
         ["tier"] = "WAF",
         ["capacity"] = "2"
     });
 }
예제 #12
0
        protected override JObject Properties(IHaveInfrastructure <AppService> elementWithInfrastructure)
        {
            var properties = base.Properties(elementWithInfrastructure);

            properties["serverFarmId"] =
                $"[concat(resourceGroup().id, \'/providers/Microsoft.Web/serverfarms/\', \'{elementWithInfrastructure.Infrastructure.Name}\')]";
            properties["hostingEnvironment"] = "";
            return(properties);
        }
        protected void AddDependsOn(IHaveInfrastructure <AppService> elementWithInfrastructure, JObject template)
        {
            var dependsOn = DependsOn(elementWithInfrastructure);

            if (dependsOn.Any())
            {
                template["dependsOn"] = new JArray(dependsOn);
            }
        }
        protected virtual JObject Properties(IHaveInfrastructure <AppService> elementWithInfrastructure)
        {
            var appService = elementWithInfrastructure.Infrastructure;
            var properties = new JObject {
                ["name"] = appService.Name
            };

            return(properties);
        }
예제 #15
0
 protected void AddHiddenRelatedToAppServicePlan(IHaveInfrastructure <AppService> elementWithInfrastructure, JObject template)
 {
     template["tags"] = new JObject
     {
         [
             $"[concat(\'hidden-related:\', resourceGroup().id, \'/providers/Microsoft.Web/serverfarms/\', \'{elementWithInfrastructure.Infrastructure.Name}\')]"
         ] = "empty"
     };
 }
예제 #16
0
 protected virtual void AddIdentity(IHaveInfrastructure <AppService> elementWithInfrastructure, JObject appService)
 {
     if (elementWithInfrastructure.Infrastructure.UseSystemAssignedIdentity)
     {
         appService["identity"] = new JObject
         {
             ["type"] = "SystemAssigned"
         };
     }
 }
 protected virtual JObject WebApplicationFirewallConfiguration(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
 {
     return(new JObject
     {
         ["enabled"] = true,
         ["firewallMode"] = "Detection",
         ["ruleSetType"] = "OWASP",
         ["ruleSetVersion"] = "3.0"
     });
 }
 protected virtual JArray FrontendPorts(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
 {
     return(new JArray(elementWithInfrastructure.Infrastructure.FrontendPorts.Select(p => new JObject
     {
         ["name"] = p.Name,
         ["properties"] = new JObject
         {
             ["Port"] = p.Port
         }
     })));
 }
        private bool DependsOnConfiguration(IHaveInfrastructure x, IHaveInfrastructure y)
        {
            var configurable = x.Infrastructure as IConfigurable;

            if (configurable == null)
            {
                return(false);
            }

            return(configurable.IsConfigurationDependentOn(y));
        }
예제 #20
0
        protected override void Render(AzureDeploymentTemplate template, IHaveInfrastructure <ServiceBus> elementWithInfrastructure,
                                       IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
        {
            var serviceBus = elementWithInfrastructure.Infrastructure;

            AddNamespace(template, serviceBus, location);

            foreach (var queue in serviceBus.Queues)
            {
                template.Resources.Add(new JObject
                {
                    ["name"]       = $"{serviceBus.Name}/{queue}",
                    ["type"]       = "Microsoft.ServiceBus/namespaces/queues",
                    ["apiVersion"] = "2015-08-01",
                    ["location"]   = location,
                    ["properties"] = new JObject
                    {
                        ["defaultMessageTimeToLive"]         = "14.00:00:00",
                        ["maxSizeInMegabytes"]               = "1024",
                        ["deadLetteringOnMessageExpiration"] = false,
                        ["requiresDuplicateDetection"]       = false,
                        ["requiresSession"]    = false,
                        ["enablePartitioning"] = true,
                    },
                    ["dependsOn"] = new JArray
                    {
                        serviceBus.ResourceIdReference
                    }
                });
            }

            foreach (var topic in serviceBus.Topics)
            {
                template.Resources.Add(new JObject
                {
                    ["name"]       = $"{serviceBus.Name}/{topic}",
                    ["type"]       = "Microsoft.ServiceBus/namespaces/topics",
                    ["apiVersion"] = "2015-08-01",
                    ["location"]   = location,
                    ["properties"] = new JObject
                    {
                        ["defaultMessageTimeToLive"]   = "14.00:00:00",
                        ["maxSizeInMegabytes"]         = "1024",
                        ["requiresDuplicateDetection"] = false,
                        ["enablePartitioning"]         = true,
                    },
                    ["dependsOn"] = new JArray
                    {
                        $"[resourceId('Microsoft.ServiceBus/namespaces', '{serviceBus.Name}')]"
                    }
                });
            }
        }
예제 #21
0
        protected virtual IEnumerable <string> DependsOn(IHaveInfrastructure <TAppService> elementWithInfrastructure, string location)
        {
            var appServicePlan = AppServicePlan(elementWithInfrastructure, location);

            if (appServicePlan != null)
            {
                return(Enumerable.Repeat(
                           $"[concat(\'Microsoft.Web/serverfarms/\', \'{elementWithInfrastructure.Infrastructure.Name}\')]",
                           1));
            }

            return(Enumerable.Empty <string>());
        }
        protected override Task Configure(IHaveInfrastructure <KeyVault> elementWithInfrastructure, AzureConfigurationValueResolverContext context)
        {
            foreach (var secret in elementWithInfrastructure.Infrastructure.Secrets)
            {
                object value;
                if (context.Values.TryGetValue(secret.Value, out value))
                {
                    // TODO: add secret to key vault using the context.Client
                }
            }

            return(Task.FromResult(1));
        }
 protected virtual JArray GatewayIPConfigurations(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
 {
     return(new JArray(new JObject
     {
         ["name"] = "appGatewayIpConfig",
         ["properties"] = new JObject
         {
             ["subnet"] = new JObject
             {
                 ["id"] = elementWithInfrastructure.Infrastructure.DefaultSubnet.ResourceIdReference
             }
         }
     }));
 }
 protected virtual JArray BackendPools(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
 {
     return(new JArray(elementWithInfrastructure.Infrastructure.BackendPools.Select(p => new JObject
     {
         ["name"] = p.Name,
         ["properties"] = new JObject
         {
             ["BackendAddresses"] = new JArray(p.Addresses.Select(a => new JObject
             {
                 [a.Type] = a.Address
             }))
         }
     })));
 }
        bool IConfigurable.IsConfigurationDependentOn(IHaveInfrastructure other)
        {
            var resource = other.Infrastructure as IHaveResourceId;

            if (resource == null)
            {
                return(false);
            }

            return(Settings.Concat(ConnectionStrings)
                   .Select(s => s.Value)
                   .OfType <IDependentConfigurationValue>()
                   .Any(v => v.DependsOn == resource));
        }
예제 #26
0
        protected override void Render(
            AzureDeploymentTemplate template,
            IHaveInfrastructure <WebAppService> elementWithInfrastructure,
            IAzureInfrastructureEnvironment environment,
            string resourceGroup,
            string location)
        {
            var name = elementWithInfrastructure.Infrastructure.Name;

            template.Resources.Add(new JObject
            {
                ["type"]       = "Microsoft.Web/serverfarms",
                ["name"]       = name,
                ["apiVersion"] = ApiVersion,
                ["location"]   = ToLocationName(location),
                ["sku"]        = new JObject
                {
                    ["Tier"] = "Free",
                    ["Name"] = "F1"
                },
                ["properties"] = new JObject
                {
                    ["name"]               = name,
                    ["workerSizeId"]       = "0",
                    ["numberOfWorkers"]    = "1",
                    ["reserved"]           = false,
                    ["hostingEnvironment"] = ""
                }
            });

            var appService = new JObject
            {
                ["type"]       = "Microsoft.Web/sites",
                ["name"]       = name,
                ["apiVersion"] = ApiVersion,
                ["location"]   = location,
                ["tags"]       = new JObject
                {
                    [
                        $"[concat(\'hidden-related:\', resourceGroup().id, \'/providers/Microsoft.Web/serverfarms/\', \'{name}\')]"
                    ] = "empty"
                },
                ["properties"] = Properties(elementWithInfrastructure),
            };

            AddSubResources(elementWithInfrastructure, appService);
            AddDependsOn(elementWithInfrastructure, appService);
            template.Resources.Add(appService);
        }
 protected virtual JArray FrontendIPConfigurations(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
 {
     return(new JArray(
                elementWithInfrastructure.Infrastructure.FrontendIps.Select(i => new JObject
     {
         ["name"] = i.Name,
         ["properties"] = new JObject
         {
             ["PublicIPAddress"] = new JObject
             {
                 ["id"] = i.PublicIpAddress.ResourceIdReference
             }
         }
     }
                                                                            )));
 }
        protected override void Render(AzureDeploymentTemplate template, IHaveInfrastructure <StorageAccount> elementWithInfrastructure,
                                       IAzureInfrastructureEnvironment environment, string resourceGroup, string location)
        {
            var storageAccount = Template(
                "Microsoft.Storage/storageAccounts",
                elementWithInfrastructure.Infrastructure.Name,
                location,
                "2017-06-01"
                );

            const string accountType = "Standard_LRS";

            storageAccount["sku"] = new JObject
            {
                ["name"] = accountType
            };

            storageAccount["kind"] = elementWithInfrastructure.Infrastructure.Kind.ToString();

            var isBlobStorage = elementWithInfrastructure.Infrastructure.Kind == StorageAccountKind.BlobStorage;

            var properties = new JObject
            {
                ["supportsHttpsTrafficOnly"] = false,
                ["encryption"] = new JObject
                {
                    ["keySource"] = "Microsoft.Storage",
                    ["services"]  = new JObject
                    {
                        ["blob"] = new JObject {
                            ["enabled"] = true
                        },
                        ["file"] = new JObject {
                            ["enabled"] = !isBlobStorage
                        }
                    }
                }
            };

            if (isBlobStorage)
            {
                properties["accessTier"] = "Hot";
            }
            storageAccount["properties"] = properties;

            template.Resources.Add(storageAccount);
        }
 protected virtual JArray UrlPathMaps(IHaveInfrastructure <ApplicationGateway> elementWithInfrastructure, IAzureInfrastructureEnvironment environment)
 {
     return(new JArray(elementWithInfrastructure.Infrastructure.UrlPathMaps.Select(u => new JObject
     {
         ["name"] = u.Name,
         ["properties"] = new JObject
         {
             ["defaultBackendAddressPool"] = new JObject
             {
                 ["id"] = $"[concat({elementWithInfrastructure.Infrastructure.ResourceIdReferenceContent}, '/backendAddressPools/{u.DefaultBackendPool.Name}')]"
             },
             ["defaultBackendHttpSettings"] = new JObject
             {
                 ["id"] = $"[concat({elementWithInfrastructure.Infrastructure.ResourceIdReferenceContent}, '/backendHttpSettingsCollection/{u.DefaultBackendHttpSetting.Name}')]"
             },
             ["pathRules"] = new JArray(u.Rules.Select(rule => UrlPathMapPathRule(rule, elementWithInfrastructure)))
         }
     })));
 }
예제 #30
0
        protected override void Render(AzureDeploymentTemplate template,
                                       IHaveInfrastructure <KeyVault> elementWithInfrastructure, IAzureInfrastructureEnvironment environment,
                                       string resourceGroup, string location)
        {
            var keyVault = elementWithInfrastructure.Infrastructure;

            template.Resources.Add(PostProcess(new JObject
            {
                ["type"]       = "Microsoft.KeyVault/vaults",
                ["name"]       = keyVault.Name,
                ["apiVersion"] = "2015-06-01",
                ["location"]   = location,
                ["properties"] = new JObject
                {
                    ["enabledForDeployment"]         = false,
                    ["enabledForTemplateDeployment"] = false,
                    ["enabledForDiskEncryption"]     = false,
                    ["accessPolicies"] = AccessPolicies(environment, keyVault),
                    ["tenantId"]       = environment.Tenant,
                    ["sku"]            = new JObject
                    {
                        ["name"]   = "Standard",
                        ["family"] = "A"
                    }
                }
            }));

            foreach (var keyVaultSecret in keyVault.Secrets)
            {
                template.Resources.Add(PostProcess(new JObject
                {
                    ["type"]       = "Microsoft.KeyVault/vaults/secrets",
                    ["name"]       = keyVault.Name + "/" + keyVaultSecret.Name,
                    ["apiVersion"] = "2015-06-01",
                    ["properties"] = new JObject
                    {
                        ["contentType"] = "text/plain",
                        ["value"]       = keyVaultSecret.Value.Value.ToString(),
                        ["dependsOn"]   = GetDependsOn(keyVaultSecret, keyVault)
                    }
                }));
            }
        }