From c23525dd537e7f41af5bdcf6cddf8141c2a5b99b Mon Sep 17 00:00:00 2001 From: brown9804 Date: Mon, 9 Feb 2026 15:19:22 -0600 Subject: [PATCH 1/2] managed identity template --- 4_identity-security/README.md | 1 + .../managed-identity/README.md | 76 +++++++++++++++++++ 4_identity-security/managed-identity/main.tf | 22 ++++++ .../managed-identity/outputs.tf | 27 +++++++ .../managed-identity/provider.tf | 25 ++++++ .../managed-identity/terraform.tfvars | 11 +++ .../managed-identity/variables.tf | 28 +++++++ 7 files changed, 190 insertions(+) create mode 100644 4_identity-security/managed-identity/README.md create mode 100644 4_identity-security/managed-identity/main.tf create mode 100644 4_identity-security/managed-identity/outputs.tf create mode 100644 4_identity-security/managed-identity/provider.tf create mode 100644 4_identity-security/managed-identity/terraform.tfvars create mode 100644 4_identity-security/managed-identity/variables.tf diff --git a/4_identity-security/README.md b/4_identity-security/README.md index 2fd27cd..835ccb9 100644 --- a/4_identity-security/README.md +++ b/4_identity-security/README.md @@ -16,6 +16,7 @@ Last updated: 2026-02-09 - [Microsoft Entra ID (Entra ID)](./entra_id) - [Azure Key Vault](./key-vault) +- [User Assigned Managed Identity](./managed-identity)
diff --git a/4_identity-security/managed-identity/README.md b/4_identity-security/managed-identity/README.md new file mode 100644 index 0000000..18afdf6 --- /dev/null +++ b/4_identity-security/managed-identity/README.md @@ -0,0 +1,76 @@ +# Terraform Template - User Assigned Managed Identity + +Costa Rica + +[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/) +[brown9804](https://github.com/brown9804) + +Last updated: 2026-02-09 + +------------------------------------------ + +> This template contains Terraform configurations to create an Azure User Assigned Managed Identity with dependencies on a Resource Group. + +## File Descriptions + +- **main.tf**: Contains the main configuration for creating the Resource Group and the User Assigned Managed Identity. +- **variables.tf**: Defines the input variables used in the Terraform configuration. +- **provider.tf**: Configures the Azure provider to interact with Azure resources. +- **terraform.tfvars**: Provides example values for the variables defined in `variables.tf`. +- **outputs.tf**: Defines outputs such as the identity resource ID, client ID, and principal ID. + +## Variables + +| Variable Name | Description | Type | Example Value | +| --- | --- | --- | --- | +| `resource_group_name` | The name of the Azure Resource Group to create and place the identity in. | string | `"rg-identity-security-dev"` | +| `location` | The Azure region where the Resource Group (and identity) will be created. | string | `"East US"` | +| `managed_identity_name` | The name of the User Assigned Managed Identity to create. | string | `"id-identity-security-dev-001"` | +| `tags` | A map of tags to assign to the resources. | map(string) | `{ "env": "dev" }` | + +## Usage + +1. Authenticate: + + ```sh + az login + ``` + +2. Ensure Azure CLI has the correct active subscription: + + ```sh + az account show + # If needed: + az account set --subscription "" + ``` + +3. Initialize: + + ```sh + terraform init -upgrade + ``` + +4. Validate and plan: + + ```sh + terraform validate + terraform plan + ``` + +5. Apply: + + ```sh + terraform apply -auto-approve + ``` + +> [!NOTES] +> +> - This template creates the Resource Group for you. +> - A User Assigned Managed Identity can be attached to Azure resources (VMs, App Service, Functions, etc.) and granted permissions via Azure RBAC. + + +
+ Total views +

Refresh Date: 2026-02-09

