Code Monkey home page Code Monkey logo

terraform-azurerm-keyvault's Introduction

Azure Key Vault feature

Changelog Notice Apache V2 License TF Registry

This Terraform module creates an Azure Key Vault with "reader" and "admin" pre-configured Access policies and Diagnostic settings enabled.

Global versioning rule for Claranet Azure modules

Module version Terraform version AzureRM version
>= 7.x.x 1.3.x >= 3.0
>= 6.x.x 1.x >= 3.0
>= 5.x.x 0.15.x >= 2.0
>= 4.x.x 0.13.x / 0.14.x >= 2.0
>= 3.x.x 0.12.x >= 2.0
>= 2.x.x 0.12.x < 2.0
< 2.x.x 0.11.x < 2.0

Contributing

If you want to contribute to this repository, feel free to use our pre-commit git hook configuration which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices.

More details are available in the CONTRIBUTING.md file.

Usage

This module is optimized to work with the Claranet terraform-wrapper tool which set some terraform variables in the environment needed by this module. More details about variables set by the terraform-wrapper available in the documentation.

module "azure_region" {
  source  = "claranet/regions/azurerm"
  version = "x.x.x"

  azure_region = var.azure_region
}

module "rg" {
  source  = "claranet/rg/azurerm"
  version = "x.x.x"

  location    = module.azure_region.location
  client_name = var.client_name
  environment = var.environment
  stack       = var.stack
}

data "azuread_group" "admin_group" {
  display_name = "Admin"
}

module "logs" {
  source  = "claranet/run/azurerm//modules/logs"
  version = "x.x.x"

  client_name         = var.client_name
  environment         = var.environment
  stack               = var.stack
  location            = module.azure_region.location
  location_short      = module.azure_region.location_short
  resource_group_name = module.rg.resource_group_name
}

module "key_vault" {
  source  = "claranet/keyvault/azurerm"
  version = "x.x.x"

  client_name         = var.client_name
  environment         = var.environment
  location            = module.azure_region.location
  location_short      = module.azure_region.location_short
  resource_group_name = module.rg.resource_group_name
  stack               = var.stack

  logs_destinations_ids = [
    module.logs.logs_storage_account_id,
    module.logs.log_analytics_workspace_id,
  ]

  # WebApp or other applications Object IDs
  reader_objects_ids = [
    var.webapp_service_principal_id
  ]

  # Current user should be here to be able to create keys and secrets
  admin_objects_ids = [
    data.azuread_group.admin_group.id
  ]

  # Specify Network ACLs
  network_acls = {
    bypass         = "None"
    default_action = "Deny"
    ip_rules       = ["10.10.0.0/26", "1.2.3.4/32"]

    virtual_network_subnet_ids = var.subnet_ids
  }
}

Providers

Name Version
azurecaf ~> 1.2, >= 1.2.22
azurerm ~> 3.39

Modules

Name Source Version
diagnostics claranet/diagnostic-settings/azurerm ~> 6.5.0

Resources

Name Type
azurerm_key_vault.keyvault resource
azurerm_key_vault_access_policy.admin_policy resource
azurerm_key_vault_access_policy.readers_policy resource
azurerm_key_vault_managed_hardware_security_module.keyvault_hsm resource
azurerm_role_assignment.rbac_keyvault_administrator resource
azurerm_role_assignment.rbac_keyvault_reader resource
azurerm_role_assignment.rbac_keyvault_secrets_users resource
azurecaf_name.keyvault data source
azurecaf_name.keyvault_hsm data source
azurerm_client_config.current_config data source

Inputs

