|
1 | 1 | variable "lock" {
|
2 | 2 | type = object({
|
| 3 | + kind = string |
3 | 4 | name = optional(string, null)
|
4 |
| - kind = optional(string, "None") |
5 | 5 | })
|
6 |
| - description = "The lock level to apply to the Key Vault. Possible values are `None`, `CanNotDelete`, and `ReadOnly`." |
7 |
| - default = {} |
8 |
| - nullable = false |
| 6 | + default = null |
| 7 | + description = <<DESCRIPTION |
| 8 | +Controls the Resource Lock configuration for this resource. The following properties can be specified: |
| 9 | +
|
| 10 | +- `kind` - (Required) The type of lock. Possible values are `\"CanNotDelete\"` and `\"ReadOnly\"`. |
| 11 | +- `name` - (Optional) The name of the lock. If not specified, a name will be generated based on the `kind` value. Changing this forces the creation of a new resource. |
| 12 | +DESCRIPTION |
| 13 | + |
9 | 14 | validation {
|
10 |
| - condition = contains(["CanNotDelete", "ReadOnly", "None"], var.lock.kind) |
11 |
| - error_message = "The lock level must be one of: 'None', 'CanNotDelete', or 'ReadOnly'." |
| 15 | + condition = var.lock != null ? contains(["CanNotDelete", "ReadOnly"], var.lock.kind) : true |
| 16 | + error_message = "Lock kind must be either `\"CanNotDelete\"` or `\"ReadOnly\"`." |
12 | 17 | }
|
13 | 18 | }
|
14 | 19 |
|
15 | 20 | # Example resource implementation
|
16 | 21 | resource "azurerm_management_lock" "this" {
|
17 |
| - count = var.lock.kind != "None" ? 1 : 0 |
18 |
| - name = coalesce(var.lock.name, "lock-${var.name}") |
19 |
| - scope = azurerm_MY_RESOURCE.this.id |
| 22 | + count = var.lock != null ? 1 : 0 |
| 23 | + |
20 | 24 | lock_level = var.lock.kind
|
| 25 | + name = coalesce(var.lock.name, "lock-${var.lock.kind}") |
| 26 | + scope = azurerm_MY_RESOURCE.this.id |
| 27 | + notes = var.lock.kind == "CanNotDelete" ? "Cannot delete the resource or its child resources." : "Cannot delete or modify the resource or its child resources." |
21 | 28 | }
|
0 commit comments