-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for policy definition resource
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
resource "azurerm_policy_definition" "policy" { | ||
name = "${var.policy_definition_name}" | ||
policy_type = "${var.policy_type}" | ||
mode = "${var.mode}" | ||
display_name = "${var.display_name}" | ||
policy_rule =<<POLICY_RULE | ||
{ | ||
"if": { | ||
"not": { | ||
"field": "location", | ||
"in": "[parameters('allowedLocations')]" | ||
} | ||
}, | ||
"then": { | ||
"effect": "audit" | ||
} | ||
} | ||
POLICY_RULE | ||
|
||
parameters =<<PARAMETERS | ||
{ | ||
"allowedLocations": { | ||
"type": "Array", | ||
"metadata": { | ||
"description": "The list of allowed locations for resources.", | ||
"displayName": "Allowed locations", | ||
"strongType": "location" | ||
} | ||
} | ||
} | ||
PARAMETERS | ||
|
||
} |
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,3 @@ | ||
output "Policy Defintion" { | ||
value = "${azurerm_policy_definition.policy.name}" | ||
} |
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,19 @@ | ||
variable "policy_definition_name" { | ||
description = "Policy definition name must only contain lowercase letters, digits or dashes, cannot use dash as the first two or last one characters, cannot contain consecutive dashes, and is limited between 2 and 60 characters in length." | ||
default = "demoPolicy" | ||
} | ||
|
||
variable "policy_type" { | ||
description = "Valid values are 'BuiltIn', 'Custom' and 'NotSpecified'." | ||
default = "Custom" | ||
} | ||
|
||
variable "mode" { | ||
description = "Valid values are 'All', 'Indexed' and 'NotSpecified'." | ||
default = "All" | ||
} | ||
|
||
variable "display_name" { | ||
description = "Policy display name must only contain lowercase letters, digits or dashes, cannot use dash as the first two or last one characters, cannot contain consecutive dashes, and is limited between 2 and 60 characters in length." | ||
default = "demoPolicy" | ||
} |
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,89 @@ | ||
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azure_policy_definition" | ||
sidebar_current: "docs-azurerm-resource-policy-definition" | ||
description: |- | ||
Creates a policy for all of the resource groups under the subscription. | ||
--- | ||
|
||
# azurerm_policy_definition | ||
|
||
Creates a policy for all of the resource groups under the subscription. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "azurerm_policy_definition" "policy" { | ||
name = "accTestPolicy" | ||
policy_type = "BuiltIn" | ||
mode = "Indexed" | ||
display_name = "acceptance test policy definition" | ||
policy_rule =<<POLICY_RULE | ||
{ | ||
"if": { | ||
"not": { | ||
"field": "location", | ||
"in": "[parameters('allowedLocations')]" | ||
} | ||
}, | ||
"then": { | ||
"effect": "audit" | ||
} | ||
} | ||
POLICY_RULE | ||
parameters =<<PARAMETERS | ||
{ | ||
"allowedLocations": { | ||
"type": "Array", | ||
"metadata": { | ||
"description": "The list of allowed locations for resources.", | ||
"displayName": "Allowed locations", | ||
"strongType": "location" | ||
} | ||
} | ||
} | ||
PARAMETERS | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the policy definition. Changing this forces a | ||
new resource to be created. | ||
|
||
* `policy_type` - (Required) The policy type. The value can be BuiltIn, Custom | ||
or NotSpecified. Changing this forces a new resource to be created. | ||
|
||
* `mode` - (Required) The policy mode that allows you to specify which resource | ||
types will be evaluated. The value can be All, Indexed or | ||
NotSpecified. Changing this resource forces a new resource to be | ||
created. | ||
|
||
* `display_name` - (Required) The display name of the policy definition. | ||
|
||
* `description` - (Optional) The description of the policy definition. | ||
|
||
* `policy_rule` - (Optional) The policy rule for the policy definition. This | ||
is a json object representing the rule that contains an if and | ||
a then block. | ||
|
||
* `parameters` - (Optional) Parameters for the policy definition. This field | ||
is a json object that allows you to parameterize your policy definition. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The policy defenition id. | ||
|
||
## Import | ||
|
||
Policy Definitions can be imported using the `policy name`, e.g. | ||
|
||
```shell | ||
terraform import azurerm_policy_definition.testPolict /subscriptions/<SUBSCRIPTION_ID>/providers/Microsoft.Authorization/policyDefinitions/<POLICY_NAME> | ||
``` |