forked from oracle-quickstart/appstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vault.tf
84 lines (76 loc) · 2.89 KB
/
vault.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Copyright (c) 2023, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
resource "oci_kms_vault" "app_vault" {
compartment_id = var.compartment_id
display_name = var.new_vault_display_name
vault_type = "DEFAULT"
count = var.use_existing_vault ? 0 : 1
}
resource "oci_kms_key" "app_key" {
compartment_id = var.compartment_id
display_name = "${var.new_vault_display_name}-key"
key_shape {
algorithm = "AES"
length = 256
}
management_endpoint = oci_kms_vault.app_vault[0].management_endpoint
count = var.use_existing_vault ? 0 : 1
}
# Secret containing the authentication token
resource "oci_vault_secret" "auth_token_secret" {
depends_on = [
oci_kms_vault.app_vault,
oci_kms_key.app_key
]
#Required
compartment_id = var.use_existing_vault ? var.vault_compartment_id : var.compartment_id
secret_content {
#Required
content_type = "BASE64"
#Optional
content = base64encode(oci_identity_auth_token.auth_token.token)
name = "auth_token_content_${formatdate("MMDDhhmm", timestamp())}"
}
secret_name ="auth_token_secret_${formatdate("MMDDhhmm", timestamp())}"
vault_id = var.use_existing_vault ? var.vault_id : oci_kms_vault.app_vault[0].id
key_id = var.use_existing_vault ? var.key_id : oci_kms_key.app_key[0].id
}
# Secret containing the db user's password
resource "oci_vault_secret" "db_user_password" {
depends_on = [
oci_kms_vault.app_vault,
oci_kms_key.app_key
]
#Required
compartment_id = var.use_existing_vault ? var.vault_compartment_id : var.compartment_id
secret_content {
#Required
content_type = "BASE64"
#Optional
content = base64encode(local.password)
name = "db_user_password_${var.application_name}_${formatdate("MMDDhhmm", timestamp())}"
}
secret_name = "db_user_password_${var.application_name}_${formatdate("MMDDhhmm", timestamp())}"
vault_id = var.use_existing_vault ? var.vault_id : oci_kms_vault.app_vault[0].id
key_id = var.use_existing_vault ? var.key_id : oci_kms_key.app_key[0].id
}
# Secret containing the db wallet password
resource "oci_vault_secret" "db_wallet_password" {
depends_on = [
oci_kms_vault.app_vault,
oci_kms_key.app_key,
random_password.wallet_password
]
#Required
compartment_id = var.use_existing_vault ? var.vault_compartment_id : var.compartment_id
secret_content {
#Required
content_type = "BASE64"
#Optional
content = base64encode(random_password.wallet_password.result)
name = "db_wallet_password_${var.application_name}_${formatdate("MMDDhhmm", timestamp())}"
}
secret_name ="db_wallet_password_${var.application_name}_${formatdate("MMDDhhmm", timestamp())}"
vault_id = var.use_existing_vault ? var.vault_id : oci_kms_vault.app_vault[0].id
key_id = var.use_existing_vault ? var.key_id : oci_kms_key.app_key[0].id
}