Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[solve:issue-892]fix: split in two policy statements #893

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions migration.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ moved {
from = module.oke.oci_containerengine_node_pool.nodepools
to = module.workers[0].oci_containerengine_node_pool.workers
}

# IAM

moved {
from = module.iam.oci_identity_policy.cluster[0]
to = module.iam.oci_identity_policy.after_cluster[0]
}
2 changes: 1 addition & 1 deletion module-operator.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ locals {
}

module "operator" {
count = var.create_bastion && var.create_operator ? 1 : 0
count = var.create_operator ? 1 : 0
source = "./modules/operator"
state_id = local.state_id
compartment_id = local.compartment_id
Expand Down
3 changes: 2 additions & 1 deletion modules/iam/await.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "time_sleep" "await_iam_resources" {
count = anytrue([
local.has_policy_statements,
local.has_policy_statements_before_cluster,
local.has_policy_statements_after_cluster,
local.create_iam_tag_namespace,
]) ? 1 : 0
create_duration = "30s"
Expand Down
7 changes: 5 additions & 2 deletions modules/iam/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

output "dynamic_group_ids" {
description = "Cluster IAM dynamic group IDs"
value = local.has_policy_statements ? compact([
value = local.has_policy_statements_before_cluster || local.has_policy_statements_after_cluster ? compact([
one(oci_identity_dynamic_group.cluster[*].id),
one(oci_identity_dynamic_group.workers[*].id),
one(oci_identity_dynamic_group.autoscaling[*].id),
Expand All @@ -13,5 +13,8 @@ output "dynamic_group_ids" {

output "policy_statements" {
description = "Cluster IAM policy statements"
value = local.has_policy_statements ? local.policy_statements : null
value = local.has_policy_statements_before_cluster || local.has_policy_statements_after_cluster ? distinct(compact(flatten([
local.policy_statements_before_cluster,
local.policy_statements_after_cluster,
]))) : null
}
34 changes: 27 additions & 7 deletions modules/iam/policy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,48 @@
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl

locals {
policy_statements = distinct(compact(flatten([
policy_statements_before_cluster = distinct(compact(flatten([
local.cluster_policy_statements,
])))

has_policy_statements_before_cluster = var.create_iam_resources && anytrue([
var.create_iam_kms_policy,
])

policy_statements_after_cluster = distinct(compact(flatten([
local.worker_policy_statements,
local.operator_policy_statements,
local.autoscaler_policy_statements,
])))

has_policy_statements = var.create_iam_resources && anytrue([
has_policy_statements_after_cluster = var.create_iam_resources && anytrue([
var.create_iam_autoscaler_policy,
var.create_iam_kms_policy,
var.create_iam_operator_policy,
var.create_iam_worker_policy,
])
}

resource "oci_identity_policy" "cluster" {
resource "oci_identity_policy" "before_cluster" {
provider = oci.home
count = local.has_policy_statements_before_cluster ? 1 : 0
compartment_id = var.compartment_id
description = format("Policies for OKE Terraform state %v", var.state_id)
name = format("%s-before-cluster", local.cluster_group_name)
statements = local.policy_statements_before_cluster
defined_tags = local.defined_tags
freeform_tags = local.freeform_tags
lifecycle {
ignore_changes = [defined_tags, freeform_tags]
}
}

resource "oci_identity_policy" "after_cluster" {
provider = oci.home
count = local.has_policy_statements ? 1 : 0
count = local.has_policy_statements_after_cluster ? 1 : 0
compartment_id = var.compartment_id
description = format("Policies for OKE Terraform state %v", var.state_id)
name = local.cluster_group_name
statements = local.policy_statements
name = format("%s-after-cluster", local.cluster_group_name)
statements = local.policy_statements_after_cluster
defined_tags = local.defined_tags
freeform_tags = local.freeform_tags
lifecycle {
Expand Down