Skip to content

Commit 110bff8

Browse files
committed
Adding terraform to create resources for csi driver secrets
Signed-off-by: ritikaguptams <[email protected]>
1 parent 5a05e5c commit 110bff8

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Getting started with secrets-store-csi-driver resource management
2+
The terraform scripts here help create:
3+
- a resource group
4+
- a key vault
5+
- a secret in the key vault
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
provider "azurerm" {
18+
features {}
19+
}
20+
21+
# Data source to get the current client configuration
22+
data "azurerm_client_config" "current" {}
23+
24+
# TODO: add state maintenance in Azure
25+
26+
# Create a resource group
27+
resource "azurerm_resource_group" "secrets_store_rg" {
28+
name = "secrets-store-csi-driver"
29+
location = "westus2"
30+
tags = {
31+
DO-NOT-DELETE = "contact <[email protected]>"
32+
}
33+
}
34+
35+
# Create a Key Vault
36+
resource "azurerm_key_vault" "secrets_csi_kv" {
37+
name = "secrets-store-csi-e2e"
38+
location = azurerm_resource_group.secrets_store_rg.location
39+
resource_group_name = azurerm_resource_group.secrets_store_rg.name
40+
tenant_id = data.azurerm_client_config.current.tenant_id
41+
sku_name = "standard"
42+
43+
depends_on = [azurerm_resource_group.secrets_store_rg]
44+
}
45+
46+
# Create a Key Vault access policy for the Service Principal
47+
resource "azurerm_key_vault_access_policy" "kv_access_service_principal" {
48+
key_vault_id = azurerm_key_vault.secrets_csi_kv.id
49+
tenant_id = data.azurerm_client_config.current.tenant_id
50+
object_id = data.azurerm_client_config.current.object_id
51+
52+
secret_permissions = [
53+
"Set",
54+
"Get"
55+
]
56+
depends_on = [azurerm_key_vault.secrets_csi_kv]
57+
}
58+
59+
# Create a secret in the Key Vault.
60+
# NOTE: This is only used for testing purposes.
61+
resource "azurerm_key_vault_secret" "kv_secret" {
62+
name = "secret1"
63+
value = "test"
64+
key_vault_id = azurerm_key_vault.secrets_csi_kv.id
65+
depends_on = [azurerm_key_vault.secrets_csi_kv]
66+
}
67+
68+
# To run the Terraform script
69+
output "key_vault_id" {
70+
value = azurerm_key_vault.secrets_csi_kv.id
71+
}
72+
73+
output "key_vault_secret_id" {
74+
value = azurerm_key_vault_secret.kv_secret.id
75+
}

0 commit comments

Comments
 (0)