Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Commit f55d050

Browse files
kavya498hkantare
authored andcommitted
fix: update policy resource according to recent provider changes
1 parent 68b49d8 commit f55d050

File tree

7 files changed

+47
-27
lines changed

7 files changed

+47
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.terraform.lock.hcl
77
# Crash log files
88
crash.log
9+
.DS_Store
910
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
1011
# password, private keys, and other secrets. These should not be part of version
1112
# control as they are data points which are potentially sensitive and subject

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ default_stages: [commit]
55
# Terraform Fmt : Used to rewrite Terraform configuration files to a canonical format and style.
66
# Terraform Validate : Validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc
77
repos:
8-
- repo: git://github.com/antonbabenko/pre-commit-terraform
9-
rev: v1.45.0
8+
- repo: https://github.com/antonbabenko/pre-commit-terraform
9+
rev: v1.64.0
1010
hooks:
1111
- id: terraform_fmt
12-
- repo: git://github.com/pre-commit/pre-commit-hooks
13-
rev: v3.4.0
12+
- repo: https://github.com/pre-commit/pre-commit-hooks
13+
rev: v4.1.0
1414
hooks:
1515
- id: check-merge-conflict
1616
- id: trailing-whitespace

examples/kp-key/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
output "kms_key_id" {
66
value = module.kms_key.kms_key_id
77
}
8+
output "kms_key_status" {
9+
value = module.kms_key.kms_key_status
10+
}
811
output "kms_instance_id" {
912
value = module.kms_key.kms_instance_guid
1013
}

modules/key-protect/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ module "kms_key" {
4242
| encrypted_nonce | Encrypted Nonce. Only for imported root key. |`string`| n/a | no |
4343
| iv_value | IV Value. Only for imported root key. |`string`| n/a | no |
4444
| expiration_date | Expination Date. |`string`| n/a | no |
45-
| policies | Set policies for a key. |`list(map)`| n/a | no |
46-
47-
## policies Inputs
48-
49-
| Name | Description | Type |Default |Required |
50-
|--------------------------|-------------------------------------------------------|:-------|:--------|:--------|
5145
| rotation | Specifies the key rotation time interval in months |`map(string)`| n/a| Atleast one of rotation/dual_auth_delete|
5246
| dual_auth_delete | Data associated with the dual authorization delete policy.|`map(string)`| n/a | Atleast one of rotation/dual_auth_delete|
5347

@@ -78,6 +72,11 @@ Note:
7872

7973
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
8074

75+
~> NOTE:
76+
```
77+
The ability to use the ibm_kms_key resource to create or update key policies in Terraform has been removed in favor of a dedicated ibm_kms_key_policies resource.
78+
```
79+
8180
## NOTE: If we want to make use of a particular version of module, then set the argument "version" to respective module version
8281

8382
## Usage

modules/key-protect/main.tf

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ resource "ibm_kms_key" "key" {
3030
encrypted_nonce = (var.encrypted_nonce != null ? var.encrypted_nonce : null)
3131
iv_value = (var.iv_value != null ? var.iv_value : null)
3232
expiration_date = (var.expiration_date != null ? var.expiration_date : null)
33-
dynamic "policies" {
34-
for_each = length(keys(var.policies)) == 0 ? [] : [var.policies]
33+
}
3534

36-
content {
37-
dynamic "rotation" {
38-
for_each = length(keys(lookup(policies.value, "rotation", {}))) == 0 ? [] : [lookup(policies.value, "rotation", {})]
35+
resource "ibm_kms_key_policies" "key_policy" {
36+
count = length(keys(var.rotation)) != 0 ? 1 : length(keys(var.dual_auth_delete)) != 0 ? 1 : 0
37+
instance_id = var.is_kp_instance_exist != true ? ibm_resource_instance.kms_instance[0].guid : data.ibm_resource_instance.kms_instance[0].guid
38+
key_id = ibm_kms_key.key.key_id
39+
dynamic "rotation" {
40+
for_each = length(keys(var.rotation)) == 0 ? [] : [var.rotation]
3941

40-
content {
41-
interval_month = lookup(rotation.value, "interval_month", null)
42-
}
43-
}
44-
dynamic "dual_auth_delete" {
45-
for_each = length(keys(lookup(policies.value, "dual_auth_delete", {}))) == 0 ? [] : [lookup(policies.value, "dual_auth_delete", {})]
46-
content {
47-
enabled = lookup(dual_auth_delete.value, "enabled", null)
48-
}
49-
}
42+
content {
43+
interval_month = lookup(rotation.value, "interval_month", null)
5044
}
5145
}
46+
dynamic "dual_auth_delete" {
47+
for_each = length(keys(var.dual_auth_delete)) == 0 ? [] : [var.dual_auth_delete]
48+
content {
49+
enabled = lookup(dual_auth_delete.value, "enabled", null)
50+
}
51+
}
52+
5253
}

modules/key-protect/outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ output "kms_instance_guid" {
1313
}
1414
output "kms_instance_crn" {
1515
value = var.is_kp_instance_exist != true ? ibm_resource_instance.kms_instance[0].id : data.ibm_resource_instance.kms_instance[0].id
16+
}
17+
output "kms_key_status" {
18+
value = ibm_kms_key.key.resource_status
1619
}

modules/key-protect/variables.tf

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,21 @@ variable "expiration_date" {
8181
type = string
8282
default = null
8383
}
84-
variable "policies" {
85-
description = " Set policies for a key, such as an automatic rotation policy or a dual authorization policy."
84+
variable "rotation" {
85+
description = "Specifies the key rotation time interval in months. Atleast one of rotation/dual_auth_delete is required for policy creation."
8686
type = any
8787
default = {}
88+
# default = { // Example value
89+
# interval_month = 3
90+
# }
91+
8892
}
93+
variable "dual_auth_delete" {
94+
description = "Data associated with the dual authorization delete policy.Atleast one of rotation/dual_auth_delete is required for policy creation."
95+
type = any
96+
default = {}
97+
# default { // Example value
98+
# enabled = false
99+
# }
100+
}
101+

0 commit comments

Comments
 (0)