Skip to content

Commit 1931a22

Browse files
committed
Updating Identity block to support all identity types
1 parent 5f3a204 commit 1931a22

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,41 @@ module "storage" {
186186
}
187187
```
188188

189+
## `Identity` - Configure managed identities to access Azure Storage
190+
191+
Managed identities for Azure resources provides Azure services with an automatically managed identity in Azure Active Directory. You can use this identity to authenticate to any service that supports Azure AD authentication, without having credentials in your code.
192+
193+
There are two types of managed identities:
194+
195+
* **System-assigned**: When enabled a system-assigned managed identity an identity is created in Azure AD that is tied to the lifecycle of that service instance. when the resource is deleted, Azure automatically deletes the identity. By design, only that Azure resource can use this identity to request tokens from Azure AD.
196+
* **User-assigned**: A managed identity as a standalone Azure resource. For User-assigned managed identities, the identity is managed separately from the resources that use it.
197+
198+
Regardless of the type of identity chosen a managed identity is a service principal of a special type that may only be used with Azure resources. When the managed identity is deleted, the corresponding service principal is automatically removed.
199+
200+
```terraform
201+
resource "azurerm_user_assigned_identity" "example" {
202+
for_each = toset(["user-identity1", "user-identity2"])
203+
resource_group_name = "rg-demo-internal-shared-westeurope-002"
204+
location = "westeurope"
205+
name = each.key
206+
}
207+
208+
module "storage" {
209+
source = "kumarvna/storage/azurerm"
210+
version = "2.5.0"
211+
212+
# .... omitted
213+
214+
# Configure managed identities to access Azure Storage (Optional)
215+
# Possible types are `SystemAssigned`, `UserAssigned` and `SystemAssigned, UserAssigned`.
216+
managed_identity_type = "UserAssigned"
217+
managed_identity_ids = [for k in azurerm_user_assigned_identity.example : k.id]
218+
219+
# .... omitted for bravity
220+
221+
}
222+
```
223+
189224
## Recommended naming and tagging conventions
190225

191226
Applying tags to your Azure resources, resource groups, and subscriptions to logically organize them into a taxonomy. Each tag consists of a name and a value pair. For example, you can apply the name `Environment` and the value `Production` to all the resources in production.
@@ -227,6 +262,8 @@ Name | Description | Type | Default
227262
`last_access_time_enabled`|Is the last access time based tracking enabled?|string|`false`
228263
`change_feed_enabled`|Is the blob service properties for change feed events enabled?|string|`false`
229264
`enable_advanced_threat_protection`|Controls Advance threat protection plan for Storage account!string|`false`
265+
`managed_identity_type`|The type of Managed Identity which should be assigned to the Azure Storage. Possible values are `SystemAssigned`, `UserAssigned` and `SystemAssigned, UserAssigned`|string|`null`
266+
`managed_identity_ids`|A list of User Managed Identity ID's which should be assigned to the Azure Storage.|string|`null`
230267
`network_rules`|Configure Azure storage firewalls and virtual networks|list|`null`
231268
`containers_list`| List of container|list|`[]`
232269
`file_shares`|List of SMB file shares|list|`[]`

main.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@ resource "azurerm_storage_account" "storeacc" {
4343
min_tls_version = var.min_tls_version
4444
tags = merge({ "ResourceName" = substr(format("sta%s%s", lower(replace(var.storage_account_name, "/[[:^alnum:]]/", "")), random_string.unique.result), 0, 24) }, var.tags, )
4545

46-
identity {
47-
type = var.identity_ids != null ? "SystemAssigned, UserAssigned" : "SystemAssigned"
48-
identity_ids = var.identity_ids
46+
dynamic "identity" {
47+
for_each = var.managed_identity_type != null ? [1] : []
48+
content {
49+
type = var.managed_identity_type
50+
identity_ids = var.managed_identity_type == "UserAssigned" || var.managed_identity_type == "SystemAssigned, UserAssigned" ? var.managed_identity_ids : null
51+
}
4952
}
5053

5154
blob_properties {

variables.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,19 @@ variable "lifecycles" {
117117
default = []
118118
}
119119

120-
variable "identity_ids" {
121-
description = "Specifies a list of user managed identity ids to be assigned. This is required when `type` is set to `UserAssigned` or `SystemAssigned, UserAssigned`"
120+
variable "managed_identity_type" {
121+
description = "The type of Managed Identity which should be assigned to the Linux Virtual Machine. Possible values are `SystemAssigned`, `UserAssigned` and `SystemAssigned, UserAssigned`"
122+
default = null
123+
type = string
124+
}
125+
126+
variable "managed_identity_ids" {
127+
description = "A list of User Managed Identity ID's which should be assigned to the Linux Virtual Machine."
122128
default = null
123129
type = list(string)
124130
}
125131

132+
126133
variable "tags" {
127134
description = "A map of tags to add to all resources"
128135
type = map(string)

0 commit comments

Comments
 (0)