Skip to content

Commit

Permalink
Validate policy mode value
Browse files Browse the repository at this point in the history
Policy creation succeeds even if the policy mode in the request is
not capitalized, however, when fetching the policy mode value from
Azure, the correct capitalized version is returned, which causes
the Terraform state and configuration to be different.

Ideally, there should be an enum with a set of allowed values, but
this is not the case in the latest version of the Azure Rest API specs.
However, the supported mode values are returned in the error
response when an invalid mode is requested.

Fixes #8748
  • Loading branch information
beandrad committed Oct 8, 2020
1 parent f6568c9 commit da7bcdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
14 changes: 14 additions & 0 deletions azurerm/internal/services/policy/policy_definition_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ func resourceArmPolicyDefinition() *schema.Resource {
"mode": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(
[]string{
"All",
"Indexed",
"Microsoft.ContainerService.Data",
"Microsoft.CustomerLockbox.Data",
"Microsoft.DataCatalog.Data",
"Microsoft.KeyVault.Data",
"Microsoft.Kubernetes.Data",
"Microsoft.MachineLearningServices.Data",
"Microsoft.Network.Data",
"Microsoft.Synapse.Data",
}, false,
),
},

"management_group_id": {
Expand Down
3 changes: 1 addition & 2 deletions website/docs/r/policy_definition.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ The following arguments are supported:
* `policy_type` - (Required) The policy type. Possible values are `BuiltIn`, `Custom` and `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".
types will be evaluated. Possible values are `All`, `Indexed`, `Microsoft.ContainerService.Data`, `Microsoft.CustomerLockbox.Data`, `Microsoft.DataCatalog.Data`, `Microsoft.KeyVault.Data`, `Microsoft.Kubernetes.Data`, `Microsoft.MachineLearningServices.Data`, `Microsoft.Network.Data` and `Microsoft.Synapse.Data`.

* `display_name` - (Required) The display name of the policy definition.

Expand Down

0 comments on commit da7bcdb

Please sign in to comment.