Created
October 5, 2022 13:33
-
-
Save hibri/223156e93a252f64b30a070bbb30557b to your computer and use it in GitHub Desktop.
extract methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyStack : TerraformStack | |
{ | |
public MyStack(Construct scope, string id) : base(scope, id) | |
{ | |
var azurermProviderConfig = new AzurermProviderConfig() { Features = new AzurermProviderFeatures() }; | |
var azurermProvider = new AzurermProvider(this, "AzureRm", azurermProviderConfig); | |
var rg = BuildResourceGroup(); | |
var functionStorageAccount = BuildFunctionStorageAccount(rg); | |
var appServicePlan = BuildAppServicePlan(rg); | |
BuildFunction(rg, appServicePlan, functionStorageAccount); | |
} | |
private void BuildFunction(ResourceGroup rg, ServicePlan appServicePlan, StorageAccount functionStorageAccount) | |
{ | |
var functionAppConfig = new LinuxFunctionAppConfig | |
{ | |
Name = "hibrifuncapp", | |
ResourceGroupName = rg.Name, | |
Location = rg.Location, | |
ServicePlanId = appServicePlan.Id, | |
AppSettings = new Dictionary<string, string>(), | |
StorageAccountName = functionStorageAccount.Name, | |
StorageAccountAccessKey = functionStorageAccount.SecondaryAccessKey, | |
SiteConfig = new LinuxFunctionAppSiteConfig | |
{ | |
ApplicationStack = new LinuxFunctionAppSiteConfigApplicationStack | |
{ | |
DotnetVersion = "6.0" | |
} | |
} | |
}; | |
var functionApp = new LinuxFunctionApp(this, "functionapp", functionAppConfig); | |
} | |
private ServicePlan BuildAppServicePlan(ResourceGroup rg) | |
{ | |
var appServicePlanConfig = new ServicePlanConfig | |
{ | |
Name = "test-plan", | |
ResourceGroupName = rg.Name, | |
Location = rg.Location, | |
OsType = "Linux", | |
SkuName = "B1" | |
}; | |
var appServicePlan = new ServicePlan(this, "test-plan", appServicePlanConfig); | |
return appServicePlan; | |
} | |
private StorageAccount BuildFunctionStorageAccount(ResourceGroup rg) | |
{ | |
var storageAccountConfig = new StorageAccountConfig | |
{ | |
Name = "hibrifuncstr", | |
ResourceGroupName = rg.Name, | |
Location = rg.Location, | |
AccountReplicationType = "LRS", | |
AccountTier = "Standard" | |
}; | |
var functionStorageAccount = new StorageAccount(this, "hibrifuncstr", storageAccountConfig); | |
return functionStorageAccount; | |
} | |
private ResourceGroup BuildResourceGroup() | |
{ | |
ResourceGroup rg = new ResourceGroup(this, "hibri-test", new ResourceGroupConfig | |
{ | |
Location = "uksouth", | |
Name = "hibri-test" | |
}); | |
return rg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment