-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggested spec change to resource locks (
lock
) interface for Terraf…
…orm (#489) Co-authored-by: Matt White <[email protected]>
- Loading branch information
1 parent
21b09bb
commit 2fb24f9
Showing
1 changed file
with
16 additions
and
9 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 |
---|---|---|
@@ -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." | ||
} |