You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: The KMS auth policy has been updated so its now scoped to the exact KMS key. If upgrading from an older version this will recreate the auth policy, however it will create the new one before destroying the old one so there is no disruption to every day services.<br> The kms_instance_guid input has been removed from the module. It is now programmticallty determined from the value of kms_key_crn<br>- A new boolean input is_hpcs_key has been added to the module and should be set to true if the key specified in kms_key_crn is from a Hyper Protect instance. Leave it at flase if using Key Protect. If set to true, a second auth policy is created which allows the Secrets Manager instance Viewer access to the HPCS instance. (#295)
|[ibm_resource_instance.sm_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/resource_instance)| data source |
93
96
94
97
### Inputs
@@ -100,8 +103,8 @@ You need the following permissions to run this module.
100
103
| <aname="input_enable_event_notification"></a> [enable\_event\_notification](#input\_enable\_event\_notification)| Set this to true to enable lifecycle notifications for your Secrets Manager instance by connecting an Event Notifications service. When setting this to true, a value must be passed for `existing_en_instance_crn` and `existing_sm_instance_crn` must be null. |`bool`|`false`| no |
101
104
| <aname="input_endpoint_type"></a> [endpoint\_type](#input\_endpoint\_type)| The type of endpoint (public or private) to connect to the Secrets Manager API. The Terraform provider uses this endpoint type to interact with the Secrets Manager API and configure Event Notifications. |`string`|`"public"`| no |
102
105
| <aname="input_existing_en_instance_crn"></a> [existing\_en\_instance\_crn](#input\_existing\_en\_instance\_crn)| The CRN of the Event Notifications service to enable lifecycle notifications for your Secrets Manager instance. |`string`|`null`| no |
103
-
| <aname="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid)| The GUID of the Hyper Protect Crypto Services or Key Protect instance in which the key specified in `kms_key_crn` is coming from. Required only if `kms_encryption_enabled` is set to true, and `skip_kms_iam_authorization_policy` is set to false. |`string`|`null`| no |
104
106
| <aname="input_existing_sm_instance_crn"></a> [existing\_sm\_instance\_crn](#input\_existing\_sm\_instance\_crn)| An existing Secrets Manager instance CRN. If not provided an new instance will be provisioned. |`string`|`null`| no |
107
+
| <aname="input_is_hpcs_key"></a> [is\_hpcs\_key](#input\_is\_hpcs\_key)| Set it to true if the key provided through the `kms_key_crn` is Hyper Protect Crypto Services key. |`bool`|`false`| no |
105
108
| <aname="input_kms_encryption_enabled"></a> [kms\_encryption\_enabled](#input\_kms\_encryption\_enabled)| Set this to true to control the encryption keys used to encrypt the data that you store in Secrets Manager. If set to false, the data that you store is encrypted at rest by using envelope encryption. For more details, see https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-mng-data&interface=ui#about-encryption.|`bool`|`false`| no |
106
109
| <aname="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn)| The root key CRN of a Key Management Service like Key Protect or Hyper Protect Crypto Services (HPCS) that you want to use for encryption. Only used if `kms_encryption_enabled` is set to true. |`string`|`null`| no |
107
110
| <aname="input_region"></a> [region](#input\_region)| The region where the resource will be provisioned.Its not required if passing a value for `existing_sm_instance_crn`. |`string`|`null`| no |
Copy file name to clipboardExpand all lines: main.tf
+82-17Lines changed: 82 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,19 @@
6
6
locals {
7
7
# Validation (approach based on https://github.com/hashicorp/terraform/issues/25609#issuecomment-1057614400)
8
8
# tflint-ignore: terraform_unused_declarations
9
-
validate_kms_values=(!var.kms_encryption_enabled&& var.kms_key_crn!=null&& var.existing_sm_instance_crn==null) ?tobool("When passing values for var.kms_key_crn, you must set 'kms_encryption_enabled' to true. Otherwise set 'kms_encryption_enabled' to false to use default encryption") :(!var.kms_encryption_enabled&& var.existing_kms_instance_guid!=null) ?tobool("When passing values for var.existing_kms_instance_guid, you must set var.kms_encryption_enabled to true. Otherwise unset them to use default encryption") :true
9
+
validate_kms_values=(!var.kms_encryption_enabled&& var.kms_key_crn!=null&& var.existing_sm_instance_crn==null) ?tobool("When passing values for var.kms_key_crn, you must set 'kms_encryption_enabled' to true. Otherwise set 'kms_encryption_enabled' to false to use default encryption") :true
10
10
# tflint-ignore: terraform_unused_declarations
11
11
validate_kms_vars=var.kms_encryption_enabled&& var.kms_key_crn==null&& var.existing_sm_instance_crn==null?tobool("When setting var.kms_encryption_enabled to true, a value must be passed for var.kms_key_crn") :true
12
12
# tflint-ignore: terraform_unused_declarations
13
-
validate_auth_policy=var.kms_encryption_enabled&& var.skip_kms_iam_authorization_policy==false&& var.existing_kms_instance_guid==null&& var.existing_sm_instance_crn==null?tobool("When var.skip_kms_iam_authorization_policy is set to false, and var.kms_encryption_enabled to true, a value must be passed for var.existing_kms_instance_guid in order to create the auth policy.") :true
13
+
validate_auth_policy=var.kms_encryption_enabled&& var.skip_kms_iam_authorization_policy==false&& var.kms_key_crn==null&& var.existing_sm_instance_crn==null?tobool("When var.skip_kms_iam_authorization_policy is set to false, and var.kms_encryption_enabled to true, a value must be passed for var.kms_key_crn in order to create the auth policy.") :true
14
14
# tflint-ignore: terraform_unused_declarations
15
15
validate_event_notification=var.enable_event_notification&& var.existing_en_instance_crn==null?tobool("When setting var.enable_event_notification to true, a value must be passed for var.existing_en_instance_crn") :true
16
16
# tflint-ignore: terraform_unused_declarations
17
17
validate_endpoint=var.endpoint_type=="public"&& var.allowed_network=="private-only"&& var.existing_sm_instance_crn==null?tobool("It is not allowed to have conflicting var.endpoint_type and var.allowed_network values.") :true
18
18
# tflint-ignore: terraform_unused_declarations
19
19
validate_region=var.existing_sm_instance_crn==null&& var.region==null?tobool("When existing_sm_instance_crn is null, a value must be passed for var.region") :true
20
+
# tflint-ignore: terraform_unused_declarations
21
+
validate_is_hpcs_key=var.is_hpcs_key&& local.kms_service_name!="hs-crypto"?tobool("When is_hpcs_key is set to true then the key provided through kms_key_crn must be a Hyper Protect Crypto Services key") :true
20
22
}
21
23
22
24
locals {
@@ -34,7 +36,7 @@ data "ibm_resource_instance" "sm_instance" {
description="Allows Secrets Manager instance ${local.secrets_manager_guid} `Groups Service Member Manage` access to the IAM Groups service to enable creating IAM credentials."
description="Allow all Secrets Manager instances in the resource group ${var.resource_group_id} to read from the ${local.kms_service_name} instance GUID ${var.existing_kms_instance_guid}"
102
+
count=local.create_kms_auth_policy?1:0
103
+
source_service_name="secrets-manager"
104
+
source_resource_group_id=var.resource_group_id
105
+
roles=["Reader"]
106
+
description="Allow all Secrets Manager instances in the resource group ${var.resource_group_id} to read the ${local.kms_service_name} key ${local.kms_key_id} from the instance GUID ${local.kms_instance_guid}."
107
+
resource_attributes {
108
+
name="serviceName"
109
+
operator="stringEquals"
110
+
value=local.kms_service_name
111
+
}
112
+
resource_attributes {
113
+
name="accountId"
114
+
operator="stringEquals"
115
+
value=local.kms_account_id
116
+
}
117
+
resource_attributes {
118
+
name="serviceInstance"
119
+
operator="stringEquals"
120
+
value=local.kms_instance_guid
121
+
}
122
+
resource_attributes {
123
+
name="resourceType"
124
+
operator="stringEquals"
125
+
value="key"
126
+
}
127
+
resource_attributes {
128
+
name="resource"
129
+
operator="stringEquals"
130
+
value=local.kms_key_id
131
+
}
132
+
# Scope of policy now includes the key, so ensure to create new policy before
133
+
# destroying old one to prevent any disruption to every day services.
134
+
lifecycle {
135
+
create_before_destroy=true
136
+
}
137
+
91
138
}
92
139
93
140
# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478
# if using HPCS ,create a second IAM authorization that assigns the Viewer platform access in Hyper Protect Crypto Services .[Learn more](https://cloud.ibm.com/docs/secrets-manager?topic=secrets-manager-mng-data#using-byok)
description="Allow all Secrets Manager instances in the resource group ${var.resource_group_id} viewer access to the ${local.kms_service_name} instance GUID ${local.kms_instance_guid}."
157
+
}
158
+
159
+
# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478
0 commit comments