|
| 1 | +# Terraform Template - Microsoft Entra ID (Entra ID) |
| 2 | + |
| 3 | +Costa Rica |
| 4 | + |
| 5 | +[](https://github.com/) |
| 6 | +[brown9804](https://github.com/brown9804) |
| 7 | + |
| 8 | +Last updated: 2026-02-03 |
| 9 | + |
| 10 | +------------------------------------------ |
| 11 | + |
| 12 | +> High level: creates a Microsoft Entra ID application registration (tenant-level). Optionally creates a service principal, a client secret, and (optionally) assigns an Azure RBAC role at a provided scope. |
| 13 | +
|
| 14 | +> High level: creates a Microsoft Entra ID application registration (tenant-level). Optionally creates a service principal and a client secret. |
| 15 | +
|
| 16 | +> No Azure resource group is required unless you choose a resource-group RBAC scope (because the RG must already exist for role assignment). |
| 17 | +
|
| 18 | +## File Descriptions |
| 19 | + |
| 20 | +- **main.tf**: Creates the application registration, optional service principal, and optional client secret. |
| 21 | +- **variables.tf**: Defines the input variables used in the Terraform configuration. |
| 22 | +- **provider.tf**: Configures the AzureRM and AzureAD providers. |
| 23 | +- **terraform.tfvars**: Provides example values for the variables defined in `variables.tf`. |
| 24 | +- **outputs.tf**: Defines outputs such as the application client ID, object IDs, and the client secret. |
| 25 | + |
| 26 | +## Variables |
| 27 | + |
| 28 | +Below is a list of variables used in this template, their expected values, types, and examples: |
| 29 | + |
| 30 | +| Variable Name | Description | Type | Example Value | |
| 31 | +| --- | --- | --- | --- | |
| 32 | +| `app_display_name` | The display name for the Entra ID application registration. | string | `"example-entra-app"` | |
| 33 | +| `sign_in_audience` | The Microsoft account types supported for the application. | string | `"AzureADMyOrg"` | |
| 34 | +| `application_owners` | Optional set of object IDs to set as owners. If empty, the current principal is used. | set(string) | `["00000000-0000-0000-0000-000000000000"]` | |
| 35 | +| `create_service_principal` | Whether to create a service principal for the application. | bool | `true` | |
| 36 | +| `use_existing_service_principal` | Import existing service principal linked to the application when present. | bool | `true` | |
| 37 | +| `create_client_secret` | Whether to create a client secret (application password). | bool | `true` | |
| 38 | +| `client_secret_display_name` | Display name for the client secret. | string | `"terraform-client-secret"` | |
| 39 | +| `client_secret_end_date_relative` | Relative duration for which the secret is valid. | string | `"4320h"` | |
| 40 | + |
| 41 | +## Usage |
| 42 | + |
| 43 | +1. Authenticate: |
| 44 | + |
| 45 | + ```sh |
| 46 | + az login |
| 47 | + ``` |
| 48 | + |
| 49 | +2. Initialize and apply: |
| 50 | + |
| 51 | + ```sh |
| 52 | + terraform init -upgrade |
| 53 | + terraform apply -auto-approve |
| 54 | + ``` |
| 55 | + |
| 56 | + Keep your `terraform.tfvars` minimal: set only `app_display_name`, and explicitly opt-in to optional resources (service principal, client secret, RBAC scope) when you need them. |
| 57 | + |
| 58 | +3. Validate and plan: |
| 59 | + |
| 60 | + ```sh |
| 61 | + terraform validate |
| 62 | + terraform plan |
| 63 | + ``` |
| 64 | + |
| 65 | +4. Apply: |
| 66 | + |
| 67 | + ```sh |
| 68 | + terraform apply -auto-approve |
| 69 | + ``` |
| 70 | + |
| 71 | +If you need Azure RBAC role assignments, use an AzureRM-based template (requires a subscription context and scope such as a subscription or resource group). |
| 72 | + |
| 73 | +> These `TF_VAR_*` environment variables are scoped to your current shell session. |
| 74 | +
|
| 75 | +## Notes |
| 76 | + |
| 77 | +- Creating applications, service principals, and secrets requires Microsoft Entra ID permissions (e.g., Application Administrator or appropriate Microsoft Graph application roles). |
| 78 | +- This template does not create Azure resources and does not require a resource group. |
| 79 | + |
| 80 | +<!-- START BADGE --> |
| 81 | +<div align="center"> |
| 82 | + <img src="https://img.shields.io/badge/Total%20views-1283-limegreen" alt="Total views"> |
| 83 | + <p>Refresh Date: 2026-02-03</p> |
| 84 | +</div> |
| 85 | +<!-- END BADGE --> |
0 commit comments