راهکار راهاندازی Infrastructure as a code
نویسنده: یاسر مرادی
تاریخ: ۱۳۹۹/۰۵/۰۵ ۲۱:۲۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
var sqlDatabasePassword = pulumiConfig.RequireSecret("sql-server-nikola-dev-password");
var sqlDatabaseUserId = pulumiConfig.RequireSecret("sql-server-nikola-dev-user-id");
var resourceGroup = new ResourceGroup("rg-dds-nikola-dev", new ResourceGroupArgs
{
Name = "rg-dds-nikola-dev",
Location = "WestUS"
});
var storageAccount = new Account("storagenikoladev", new AccountArgs
{
Name = "storagenikoladev",
ResourceGroupName = resourceGroup.Name,
Location = resourceGroup.Location,
AccountKind = "StorageV2",
AccountReplicationType = "LRS",
AccountTier = "Standard",
});
var container = new Container("container-nikola-dev", new ContainerArgs
{
Name = "container-nikola-dev",
ContainerAccessType = "blob",
StorageAccountName = storageAccount.Name
});
var blobStorage = new Blob("blob-nikola-dev", new BlobArgs
{
Name = "blob-nikola-dev",
StorageAccountName = storageAccount.Name,
StorageContainerName = container.Name,
Type = "Block"
});
var appInsights = new Insights("app-insights-nikola-dev", new InsightsArgs
{
Name = "app-insights-nikola-dev",
ResourceGroupName = resourceGroup.Name,
Location = resourceGroup.Location,
ApplicationType = "web" // also general for mobile apps
});
var sqlServer = new SqlServer("sql-server-nikola-dev", new SqlServerArgs
{
Name = "sql-server-nikola-dev",
ResourceGroupName = resourceGroup.Name,
Location = resourceGroup.Location,
AdministratorLogin = sqlDatabaseUserId,
AdministratorLoginPassword = sqlDatabasePassword,
Version = "12.0"
});
var sqlDatabase = new Database("sql-database-nikola-dev", new DatabaseArgs
{
Name = "sql-database-nikola-dev",
ResourceGroupName = resourceGroup.Name,
Location = resourceGroup.Location,
ServerName = sqlServer.Name,
RequestedServiceObjectiveName = "Basic"
});
var appServicePlan = new Plan("app-plan-nikola-dev", new PlanArgs
{
Name = "app-plan-nikola-dev",
ResourceGroupName = resourceGroup.Name,
Location = resourceGroup.Location,
Sku = new PlanSkuArgs
{
Tier = "Shared",
Size = "D1"
}
});
var appService = new AppService("app-service-nikola-dev", new AppServiceArgs
{
Name = "app-service-nikola-dev",
ResourceGroupName = resourceGroup.Name,
Location = resourceGroup.Location,
AppServicePlanId = appServicePlan.Id,
SiteConfig = new AppServiceSiteConfigArgs
{
Use32BitWorkerProcess = true, // X64 not allowed in shared plan!
AlwaysOn = false, // not allowed in shared plan!
Http2Enabled = true
},
AppSettings =
{
{ "ApplicationInsights:InstrumentationKey", appInsights.InstrumentationKey },
{ "APPINSIGHTS_INSTRUMENTATIONKEY", appInsights.InstrumentationKey }
},
ConnectionStrings = new InputList<AppServiceConnectionStringArgs>()
{
new AppServiceConnectionStringArgs
{
Name = "AppDbConnectionString",
Type = "SQLAzure",
Value = Output.Tuple(sqlServer.Name, sqlDatabase.Name, sqlDatabaseUserId, sqlDatabasePassword).Apply(t =>
{
(string _sqlServer, string _sqlDatabase, string _sqlDatabaseUserId, string _sqlDatabasePassword) = t;
return $"Data Source=tcp:{_sqlServer}.database.windows.net;Initial Catalog={_sqlDatabase};User ID={_sqlDatabaseUserId};Password={_sqlDatabasePassword};Max Pool Size=1024;Persist Security Info=true;Application Name=Nikola";
})
},
new AppServiceConnectionStringArgs
{
Name = "AzureBlobStorageConnectionString",
Type = "Custom",
Value = Output.Tuple(storageAccount.PrimaryAccessKey, storageAccount.Name).Apply(t =>
{
(string _primaryAccess, string _storageAccountName) = t;
return $"DefaultEndpointsProtocol=https;AccountName={_storageAccountName};AccountKey={_primaryAccess};EndpointSuffix=core.windows.net";
})
}
}
});
appService.OutboundIpAddresses.Apply(ips =>
{
foreach (string ip in ips.Split(','))
{
new FirewallRule($"app-srv-{ip}", new FirewallRuleArgs
{
Name = $"app-srv-{ip}",
EndIpAddress = ip,
ResourceGroupName = resourceGroup.Name,
ServerName = sqlServer.Name,
StartIpAddress = ip
});
}
return (string?)null;
});