forked from Azure/AzureStack-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureStack.Policy.psm1
85 lines (76 loc) · 3.09 KB
/
AzureStack.Policy.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE.txt in the project root for license information.
#requires -Version 4.0
#requires -Modules AzureRM.Profile
<#
.SYNOPSIS
Produces Azure Resource Manager Policy document to apply to restrict Azure subscriptions to Azure Stack compatible functionality
#>
function Get-AzureStackRmPolicy
{
$defaults = [System.IO.Path]::GetDirectoryName($PSCommandPath)
$providerMetadata = ConvertFrom-Json (Get-Content -Path ($defaults + "\AzureStack.Provider.Metadata.json") -Raw)
$vmSkus = @() + (ConvertFrom-Json (Get-Content -Path ($defaults + "\AzureStack.vmSkus.json") -Raw))
$storageSkus = @() + (ConvertFrom-Json (Get-Content -Path ($defaults + "\AzureStack.storageSkus.json") -Raw))
$allowResources = @()
foreach ($p in $providerMetadata.value)
{
foreach ($r in $p.resourceTypes)
{
$allowResources += @{ field = "type"; equals = $p.namespace + "/" + $r.ResourceType}
$allowResources += @{ field = "type"; like = $p.namespace + "/" + $r.ResourceType + "/*" }
}
}
$vmSkuField = "Microsoft.Compute/virtualMachines/sku.name"
$storageSkuField = "Microsoft.Storage/storageAccounts/sku.name"
$policy = @{
if = @{
not = @{
allOf = @(
@{
anyOf = $allowResources
},
@{
not = @{
anyOf = @(
@{
allOf = @(
@{
field = $vmSkuField;
exists = "true"
},
@{
not = @{
field = $vmSkuField;
in = $vmSkus
}
}
)
},
@{
allOf = @(
@{
field = $storageSkuField;
exists = "true"
},
@{
not = @{
field = $storageSkuField;
in = $storageSkus
}
}
)
}
)
}
}
)
}
};
then = @{
effect = "deny"
}
}
ConvertTo-Json $policy -Depth 100
}
Export-ModuleMember Get-AzureStackRmPolicy