Skip to content

Commit 2fb24f9

Browse files
Suggested spec change to resource locks (lock) interface for Terraform (#489)
Co-authored-by: Matt White <[email protected]>
1 parent 21b09bb commit 2fb24f9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
variable "lock" {
22
type = object({
3+
kind = string
34
name = optional(string, null)
4-
kind = optional(string, "None")
55
})
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+
914
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\"`."
1217
}
1318
}
1419

1520
# Example resource implementation
1621
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+
2024
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."
2128
}

0 commit comments

Comments
 (0)