Name Description Type Default Required
admin_objects_ids IDs of the objects that can do all operations on all keys, secrets and certificates. list(string) [] no
client_name Client name string n/a yes
custom_diagnostic_settings_name Custom name of the diagnostics settings, name will be 'default' if not set. string "default" no
custom_name Name of the Key Vault, generated if not set. string "" no
default_tags_enabled Option to enable or disable default tags. bool true no
enabled_for_deployment Whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the Key Vault. bool false no
enabled_for_disk_encryption Whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys. bool false no
enabled_for_template_deployment Whether Azure Resource Manager is permitted to retrieve secrets from the Key Vault. bool false no
environment Environment name string n/a yes
extra_tags Extra tags to add. map(string) {} no
location Azure location for Key Vault. string n/a yes
location_short Short string for Azure location. string n/a yes
logs_categories Log categories to send to destinations. list(string) null no
logs_destinations_ids List of destination resources IDs for logs diagnostic destination.
Can be Storage Account, Log Analytics Workspace and Event Hub. No more than one of each can be set.
If you want to specify an Azure EventHub to send logs and metrics to, you need to provide a formated string with both the EventHub Namespace authorization send ID and the EventHub name (name of the queue to use in the Namespace) separated by the `
` character. list(string) n/a
logs_metrics_categories Metrics categories to send to destinations. list(string) null no
managed_hardware_security_module_enabled Create a KeyVault Managed HSM resource if enabled. Changing this forces a new resource to be created. bool false no
name_prefix Optional prefix for the generated name string "" no
name_suffix Optional suffix for the generated name string "" no
network_acls Object with attributes: bypass, default_action, ip_rules, virtual_network_subnet_ids. Set to null to disable. See https://www.terraform.io/docs/providers/azurerm/r/key_vault.html#bypass for more information.
object({
bypass = optional(string, "None"),
default_action = optional(string, "Deny"),
ip_rules = optional(list(string)),
virtual_network_subnet_ids = optional(list(string)),
})
{} no
public_network_access_enabled Whether the Key Vault is available from public network. bool false no
purge_protection_enabled Whether to activate purge protection. bool true no
rbac_authorization_enabled Whether the Key Vault uses Role Based Access Control (RBAC) for authorization of data actions instead of access policies. bool false no
reader_objects_ids IDs of the objects that can read all keys, secrets and certificates. list(string) [] no
resource_group_name Resource Group the resources will belong to string n/a yes
sku_name The Name of the SKU used for this Key Vault. Possible values are "standard" and "premium". string "standard" no
soft_delete_retention_days The number of days that items should be retained for once soft-deleted. This value can be between 7 and 90 days. number 7 no
stack Stack name string n/a yes
tenant_id The Azure Active Directory tenant ID that should be used for authenticating requests to the Key Vault. Default is the current one. string "" no
use_caf_naming Use the Azure CAF naming provider to generate default resource name. custom_name override this if set. Legacy default name is used if this is set to false. bool true no

Outputs

Name Description
key_vault_hsm_uri The URI of the Key Vault Managed Hardware Security Module, used for performing operations on keys.
key_vault_id ID of the Key Vault.
key_vault_name Name of the Key Vault.
key_vault_uri URI of the Key Vault

Related documentation

Microsoft Azure documentation: docs.microsoft.com/en-us/azure/key-vault/

terraform-azurerm-keyvault's People

Contributors

alanbty avatar bd-clara avatar bzspi avatar jmapro avatar jnancel avatar maxpoullain avatar pyar97 avatar rossifumax avatar shr3ps avatar zfiel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

terraform-azurerm-keyvault's Issues

[FEAT] Allow undetermined ID values in admin_objects_ids

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

I'm trying to assign application (or service principal) an RBAC role to key vault created with this module:

resource "azuread_application" "example" {
  #...snip...
}
module "keyvault" {
  source  = "claranet/keyvault/azurerm"
  version = "7.5.0"

  #...snip...

  admin_objects_ids = [
    data.azurerm_client_config.current.object_id,
    azuread_application.example.object_id           # <--- troublemaker
  ]

but terraform plan complains

โ”‚ Error: Invalid for_each argument
โ”‚
โ”‚   on .terraform/modules/keyvault/r-rbac.tf line 2, in resource "azurerm_role_assignment" "rbac_keyvault_administrator":
โ”‚    2:   for_each = toset(var.rbac_authorization_enabled && !var.managed_hardware_security_module_enabled ? var.admin_objects_ids : [])
โ”‚     โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”‚     โ”‚ var.admin_objects_ids is list of string with 2 elements
โ”‚     โ”‚ var.managed_hardware_security_module_enabled is false
โ”‚     โ”‚ var.rbac_authorization_enabled is true
โ”‚
โ”‚ The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the instances of this resource.
โ”‚
โ”‚ When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values contain apply-time results.
โ”‚
โ”‚ Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge.

If I remove the azuread_application.example.object_id from the admin_objects_ids list, then obviously the error is gone.

New or Affected Resource(s)/Data Source(s)

azurerm_role_assignment

Potential Terraform Configuration

No response

References

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.