Skip to content

Commit

Permalink
Suggested spec change to resource locks (lock) interface for Terraf…
Browse files Browse the repository at this point in the history
…orm (#489)

Co-authored-by: Matt White <[email protected]>
  • Loading branch information
MariusStorhaug and matt-FFFFFF authored Jan 21, 2024
1 parent 21b09bb commit 2fb24f9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions docs/static/includes/interfaces/int.locks.schema.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
variable "lock" {
type = object({
kind = string
name = optional(string, null)
kind = optional(string, "None")
})
description = "The lock level to apply to the Key Vault. Possible values are `None`, `CanNotDelete`, and `ReadOnly`."
default = {}
nullable = false
default = null
description = <<DESCRIPTION
Controls the Resource Lock configuration for this resource. The following properties can be specified:
- `kind` - (Required) The type of lock. Possible values are `\"CanNotDelete\"` and `\"ReadOnly\"`.
- `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.
DESCRIPTION

validation {
condition = contains(["CanNotDelete", "ReadOnly", "None"], var.lock.kind)
error_message = "The lock level must be one of: 'None', 'CanNotDelete', or 'ReadOnly'."
condition = var.lock != null ? contains(["CanNotDelete", "ReadOnly"], var.lock.kind) : true
error_message = "Lock kind must be either `\"CanNotDelete\"` or `\"ReadOnly\"`."
}
}

# Example resource implementation
resource "azurerm_management_lock" "this" {
count = var.lock.kind != "None" ? 1 : 0
name = coalesce(var.lock.name, "lock-${var.name}")
scope = azurerm_MY_RESOURCE.this.id
count = var.lock != null ? 1 : 0

lock_level = var.lock.kind
name = coalesce(var.lock.name, "lock-${var.lock.kind}")
scope = azurerm_MY_RESOURCE.this.id
notes = var.lock.kind == "CanNotDelete" ? "Cannot delete the resource or its child resources." : "Cannot delete or modify the resource or its child resources."
}

0 comments on commit 2fb24f9

Please sign in to comment.