Skip to content

Commit e5d4806

Browse files
authored
feat: Added new input skip_iam_authorization_policy which defaults to false, meaning by default the module will now create the IAM authorization policies required to enable the IAM credentials engine by creating policies that grants the Secrets Manager instance 'Operator' access to the IAM identity service, and 'Groups Service Member Manage' access to the IAM groups service (#237)
1 parent 9249319 commit e5d4806

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ You need the following permissions to run this module.
8383
| Name | Type |
8484
|------|------|
8585
| [ibm_iam_authorization_policy.en_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
86+
| [ibm_iam_authorization_policy.iam_groups_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
87+
| [ibm_iam_authorization_policy.iam_identity_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8688
| [ibm_iam_authorization_policy.kms_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
8789
| [ibm_resource_instance.secrets_manager_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/resource_instance) | resource |
8890
| [ibm_sm_en_registration.sm_en_registration](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/sm_en_registration) | resource |
@@ -107,7 +109,8 @@ You need the following permissions to run this module.
107109
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Secret Manager secrets configurations. | <pre>list(object({<br/> secret_group_name = string<br/> secret_group_description = optional(string)<br/> existing_secret_group = optional(bool, false)<br/> secrets = optional(list(object({<br/> secret_name = string<br/> secret_description = optional(string)<br/> secret_type = optional(string)<br/> imported_cert_certificate = optional(string)<br/> imported_cert_private_key = optional(string)<br/> imported_cert_intermediate = optional(string)<br/> secret_username = optional(string)<br/> secret_labels = optional(list(string), [])<br/> secret_payload_password = optional(string, "")<br/> secret_auto_rotation = optional(bool, true)<br/> secret_auto_rotation_unit = optional(string, "day")<br/> secret_auto_rotation_interval = optional(number, 89)<br/> service_credentials_ttl = optional(string, "7776000") # 90 days<br/> service_credentials_source_service_crn = optional(string)<br/> service_credentials_source_service_role_crn = optional(string)<br/> })))<br/> }))</pre> | `[]` | no |
108110
| <a name="input_secrets_manager_name"></a> [secrets\_manager\_name](#input\_secrets\_manager\_name) | The name of the Secrets Manager instance to create | `string` | n/a | yes |
109111
| <a name="input_skip_en_iam_authorization_policy"></a> [skip\_en\_iam\_authorization\_policy](#input\_skip\_en\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits all Secrets Manager instances (scoped to the resource group) an 'Event Source Manager' role to the given Event Notifications instance passed in the `existing_en_instance_crn` input variable. In addition, no policy is created if `enable_event_notification` is set to false. | `bool` | `false` | no |
110-
| <a name="input_skip_kms_iam_authorization_policy"></a> [skip\_kms\_iam\_authorization\_policy](#input\_skip\_kms\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits all Secrets Manager instances in the resource group to read the encryption key from the KMS instance. If set to false, pass in a value for the KMS instance in the `existing_kms_instance_guid` variable. In addition, no policy is created if `kms_encryption_enabled` is set to false. | `bool` | `false` | no |
112+
| <a name="input_skip_iam_authorization_policy"></a> [skip\_iam\_authorization\_policy](#input\_skip\_iam\_authorization\_policy) | Whether to skip the creation of the IAM authorization policies required to enable the IAM credentials engine. If set to false, policies will be created that grants the Secrets Manager instance 'Operator' access to the IAM identity service, and 'Groups Service Member Manage' access to the IAM groups service. | `bool` | `false` | no |
113+
| <a name="input_skip_kms_iam_authorization_policy"></a> [skip\_kms\_iam\_authorization\_policy](#input\_skip\_kms\_iam\_authorization\_policy) | Whether to skip the creation of the IAM authorization policies required to enable the IAM credentials engine. If set to false, policies will be created that grants the Secrets Manager instance 'Operator' access to the IAM identity service, and 'Groups Service Member Manage' access to the IAM groups service. | `bool` | `false` | no |
111114
| <a name="input_sm_service_plan"></a> [sm\_service\_plan](#input\_sm\_service\_plan) | The Secrets Manager plan to provision. | `string` | `"standard"` | no |
112115
| <a name="input_sm_tags"></a> [sm\_tags](#input\_sm\_tags) | The list of resource tags that you want to associate with your Secrets Manager instance. | `list(string)` | `[]` | no |
113116

main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ resource "ibm_resource_instance" "secrets_manager_instance" {
5252
}
5353
}
5454

55+
# Create IAM credentials engine using s2s auth
56+
resource "ibm_iam_authorization_policy" "iam_identity_policy" {
57+
count = var.skip_iam_authorization_policy ? 0 : 1
58+
source_service_name = "secrets-manager"
59+
source_resource_instance_id = local.secrets_manager_guid
60+
target_service_name = "iam-identity"
61+
roles = ["Operator"]
62+
description = "Allows Secrets Manager instance ${local.secrets_manager_guid} `Operator` access to the IAM Identity service to enable creating IAM credentials."
63+
}
64+
65+
resource "ibm_iam_authorization_policy" "iam_groups_policy" {
66+
count = var.skip_iam_authorization_policy ? 0 : 1
67+
source_service_name = "secrets-manager"
68+
source_resource_instance_id = local.secrets_manager_guid
69+
target_service_name = "iam-groups"
70+
roles = ["Groups Service Member Manage"]
71+
description = "Allows Secrets Manager instance ${local.secrets_manager_guid} `Groups Service Member Manage` access to the IAM Groups service to enable creating IAM credentials."
72+
}
73+
5574
locals {
5675
# determine which service name to use for the policy
5776
kms_service_name = var.kms_encryption_enabled && var.kms_key_crn != null ? (

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ variable "sm_service_plan" {
2727
}
2828
}
2929

30+
variable "skip_iam_authorization_policy" {
31+
type = bool
32+
description = "Whether to skip the creation of the IAM authorization policies required to enable the IAM credentials engine. If set to false, policies will be created that grants the Secrets Manager instance 'Operator' access to the IAM identity service, and 'Groups Service Member Manage' access to the IAM groups service."
33+
default = false
34+
}
35+
3036
variable "sm_tags" {
3137
type = list(string)
3238
description = "The list of resource tags that you want to associate with your Secrets Manager instance."
@@ -51,7 +57,7 @@ variable "kms_encryption_enabled" {
5157

5258
variable "skip_kms_iam_authorization_policy" {
5359
type = bool
54-
description = "Set to true to skip the creation of an IAM authorization policy that permits all Secrets Manager instances in the resource group to read the encryption key from the KMS instance. If set to false, pass in a value for the KMS instance in the `existing_kms_instance_guid` variable. In addition, no policy is created if `kms_encryption_enabled` is set to false."
60+
description = "Whether to skip the creation of the IAM authorization policies required to enable the IAM credentials engine. If set to false, policies will be created that grants the Secrets Manager instance 'Operator' access to the IAM identity service, and 'Groups Service Member Manage' access to the IAM groups service."
5561
default = false
5662
}
5763

0 commit comments

Comments
 (0)