+
+ diff --git a/4_identity-security/managed-identity/main.tf b/4_identity-security/managed-identity/main.tf new file mode 100644 index 0000000..ef97171 --- /dev/null +++ b/4_identity-security/managed-identity/main.tf @@ -0,0 +1,22 @@ +# main.tf +# This file contains the main configuration for creating an Azure User Assigned Managed Identity. +# It defines the resource blocks for the Azure Resource Group and the Managed Identity. + +resource "azurerm_resource_group" "example" { + name = var.resource_group_name + location = var.location + + tags = var.tags +} + +resource "azurerm_user_assigned_identity" "example" { + name = var.managed_identity_name + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + tags = var.tags + + depends_on = [ + azurerm_resource_group.example + ] +} diff --git a/4_identity-security/managed-identity/outputs.tf b/4_identity-security/managed-identity/outputs.tf new file mode 100644 index 0000000..c582e95 --- /dev/null +++ b/4_identity-security/managed-identity/outputs.tf @@ -0,0 +1,27 @@ +# outputs.tf +# This file defines the outputs of the Terraform configuration. + +output "managed_identity_id" { + description = "The resource ID of the User Assigned Managed Identity." + value = azurerm_user_assigned_identity.example.id +} + +output "managed_identity_name" { + description = "The name of the User Assigned Managed Identity." + value = azurerm_user_assigned_identity.example.name +} + +output "managed_identity_client_id" { + description = "The client ID (application ID) of the User Assigned Managed Identity." + value = azurerm_user_assigned_identity.example.client_id +} + +output "managed_identity_principal_id" { + description = "The principal ID (object ID) of the User Assigned Managed Identity." + value = azurerm_user_assigned_identity.example.principal_id +} + +output "resource_group_name" { + description = "The name of the Resource Group created for this template." + value = azurerm_resource_group.example.name +} diff --git a/4_identity-security/managed-identity/provider.tf b/4_identity-security/managed-identity/provider.tf new file mode 100644 index 0000000..ea7ee3c --- /dev/null +++ b/4_identity-security/managed-identity/provider.tf @@ -0,0 +1,25 @@ +# provider.tf +# This file configures the Azure provider to interact with Azure resources. +# It specifies the required provider and its version, along with provider-specific configurations. + +terraform { + required_version = ">= 1.8, < 2.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~> 3.116" + } + } +} + +provider "azurerm" { + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } + + # Uses the current Azure CLI context (az login + az account set) + skip_provider_registration = false +} diff --git a/4_identity-security/managed-identity/terraform.tfvars b/4_identity-security/managed-identity/terraform.tfvars new file mode 100644 index 0000000..d809af9 --- /dev/null +++ b/4_identity-security/managed-identity/terraform.tfvars @@ -0,0 +1,11 @@ +# Example values for the Managed Identity template + +resource_group_name = "rg-identity-security-dev" +location = "East US" +managed_identity_name = "id-identity-security-dev-001" + +tags = { + env = "dev" + app = "identity-security" + owner = "terraform" +} diff --git a/4_identity-security/managed-identity/variables.tf b/4_identity-security/managed-identity/variables.tf new file mode 100644 index 0000000..9e07bb8 --- /dev/null +++ b/4_identity-security/managed-identity/variables.tf @@ -0,0 +1,28 @@ +# variables.tf +# This file defines the input variables used in the Terraform configuration. + +variable "resource_group_name" { + description = "The name of the Azure Resource Group to create and place the Managed Identity in." + type = string +} + +variable "location" { + description = "The Azure region where the Resource Group (and Managed Identity) will be created." + type = string +} + +variable "managed_identity_name" { + description = "The name of the User Assigned Managed Identity to create." + type = string + + validation { + condition = length(trimspace(var.managed_identity_name)) > 0 + error_message = "managed_identity_name must not be empty." + } +} + +variable "tags" { + description = "A map of tags to assign to the resources." + type = map(string) + default = {} +} From fde4d9667bbedc210e0f19cee9cf193118aa364e Mon Sep 17 00:00:00 2001 From: Timna Brown <24630902+brown9804@users.noreply.github.com> Date: Mon, 9 Feb 2026 15:47:30 -0600 Subject: [PATCH 2/2] Enhance README with additional images Added images to the README for better visualization. --- 4_identity-security/managed-identity/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/4_identity-security/managed-identity/README.md b/4_identity-security/managed-identity/README.md index 18afdf6..8a74290 100644 --- a/4_identity-security/managed-identity/README.md +++ b/4_identity-security/managed-identity/README.md @@ -11,6 +11,10 @@ Last updated: 2026-02-09 > This template contains Terraform configurations to create an Azure User Assigned Managed Identity with dependencies on a Resource Group. +image + +image + ## File Descriptions - **main.tf**: Contains the main configuration for creating the Resource Group and the User Assigned Managed Identity.