Skip to content

Commit 6ea864c

Browse files
committed
oci-kms-vault module clean up
Signed-off-by: junior <junior@users.noreply.github.com>
1 parent a8ee653 commit 6ea864c

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

modules/oci-vault-kms/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
### OCI Vault vault
1010
resource "oci_kms_vault" "oke_vault" {
1111
compartment_id = var.oke_cluster_compartment_ocid
12-
display_name = "${local.vault_display_name} - ${var.app_details.app_deployment_id}"
12+
display_name = "${local.vault_display_name} - ${var.freeform_deployment_tags.DeploymentID}"
1313
vault_type = local.vault_type[0]
14-
freeform_tags = local.freeform_deployment_tags
14+
freeform_tags = var.freeform_deployment_tags
1515

1616
# depends_on = [oci_identity_policy.kms_user_group_compartment_policies]
1717

@@ -20,10 +20,10 @@ resource "oci_kms_vault" "oke_vault" {
2020
### OCI Vault key
2121
resource "oci_kms_key" "oke_key" {
2222
compartment_id = var.oke_cluster_compartment_ocid
23-
display_name = "${local.vault_key_display_name} - ${var.app_details.app_deployment_id}"
23+
display_name = "${local.vault_key_display_name} - ${var.freeform_deployment_tags.DeploymentID}"
2424
management_endpoint = oci_kms_vault.oke_vault[0].management_endpoint
2525
protection_mode = local.vault_key_protection_mode
26-
freeform_tags = local.freeform_deployment_tags
26+
freeform_tags = var.freeform_deployment_tags
2727

2828
key_shape {
2929
algorithm = local.vault_key_key_shape_algorithm

modules/oci-vault-kms/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#
44

55
output "oci_vault_key_id" {
6-
value = var.use_encryption_from_oci_vault ? (var.create_new_encryption_key ? oci_kms_key.oke_key[0].id : var.existent_encryption_key_id) : null
6+
value = var.use_encryption_from_oci_vault ? (var.create_new_encryption_key ? oci_kms_key.oke_key[0].id : var.existent_encryption_key_id) : null
77
}

modules/oci-vault-kms/policies.tf

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@
33
#
44

55
resource "oci_identity_dynamic_group" "app_dynamic_group" {
6-
name = "${local.app_name_normalized}-kms-dg-${var.app_details.app_deployment_id}"
7-
description = "${var.app_details.app_name} KMS for OKE Dynamic Group (${var.app_details.app_deployment_id})"
6+
name = "${local.app_name_normalized}-kms-dg-${local.deploy_id}"
7+
description = "${local.app_name} KMS for OKE Dynamic Group (${local.deploy_id})"
88
compartment_id = var.tenancy_ocid
99
matching_rule = "ANY {${join(",", local.dynamic_group_matching_rules)}}"
1010

1111
provider = oci.home_region
1212

13-
count = var.create_dynamic_group_for_nodes_in_compartment ? 1 : 0
13+
count = (var.use_encryption_from_oci_vault && var.create_dynamic_group_for_nodes_in_compartment) ? 1 : 0
1414
}
1515
resource "oci_identity_policy" "app_compartment_policies" {
16-
name = "${local.app_name_normalized}-kms-compartment-policies-${var.app_details.app_deployment_id}"
17-
description = "${var.app_details.app_name} KMS for OKE Compartment Policies (${var.app_details.app_deployment_id})"
16+
name = "${local.app_name_normalized}-kms-compartment-policies-${local.deploy_id}"
17+
description = "${local.app_name} KMS for OKE Compartment Policies (${local.deploy_id})"
1818
compartment_id = var.oke_cluster_compartment_ocid
1919
statements = local.app_compartment_statements
2020

2121
depends_on = [oci_identity_dynamic_group.app_dynamic_group]
2222

2323
provider = oci.home_region
2424

25-
count = var.create_compartment_policies ? 1 : 0
25+
count = (var.use_encryption_from_oci_vault && var.create_compartment_policies) ? 1 : 0
2626
}
2727
resource "oci_identity_policy" "kms_user_group_compartment_policies" {
28-
name = "${local.app_name_normalized}-kms-compartment-policies-${var.app_details.app_deployment_id}"
29-
description = "${var.app_details.app_name} KMS User Group Compartment Policies (${var.app_details.app_deployment_id})"
28+
name = "${local.app_name_normalized}-kms-compartment-policies-${local.deploy_id}"
29+
description = "${local.app_name} KMS User Group Compartment Policies (${local.deploy_id})"
3030
compartment_id = var.oke_cluster_compartment_ocid
3131
statements = local.kms_user_group_compartment_statements
3232

3333
depends_on = [oci_identity_dynamic_group.app_dynamic_group]
3434

3535
provider = oci.home_region
3636

37-
count = (var.create_compartment_policies && var.create_vault_policies_for_group) ? 1 : 0
37+
count = (var.use_encryption_from_oci_vault && var.create_compartment_policies && var.create_vault_policies_for_group) ? 1 : 0
3838
}
3939

4040
# Concat Matching Rules and Policy Statements
@@ -44,7 +44,7 @@ locals {
4444
local.clusters_in_compartment_rule
4545
)
4646
app_compartment_statements = concat(
47-
var.use_encryption_from_oci_vault ? local.allow_oke_use_oci_vault_keys_statements : []
47+
local.allow_oke_use_oci_vault_keys_statements
4848
)
4949
kms_user_group_compartment_statements = concat(
5050
local.allow_group_manage_vault_keys_statements
@@ -76,6 +76,8 @@ locals {
7676

7777
# Conditional locals
7878
locals {
79-
app_dynamic_group = var.create_dynamic_group_for_nodes_in_compartment ? oci_identity_dynamic_group.app_dynamic_group.0.name : "void"
80-
app_name_normalized = var.app_details.app_name_normalized
79+
app_dynamic_group = var.create_dynamic_group_for_nodes_in_compartment ? oci_identity_dynamic_group.app_dynamic_group.0.name : "void"
80+
app_name_normalized = substr(replace(lower(var.freeform_deployment_tags.AppName), " ", "-"), 0, 6)
81+
app_name = var.freeform_deployment_tags.AppName
82+
deploy_id = var.freeform_deployment_tags.DeploymentID
8183
}

modules/oci-vault-kms/variables.tf

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ variable "existent_encryption_key_id" {
1616
description = "Use an existent master encryption key to encrypt boot volume and object storage bucket. NOTE: If the key resides in a different compartment or in a different tenancy, make sure you have the proper policies to access, or the provision of the worker nodes will fail"
1717
}
1818

19-
# Deployment Details
20-
variable "app_details" {
21-
description = "App Details"
19+
# Deployment Details + Freeform Tags
20+
variable "freeform_deployment_tags" {
21+
description = "Tags to be added to the resources"
2222
}
2323

2424
# OKE Variables
@@ -38,7 +38,7 @@ variable "user_admin_group_for_vault_policy" {
3838
}
3939
## Create Dynamic Group and Policies
4040
variable "create_dynamic_group_for_nodes_in_compartment" {
41-
default = false
41+
default = false
4242
description = "Creates dynamic group of Nodes in the compartment. Note: You need to have proper rights on the Tenancy. If you only have rights in a compartment, uncheck and ask you administrator to create the Dynamic Group for you"
4343
}
4444
variable "create_compartment_policies" {
@@ -48,12 +48,3 @@ variable "create_compartment_policies" {
4848

4949
# OCI Provider
5050
variable "tenancy_ocid" {}
51-
52-
# Deployment Tags
53-
locals {
54-
freeform_deployment_tags = {
55-
"DeploymentID" = "${var.app_details.app_deployment_id}",
56-
"AppName" = "${var.app_details.app_name}",
57-
"Environment" = "${var.app_details.app_deployment_environment}",
58-
"DeploymentType" = "${var.app_details.app_deployment_type}" }
59-
}

0 commit comments

Comments
 (0)