Skip to content

Commit 9dce5c7

Browse files
committed
issue #85 added additional checks to prevent locals in policies module looking up a dynamic group when instance_principal is not created and
use_encryption=false and updated terraform.tfvars.example to remove unused bastion parameters' Signed-off-by: Ali Mukadam <[email protected]>
1 parent 8c9b5da commit 9dce5c7

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

modules/base/bastion/datasources.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ data "oci_core_instance" "bastion" {
6666
#Required
6767
instance_id = oci_core_instance.bastion[0].id
6868
count = var.oci_bastion.create_bastion == true ? 1 : 0
69-
}
69+
}

modules/base/bastion/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ output "bastion_public_ip" {
66
}
77

88
output "bastion_instance_principal_group_name" {
9-
value = oci_identity_dynamic_group.bastion_instance_principal[0].name
10-
}
9+
value = (var.oci_bastion.enable_instance_principal == true) ? oci_identity_dynamic_group.bastion_instance_principal[0].name : null
10+
}

modules/policies/groups.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ resource "oci_identity_dynamic_group" "oke-kms-cluster" {
66
compartment_id = var.oci_identity.tenancy_id
77
description = "dynamic group to allow cluster to use kms"
88
matching_rule = local.dynamic_group_rule_all_clusters
9-
name = "${var.label_prefix}-oke-kms-cluster"
10-
count = var.oke_kms.use_encryption == true ? 1 : 0
9+
name = "${var.label_prefix}-oke-kms-cluster"
10+
count = (var.oke_kms.use_encryption == true) ? 1 : 0
1111

1212
lifecycle {
1313
ignore_changes = [matching_rule]
@@ -24,7 +24,7 @@ data "template_file" "update_dynamic_group_script" {
2424

2525
depends_on = ["oci_identity_dynamic_group.oke-kms-cluster"]
2626

27-
count = var.oke_kms.use_encryption == true && var.bastion.create_bastion == true && var.bastion.enable_instance_principal == true ? 1 : 0
27+
count = (var.oke_kms.use_encryption == true && var.bastion.create_bastion == true && var.bastion.enable_instance_principal == true) ? 1 : 0
2828
}
2929

3030
resource null_resource "update_dynamic_group" {
@@ -55,5 +55,5 @@ resource null_resource "update_dynamic_group" {
5555
]
5656
}
5757

58-
count = var.oke_kms.use_encryption == true && var.bastion.create_bastion == true && var.bastion.enable_instance_principal == true ? 1 : 0
58+
count = (var.oke_kms.use_encryption == true && var.bastion.create_bastion == true && var.bastion.enable_instance_principal == true) ? 1 : 0
5959
}

modules/policies/locals.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl
33

44
locals {
5-
6-
dynamic_group_rule_all_clusters = "ALL {resource.type = 'cluster', resource.compartment.id = '${var.oci_identity.compartment_id}'}"
7-
8-
dynamic_group_rule_this_cluster = "ALL {resource.type = 'cluster', resource.id = '${var.cluster_id}'}"
95

10-
policy_statement = "Allow dynamic-group ${oci_identity_dynamic_group.oke-kms-cluster[0].name} to use keys in compartment ${var.oci_identity.compartment_name} where target.key.id = '${var.oke_kms.key_id}'"
6+
dynamic_group_rule_all_clusters = (var.oke_kms.use_encryption == true) ? "ALL {resource.type = 'cluster', resource.compartment.id = '${var.oci_identity.compartment_id}'}" : null
117

12-
}
8+
dynamic_group_rule_this_cluster = (var.oke_kms.use_encryption == true) ? "ALL {resource.type = 'cluster', resource.id = '${var.cluster_id}'}" : null
9+
10+
policy_statement = (var.oke_kms.use_encryption == true) ? "Allow dynamic-group ${oci_identity_dynamic_group.oke-kms-cluster[0].name} to use keys in compartment ${var.oci_identity.compartment_name} where target.key.id = '${var.oke_kms.key_id}'" : ""
11+
12+
}

modules/policies/policies.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ resource "oci_identity_policy" "bastion_instance_principal_dynamic_group" {
77
description = "policy to allow bastion host to manage dynamic group"
88
name = "${var.label_prefix}-bastion-instance-principal-dynamic-group"
99
statements = ["Allow dynamic-group ${var.dynamic_group} to use dynamic-groups in tenancy"]
10-
count = var.oke_kms.use_encryption == true ? 1 : 0
10+
count = (var.oke_kms.use_encryption == true && var.bastion.create_bastion == true && var.bastion.enable_instance_principal == true) ? 1 : 0
1111
}
1212

1313
resource "oci_identity_policy" "oke-kms" {
@@ -16,5 +16,5 @@ resource "oci_identity_policy" "oke-kms" {
1616
description = "policy to allow instances to allow dynamic group ${var.label_prefix}-oke-kms-cluster to use kms"
1717
name = "${var.label_prefix}-oke-kms"
1818
statements = [local.policy_statement]
19-
count = var.oke_kms.use_encryption == true ? 1 : 0
19+
count = (var.oke_kms.use_encryption == true) ? 1 : 0
2020
}

terraform.tfvars.example

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,13 @@ bastion_access = "ANYWHERE"
6565

6666
enable_instance_principal = false
6767

68-
image_operating_system = "Oracle Linux"
69-
70-
image_operating_system_version = "7.7"
71-
7268
# availability_domains
7369

7470
# which AD where to place non-OKE resources
7571
availability_domains = {
7672
"bastion" = 1
7773
}
7874

79-
bastion_package_update = false
80-
8175
bastion_package_upgrade = true
8276

8377
# oke

0 commit comments

Comments
 (0)