-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from codatio/create-resource-builder
Add Support for nested resource groups
- Loading branch information
Showing
20 changed files
with
818 additions
and
248 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#r "../../src/Farmer/bin/Debug/net5.0/Farmer.dll" | ||
|
||
open Farmer | ||
open Farmer.Builders | ||
|
||
let myStorage = storageAccount { | ||
name "myfarmerstorage" | ||
} | ||
let myVm = vm { | ||
name "farmer-test-vm" | ||
username "codat" | ||
} | ||
let nested = resourceGroup { | ||
name "farmer-test-inner" | ||
add_resource myStorage | ||
add_resource myVm | ||
output "foo" "bax" | ||
} | ||
let template = arm { | ||
location Location.UKSouth | ||
add_resource nested | ||
} | ||
|
||
template |> Writer.quickWrite "template" | ||
template |> Deploy.execute "farmer-test-rg" [("password-for-farmer-test-vm","Codat121!")] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
{ | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"outputs": { | ||
"farmer-test-inner.foo": { | ||
"type": "string", | ||
"value": "[reference('farmer-test-inner').outputs['foo'].value]" | ||
} | ||
}, | ||
"parameters": { | ||
"password-for-farmer-test-vm": { | ||
"type": "securestring" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"apiVersion": "2020-10-01", | ||
"name": "farmer-test-inner", | ||
"properties": { | ||
"expressionEvaluationOptions": { | ||
"scope": "Inner" | ||
}, | ||
"mode": "Incremental", | ||
"parameters": { | ||
"password-for-farmer-test-vm": { | ||
"value": "[parameters('password-for-farmer-test-vm')]" | ||
} | ||
}, | ||
"template": { | ||
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"outputs": { | ||
"foo": { | ||
"type": "string", | ||
"value": "bax" | ||
} | ||
}, | ||
"parameters": { | ||
"password-for-farmer-test-vm": { | ||
"type": "securestring" | ||
} | ||
}, | ||
"resources": [ | ||
{ | ||
"apiVersion": "2019-06-01", | ||
"dependsOn": [], | ||
"kind": "StorageV2", | ||
"location": "westeurope", | ||
"name": "myfarmerstorage", | ||
"properties": {}, | ||
"sku": { | ||
"name": "Standard_LRS" | ||
}, | ||
"tags": {}, | ||
"type": "Microsoft.Storage/storageAccounts" | ||
}, | ||
{ | ||
"apiVersion": "2018-10-01", | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.Network/networkInterfaces', 'farmer-test-vm-nic')]" | ||
], | ||
"location": "westeurope", | ||
"name": "farmer-test-vm", | ||
"properties": { | ||
"diagnosticsProfile": { | ||
"bootDiagnostics": { | ||
"enabled": false | ||
} | ||
}, | ||
"hardwareProfile": { | ||
"vmSize": "Basic_A0" | ||
}, | ||
"networkProfile": { | ||
"networkInterfaces": [ | ||
{ | ||
"id": "[resourceId('Microsoft.Network/networkInterfaces', 'farmer-test-vm-nic')]" | ||
} | ||
] | ||
}, | ||
"osProfile": { | ||
"adminPassword": "[parameters('password-for-farmer-test-vm')]", | ||
"adminUsername": "codat", | ||
"computerName": "farmer-test-vm" | ||
}, | ||
"storageProfile": { | ||
"dataDisks": [ | ||
{ | ||
"createOption": "Empty", | ||
"diskSizeGB": 1024, | ||
"lun": 0, | ||
"managedDisk": { | ||
"storageAccountType": "Standard_LRS" | ||
}, | ||
"name": "farmer-test-vm-datadisk-0" | ||
} | ||
], | ||
"imageReference": { | ||
"offer": "WindowsServer", | ||
"publisher": "MicrosoftWindowsServer", | ||
"sku": "2012-Datacenter", | ||
"version": "latest" | ||
}, | ||
"osDisk": { | ||
"createOption": "FromImage", | ||
"diskSizeGB": 128, | ||
"managedDisk": { | ||
"storageAccountType": "Standard_LRS" | ||
}, | ||
"name": "farmer-test-vm-osdisk" | ||
} | ||
} | ||
}, | ||
"tags": {}, | ||
"type": "Microsoft.Compute/virtualMachines" | ||
}, | ||
{ | ||
"apiVersion": "2018-11-01", | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.Network/virtualNetworks', 'farmer-test-vm-vnet')]", | ||
"[resourceId('Microsoft.Network/publicIPAddresses', 'farmer-test-vm-ip')]" | ||
], | ||
"location": "westeurope", | ||
"name": "farmer-test-vm-nic", | ||
"properties": { | ||
"ipConfigurations": [ | ||
{ | ||
"name": "ipconfig1", | ||
"properties": { | ||
"privateIPAllocationMethod": "Dynamic", | ||
"publicIPAddress": { | ||
"id": "[resourceId('Microsoft.Network/publicIPAddresses', 'farmer-test-vm-ip')]" | ||
}, | ||
"subnet": { | ||
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'farmer-test-vm-vnet', 'farmer-test-vm-subnet')]" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"tags": {}, | ||
"type": "Microsoft.Network/networkInterfaces" | ||
}, | ||
{ | ||
"apiVersion": "2018-11-01", | ||
"location": "westeurope", | ||
"name": "farmer-test-vm-vnet", | ||
"properties": { | ||
"addressSpace": { | ||
"addressPrefixes": [ | ||
"10.0.0.0/16" | ||
] | ||
}, | ||
"subnets": [ | ||
{ | ||
"name": "farmer-test-vm-subnet", | ||
"properties": { | ||
"addressPrefix": "10.0.0.0/24", | ||
"delegations": [] | ||
} | ||
} | ||
] | ||
}, | ||
"tags": {}, | ||
"type": "Microsoft.Network/virtualNetworks" | ||
}, | ||
{ | ||
"apiVersion": "2018-11-01", | ||
"location": "westeurope", | ||
"name": "farmer-test-vm-ip", | ||
"properties": { | ||
"publicIPAllocationMethod": "Dynamic" | ||
}, | ||
"sku": { | ||
"name": "Basic" | ||
}, | ||
"tags": {}, | ||
"type": "Microsoft.Network/publicIPAddresses" | ||
} | ||
] | ||
} | ||
}, | ||
"resourceGroup": "farmer-test-inner", | ||
"tags": {}, | ||
"type": "Microsoft.Resources/deployments" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[<AutoOpen>] | ||
module Farmer.Aliases | ||
|
||
let arm = Farmer.Builders.ResourceGroup.resourceGroup |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[<AutoOpen>] | ||
module Farmer.Arm.ResourceGroup | ||
|
||
open Farmer | ||
open Farmer.Writer | ||
|
||
let resourceGroupDeployment = ResourceType ("Microsoft.Resources/deployments","2020-10-01") | ||
|
||
type DeploymentMode = Incremental|Complete | ||
|
||
/// Represents all configuration information to generate an ARM template. | ||
type ResourceGroupDeployment = | ||
{ Name: ResourceName | ||
Dependencies: ResourceId Set | ||
Outputs : Map<string, string> | ||
Location : Location | ||
Resources : IArmResource list | ||
Mode: DeploymentMode | ||
Tags: Map<string,string> } | ||
member this.ResourceId = resourceGroupDeployment.resourceId this.Name | ||
member this.Parameters = | ||
[ for resource in this.Resources do | ||
match resource with | ||
| :? IParameters as p -> yield! p.SecureParameters | ||
| _ -> () | ||
] |> List.distinct | ||
member this.Template = | ||
{ Parameters = this.Parameters | ||
Outputs = this.Outputs |> Map.toList | ||
Resources = this.Resources } | ||
interface IParameters with | ||
member this.SecureParameters = this.Parameters | ||
interface IArmResource with | ||
member this.ResourceId = resourceGroupDeployment.resourceId this.Name | ||
member this.JsonModel = | ||
{| resourceGroupDeployment.Create(this.Name, this.Location, dependsOn = this.Dependencies, tags = this.Tags ) with | ||
location = null // location is not supported for nested resource groups | ||
resourceGroup = this.Name.Value | ||
properties = | ||
{| template = TemplateGeneration.processTemplate this.Template | ||
parameters = | ||
this.Parameters | ||
|> Seq.map(fun (SecureParameter s) -> s, {| ``value`` = $"[parameters('%s{s}')]" |}) | ||
|> Map.ofSeq | ||
mode = | ||
match this.Mode with | ||
| Incremental -> "Incremental" | ||
| Complete -> "Complete" | ||
expressionEvaluationOptions = {| scope = "Inner" |} | ||
|} | ||
|} :> _ |
Oops, something went wrong.