|
| 1 | +````markdown |
| 2 | +# Terraform Template - Azure Key Vault |
| 3 | + |
| 4 | +Costa Rica |
| 5 | + |
| 6 | +[](https://github.com/) |
| 7 | +[brown9804](https://github.com/brown9804) |
| 8 | + |
| 9 | +Last updated: 2026-02-06 |
| 10 | + |
| 11 | +------------------------------------------ |
| 12 | + |
| 13 | +> This template contains Terraform configurations to create and manage an Azure Key Vault with dependencies on a Resource Group. |
| 14 | +
|
| 15 | +> [!NOTE] |
| 16 | +> Key Vault data-plane access (secrets/keys/certificates) depends on your authorization mode: |
| 17 | +> - If `enable_rbac_authorization = true`, grant Azure RBAC roles (for example: Key Vault Secrets Officer) at the vault scope. |
| 18 | +> - If `enable_rbac_authorization = false`, you must manage Key Vault access policies (not included in this minimal template). |
| 19 | +
|
| 20 | +## File Descriptions |
| 21 | + |
| 22 | +- **main.tf**: Contains the main configuration for creating the Azure Key Vault and the Resource Group it depends on. |
| 23 | +- **variables.tf**: Defines the input variables used in the Terraform configuration. |
| 24 | +- **provider.tf**: Configures the Azure provider to interact with Azure resources. |
| 25 | +- **terraform.tfvars**: Provides example values for the variables defined in `variables.tf`. |
| 26 | +- **outputs.tf**: Defines the outputs of the Terraform configuration, such as the Key Vault URI and Resource Group. |
| 27 | + |
| 28 | +## Variables |
| 29 | + |
| 30 | +Below is a list of variables used in this template, their expected values, types, and examples: |
| 31 | + |
| 32 | +| Variable Name | Description | Type | Example Value | |
| 33 | +| --- | --- | --- | --- | |
| 34 | +| `resource_group_name` | The name of the Azure Resource Group to associate the Key Vault with. | string | `"rg-identity-security-dev"` | |
| 35 | +| `location` | The Azure region where the Resource Group will be created. | string | `"East US"` | |
| 36 | +| `key_vault_name` | The name of the Azure Key Vault to create. | string | `"kvidentitydev001"` | |
| 37 | +| `key_vault_name_use_random_suffix` | Append a short random suffix to avoid global name collisions. | bool | `true` | |
| 38 | +| `sku_name` | The SKU name for Key Vault (`standard` or `premium`). | string | `"standard"` | |
| 39 | +| `enable_rbac_authorization` | Use Azure RBAC for data-plane permissions. | bool | `true` | |
| 40 | +| `public_network_access_enabled` | Enable or disable public network access. | bool | `true` | |
| 41 | +| `soft_delete_retention_days` | Soft delete retention days (7-90). | number | `90` | |
| 42 | +| `purge_protection_enabled` | Enable purge protection (affects destroy). | bool | `false` | |
| 43 | +| `network_default_action` | Network ACL default action (`Allow` or `Deny`). | string | `"Allow"` | |
| 44 | +| `network_bypass` | Firewall bypass (`AzureServices` or `None`). | string | `"AzureServices"` | |
| 45 | +| `ip_rules` | List of public IPs/CIDRs allowed. | list(string) | `[]` | |
| 46 | +| `virtual_network_subnet_ids` | List of subnet IDs allowed. | list(string) | `[]` | |
| 47 | +| `tags` | A map of tags to assign to the resources. | map(string) | `{ "env": "dev" }` | |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +1. Authenticate: |
| 52 | + |
| 53 | + ```sh |
| 54 | + az login |
| 55 | + ``` |
| 56 | + |
| 57 | +2. Ensure Azure CLI has the correct active subscription: |
| 58 | + |
| 59 | + ```sh |
| 60 | + az account show |
| 61 | + # If needed: |
| 62 | + az account set --subscription "<subscription-id-or-name>" |
| 63 | + ``` |
| 64 | + |
| 65 | +3. Initialize: |
| 66 | + |
| 67 | + ```sh |
| 68 | + terraform init -upgrade |
| 69 | + ``` |
| 70 | + |
| 71 | +4. Validate and plan: |
| 72 | + |
| 73 | + ```sh |
| 74 | + terraform validate |
| 75 | + terraform plan |
| 76 | + ``` |
| 77 | + |
| 78 | +5. Apply: |
| 79 | + |
| 80 | + ```sh |
| 81 | + terraform apply -auto-approve |
| 82 | + ``` |
| 83 | + |
| 84 | +## Notes |
| 85 | + |
| 86 | +- This template creates the Resource Group for you. |
| 87 | +- Key Vault names are globally unique. If you see `VaultAlreadyExists`, either change the base name or keep `key_vault_name_use_random_suffix = true`. |
| 88 | +- If you enable `purge_protection_enabled`, Key Vault deletion becomes more restrictive and `terraform destroy` may fail until purge protection rules allow cleanup. |
| 89 | + |
| 90 | +<!-- START BADGE --> |
| 91 | +<div align="center"> |
| 92 | + <img src="https://img.shields.io/badge/Total%20views-0-limegreen" alt="Total views"> |
| 93 | + <p>Refresh Date: 2026-02-06</p> |
| 94 | +</div> |
| 95 | +<!-- END BADGE --> |
| 96 | + |
| 97 | +```` |
0 commit comments