Skip to content

Commit 5316c21

Browse files
Feature/keyvault nonprod (#16)
* "Update GitHub workflow to push to main branch instead of default branch" * DEVOPS-303 nonprod keyvaul terraform module * DEVOPS-303 fix variable validation issue * DEVOPS-303 fix access policy objet type issue
1 parent 7156ee3 commit 5316c21

File tree

6 files changed

+220
-1
lines changed

6 files changed

+220
-1
lines changed

.github/workflows/create-root-readme.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
git add .
4040
git commit -m "Update documentation"
4141
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/devwithkrishna/azure-terraform-modules.git
42-
git push
42+
git push origin main

keyvault-nonprod/data.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "azurerm_client_config" "current" {}

keyvault-nonprod/keyvault.tf

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
resource "azurerm_resource_group" "keyvault_rg" {
2+
name = var.resource_group_name
3+
location = var.location
4+
tags = {
5+
Environment = upper(var.environment)
6+
Orchestrator = "Terraform"
7+
DisplayName = upper(var.resource_group_name)
8+
ApplicationName = lower(var.application_name)
9+
Temporary = upper(var.temporary)
10+
}
11+
}
12+
13+
resource "azurerm_key_vault" "kv" {
14+
name = var.keyvault_name
15+
resource_group_name = azurerm_resource_group.keyvault_rg.name
16+
location = azurerm_resource_group.keyvault_rg.location
17+
tenant_id = data.azurerm_client_config.current.tenant_id
18+
sku_name = var.sku_name
19+
20+
enable_rbac_authorization = var.enable_rbac_authorization
21+
enabled_for_deployment = var.azure_vms_can_access_certs_stored_as_secrets
22+
enabled_for_disk_encryption = var.azure_disk_encryption_can_retrieve_secrets
23+
enabled_for_template_deployment = var.azure_resource_manager_can_retrieve_secrets
24+
25+
purge_protection_enabled = var.purge_protection_enabled
26+
soft_delete_retention_days = var.soft_delete_retention_days
27+
28+
public_network_access_enabled = var.public_network_access_enabled
29+
30+
access_policy {
31+
tenant_id = data.azurerm_client_config.current.tenant_id
32+
object_id = data.azurerm_client_config.current.object_id
33+
34+
key_permissions = [
35+
"Get", "List", "Create", "Recover", "Purge", "UnwrapKey", "Update", "WrapKey", "Rotate", "GetRotationPolicy", "SetRotationPolicy"
36+
]
37+
38+
secret_permissions = [
39+
"Get","Set", "List", "Delete", "Recover"
40+
]
41+
42+
storage_permissions = [
43+
"Get", "Delete", "List", "Recover", "RegenerateKey","Restore","Set" , "SetSAS", "Update"
44+
]
45+
46+
certificate_permissions = [
47+
"Create", "Delete", "Get", "GetIssuers", "Import", "List", "ListIssuers", "ManageIssuers", "SetIssuers", "Update"
48+
]
49+
50+
}
51+
52+
tags = {
53+
Environment = upper(var.environment)
54+
Orchestrator = "Terraform"
55+
DisplayName = upper(var.keyvault_name)
56+
ApplicationName = lower(var.application_name)
57+
Temporary = upper(var.temporary)
58+
59+
}
60+
}

keyvault-nonprod/output.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
output "azurerm_resource_group" {
2+
description = "Azure resource group name"
3+
value = azurerm_resource_group.keyvault_rg
4+
}
5+
6+
output "keyvault_name" {
7+
description = "Azure keyvault name"
8+
value = azurerm_key_vault.kv.name
9+
}
10+
11+
output "keyvault_location" {
12+
description = "Azure keyvault location"
13+
value = azurerm_key_vault.kv.location
14+
}
15+
16+
output "keyvault_sku" {
17+
description = "Azure Keyvault SKu"
18+
value = azurerm_key_vault.kv.sku_name
19+
}
20+
21+
output "enable_rbac_authorization" {
22+
description = "Azure kv RBAC access enabled or not"
23+
value = azurerm_key_vault.kv.enable_rbac_authorization
24+
}
25+
26+
output "enabled_for_deployment" {
27+
description = "Azure vms can access certs from kv"
28+
value = azurerm_key_vault.kv.enabled_for_deployment
29+
}
30+
31+
output "enabled_for_disk_encryption" {
32+
description = "Azure disk encryption can access keys from keyvault or not"
33+
value = azurerm_key_vault.kv.enabled_for_disk_encryption
34+
}
35+
36+
output "enabled_for_template_deployment" {
37+
description = "Azure resource manager can access secrets or not"
38+
value = azurerm_key_vault.kv.enabled_for_template_deployment
39+
}
40+
output "public_access_enabled" {
41+
description = "Azure kv enabled public access or not"
42+
value = azurerm_key_vault.kv.public_network_access_enabled
43+
}

keyvault-nonprod/providers.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
terraform {
2+
required_version = "~> 1.3"
3+
required_providers {
4+
azurerm = {
5+
source = "hashicorp/azurerm"
6+
version = "<= 4.0"
7+
}
8+
random = {
9+
source = "hashicorp/random"
10+
version = ">= 3.1"
11+
}
12+
}
13+
}
14+
provider "azurerm" {
15+
features {}
16+
}

keyvault-nonprod/variables.tf

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
variable "resource_group_name" {
2+
type = string
3+
description = "Azure keyvault Rg"
4+
}
5+
6+
variable "location" {
7+
type = string
8+
description = "Azure keyvault location"
9+
default = ""
10+
}
11+
12+
variable "keyvault_name" {
13+
description = "Azure keyvault name"
14+
type = string
15+
16+
}
17+
18+
variable "sku_name" {
19+
default = "standard"
20+
description = "Keyvault SKUs available in azure. Valid options are standard and premium"
21+
validation {
22+
condition = contains(["standard", "premium"], var.sku_name)
23+
error_message = "Keyvault SKU should be one among standard or premium"
24+
}
25+
}
26+
27+
variable "environment" {
28+
default = "DEV"
29+
description = "Environment tag value in Azure"
30+
type = string
31+
validation {
32+
condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment)
33+
error_message = "Environment value should be one among DEV or QA or UAT or PROD."
34+
}
35+
}
36+
37+
variable "application_name" {
38+
default = "devwithkrishna"
39+
description = "Azure application name tag"
40+
}
41+
42+
43+
variable "temporary" {
44+
default = "TRUE"
45+
description = "Temporary tag value in Azure"
46+
type = string
47+
validation {
48+
condition = contains(["TRUE", "FALSE"], upper(var.temporary))
49+
error_message = "The temporary tag value must be either 'TRUE' or 'FALSE'."
50+
}
51+
52+
}
53+
54+
variable "azure_vms_can_access_certs_stored_as_secrets" {
55+
default = false
56+
type = bool
57+
description = "Boolean flag to specify whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault"
58+
}
59+
60+
variable "azure_disk_encryption_can_retrieve_secrets"{
61+
default = false
62+
type = bool
63+
description = "Boolean flag to specify whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys"
64+
}
65+
66+
variable "azure_resource_manager_can_retrieve_secrets"{
67+
default = false
68+
type = bool
69+
description = "Boolean flag to specify whether Azure Resource Manager is permitted to retrieve secrets from the vault"
70+
}
71+
72+
variable "enable_rbac_authorization" {
73+
default = false
74+
type = bool
75+
description = "Boolean flag to specify whether Azure Key Vault uses Role Based Access Control (RBAC) for authorization of data actions"
76+
}
77+
78+
variable "purge_protection_enabled" {
79+
type = bool
80+
default = false
81+
description = "Purge Protection enabled or not"
82+
}
83+
84+
variable "public_network_access_enabled" {
85+
default = true
86+
type = bool
87+
description = "Whether public network access is allowed for this Key Vault"
88+
}
89+
90+
variable "soft_delete_retention_days" {
91+
default = 90
92+
type = number
93+
description = " The number of days that items should be retained for once soft-deleted. This value can be between 7 and 90"
94+
validation {
95+
condition = var.soft_delete_retention_days >= 7 && var.soft_delete_retention_days <=90
96+
error_message = "This value should be between 7 and 90 both included."
97+
}
98+
}
99+

0 commit comments

Comments
 (0)