Skip to content

Commit

Permalink
resource lock added in resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol Nagpal committed Feb 15, 2023
1 parent c4c69b7 commit 94f38d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _example/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ module "resource_group" {

name = "example"
location = "North Europe"

#resource lock
resource_lock_enabled = true
lock_level = "CanNotDelete"
}
8 changes: 8 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ resource "azurerm_resource_group" "default" {
delete = var.delete
}
}

resource "azurerm_management_lock" "resource-group-level" {
count = var.enabled && var.resource_lock_enabled ? 1 : 0
name = format("%s-rg-lock", var.lock_level)
scope = azurerm_resource_group.default.*.id[0]
lock_level = var.lock_level
notes = "This Resource Group is locked by terrafrom"
}
11 changes: 11 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,14 @@ variable "delete" {
default = "90m"
description = "Used when deleting the Resource Group."
}

variable "resource_lock_enabled" {
type = bool
default = false
description = "enable or disable lock resource"
}

variable "lock_level" {
type = string
default = "CanNotDelete"
}

0 comments on commit 94f38d9

Please sign in to comment.