|
1 | | -# Copyright 2017, 2021 Oracle Corporation and/or affiliates. All rights reserved. |
| 1 | +# Copyright (c) 2022, Oracle Corporation and/or affiliates. All rights reserved. |
2 | 2 | # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl |
3 | 3 |
|
4 | | -resource "oci_identity_dynamic_group" "enable_operator_instance_principal" { |
| 4 | +resource "random_id" "dynamic_group_suffix" { |
| 5 | + keepers = { |
| 6 | + # Generate a new suffix only when variables are changed |
| 7 | + label_prefix = local.dynamic_group_prefix |
| 8 | + tenancy_id = var.tenancy_id |
| 9 | + } |
| 10 | + |
| 11 | + byte_length = 8 |
| 12 | +} |
| 13 | + |
| 14 | +resource "oci_identity_dynamic_group" "operator_group" { |
5 | 15 | provider = oci.home |
6 | 16 |
|
7 | | - compartment_id = var.tenancy_id |
8 | | - description = var.label_prefix == "none" ? "dynamic group to allow operator instance to invoke services" : "dynamic group with label ${var.label_prefix} to allow operator to invoke services" |
| 17 | + compartment_id = random_id.dynamic_group_suffix.keepers.tenancy_id |
| 18 | + description = "dynamic group %{ if var.label_prefix != "none" }with label ${var.label_prefix}%{ endif } to allow operator to invoke services" |
9 | 19 |
|
10 | 20 | lifecycle { |
11 | | - ignore_changes = [name, defined_tags] |
| 21 | + ignore_changes = [defined_tags] |
12 | 22 | } |
13 | 23 |
|
14 | 24 | matching_rule = "ALL {instance.id = '${join(",", data.oci_core_instance.operator.*.id)}'}" |
15 | | - name = "operator-instance-principal-${substr(uuid(), 0, 8)}" |
| 25 | + name = join("-", compact([ |
| 26 | + random_id.dynamic_group_suffix.keepers.label_prefix, |
| 27 | + "operator-instance-principal", |
| 28 | + random_id.dynamic_group_suffix.hex |
| 29 | + ])) |
16 | 30 |
|
17 | 31 | count = var.enable_operator_instance_principal == true ? 1 : 0 |
18 | 32 | } |
19 | 33 |
|
20 | | -resource "oci_identity_policy" "enable_operator_instance_principal" { |
| 34 | +resource "oci_identity_policy" "operator_group_policy" { |
21 | 35 | provider = oci.home |
22 | 36 |
|
23 | 37 | compartment_id = var.compartment_id |
24 | 38 | description = "policy to allow operator host to call services" |
25 | | - name = var.label_prefix == "none" ? "operator-instance-principal" : "${var.label_prefix}-operator-instance-principal" |
26 | | - statements = ["Allow dynamic-group ${oci_identity_dynamic_group.enable_operator_instance_principal[0].name} to manage all-resources in compartment id ${var.compartment_id}"] |
| 39 | + name = join("-", compact([ local.dynamic_group_prefix, "operator-instance-principal" ])) |
| 40 | + statements = ["Allow dynamic-group ${oci_identity_dynamic_group.operator_group[0].name} to manage all-resources in compartment id ${var.compartment_id}"] |
27 | 41 |
|
28 | 42 | count = var.enable_operator_instance_principal == true ? 1 : 0 |
29 | 43 | } |
0 commit comments