Skip to content

Commit bf849d0

Browse files
authored
fix: added variable validation to var.rotation_interval_month (#103)
1 parent f63ee1e commit bf849d0

File tree

12 files changed

+91
-84
lines changed

12 files changed

+91
-84
lines changed

.secrets.baseline

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2022-10-25T23:10:16Z",
6+
"generated_at": "2022-12-22T12:29:53Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -76,7 +76,18 @@
7676
"name": "TwilioKeyDetector"
7777
}
7878
],
79-
"results": {},
79+
"results": {
80+
"README.md": [
81+
{
82+
"hashed_secret": "ff9ee043d85595eb255c05dfe32ece02a53efbb2",
83+
"is_secret": false,
84+
"is_verified": false,
85+
"line_number": 16,
86+
"type": "Secret Keyword",
87+
"verified_result": null
88+
}
89+
]
90+
},
8091
"version": "0.13.1+ibm.55.dss",
8192
"word_list": {
8293
"file": null,

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
1-
<!-- BEGIN MODULE HOOK -->
2-
3-
<!-- Update the title to match the module name and add a description -->
41
# Key Protect key module
5-
<!-- UPDATE BADGE: Update the link for the following badge-->
2+
63
[![Stable (With quality checks)](https://img.shields.io/badge/Status-Stable%20(With%20quality%20checks)-green?style=plastic)](https://terraform-ibm-modules.github.io/documentation/#/badge-status)
74
[![Build status](https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key/actions/workflows/ci.yml/badge.svg)](https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key/actions/workflows/ci.yml)
85
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
96
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
107
[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-key-protect-key?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key/releases/latest)
8+
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
119

12-
This module creates a key in an existing key ring and Key Protect instance. You can specify rotation and deletion policies.
10+
This module supports creating a standard or root key in an existing key ring and Key Protect instance. You can specify rotation and deletion policies.
1311

1412
## Usage
1513

1614
```hcl
17-
##############################################################################
18-
# Key Protect Key
19-
##############################################################################
15+
provider "ibm" {
16+
ibmcloud_api_key = "XXXXXXXXXX"
17+
# Must be the same region the Key Protect instance is in
18+
region = "us-south"
19+
}
2020
21-
# Replace "main" with a GIT release version to lock into a specific release
22-
module "key_protect_key" {
21+
# Key Protect root key
22+
module "key_protect_root_key" {
23+
# Replace "main" with a GIT release version to lock into a specific release
2324
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key.git?ref=main"
24-
kms_instance_id = var.kms_instance_id
25-
key_name = var.key_name
26-
kms_key_ring_id = var.kms_key_ring_id
27-
standard_key = var.standard_key
28-
endpoint_type = var.endpoint_type
29-
rotation_interval_month = var.rotation_interval_month
30-
dual_auth_delete_enabled = var.dual_auth_delete_enabled
25+
key_protect_instance_id = ibm_resource_instance.key_protect_instance.guid
26+
key_name = "my-root-key"
3127
}
3228
29+
# Key Protect standard key
30+
module "key_protect_standard_key" {
31+
# Replace "main" with a GIT release version to lock into a specific release
32+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect-key.git?ref=main"
33+
key_protect_instance_id = ibm_resource_instance.key_protect_instance.guid
34+
key_name = "my-standard-key"
35+
standard_key = true
36+
}
3337
```
3438

3539
## Required IAM access policies
@@ -43,9 +47,6 @@ You need the following permissions to run this module.
4347
- `Viewer` platform access
4448
- `Manager` service access
4549

46-
For more information about the access you need to run all the GoldenEye modules, see [GoldenEye IAM permissions](https://github.ibm.com/GoldenEye/documentation/blob/master/goldeneye-iam-permissions.md).
47-
48-
<!-- END MODULE HOOK -->
4950
<!-- BEGIN EXAMPLES HOOK -->
5051
## Examples
5152

@@ -75,13 +76,13 @@ No modules.
7576

7677
| Name | Description | Type | Default | Required |
7778
|------|-------------|------|---------|:--------:|
78-
| <a name="input_dual_auth_delete_enabled"></a> [dual\_auth\_delete\_enabled](#input\_dual\_auth\_delete\_enabled) | Set as true to enable Dual Auth Delete | `bool` | `false` | no |
79+
| <a name="input_dual_auth_delete_enabled"></a> [dual\_auth\_delete\_enabled](#input\_dual\_auth\_delete\_enabled) | If set to true, Key Protect enables a dual authorization policy on a single key. Note: Once the dual authorization policy is set on the key, it cannot be reverted. A key with dual authorization policy enabled cannot be destroyed by using Terraform. | `bool` | `false` | no |
7980
| <a name="input_endpoint_type"></a> [endpoint\_type](#input\_endpoint\_type) | Endpoint to use when creating the Key | `string` | `"public"` | no |
8081
| <a name="input_force_delete"></a> [force\_delete](#input\_force\_delete) | Set as true to enable forcing deletion even if key is in use | `bool` | `false` | no |
8182
| <a name="input_key_name"></a> [key\_name](#input\_key\_name) | Name to give the key | `string` | n/a | yes |
82-
| <a name="input_key_protect_instance_id"></a> [key\_protect\_instance\_id](#input\_key\_protect\_instance\_id) | ID of Key Protect Instance | `string` | n/a | yes |
83-
| <a name="input_key_protect_key_ring_id"></a> [key\_protect\_key\_ring\_id](#input\_key\_protect\_key\_ring\_id) | ID of Key Ring where key is assigned | `string` | `"default"` | no |
84-
| <a name="input_rotation_interval_month"></a> [rotation\_interval\_month](#input\_rotation\_interval\_month) | Interval in months to rotate the Key | `number` | `1` | no |
83+
| <a name="input_key_protect_instance_id"></a> [key\_protect\_instance\_id](#input\_key\_protect\_instance\_id) | ID or GUID of Key Protect Instance | `string` | n/a | yes |
84+
| <a name="input_key_protect_key_ring_id"></a> [key\_protect\_key\_ring\_id](#input\_key\_protect\_key\_ring\_id) | The ID of the key ring where you want to add your Key Protect key | `string` | `"default"` | no |
85+
| <a name="input_rotation_interval_month"></a> [rotation\_interval\_month](#input\_rotation\_interval\_month) | The key rotation time interval in months. Rotation policy cannot be set for standard key, so value is ignored if var.standard\_key is true | `number` | `1` | no |
8586
| <a name="input_standard_key"></a> [standard\_key](#input\_standard\_key) | Set as true for Standard Key, false for Root Key | `bool` | `false` | no |
8687

8788
## Outputs

catalogValidationValues.json.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/default/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# End to end example with default values
22

33
An end-to-end example that uses the module's default variable values.
4-
This example uses the IBM Cloud terraform provider to:
5-
- Create a new resource group if one is not passed in.
6-
- Create a new Key Protect instance in the Resource Group.
4+
This example will:
5+
- Create a new resource group (if existing one is not passed in).
6+
- Create a new Key Protect instance in the region and resource group provided.
77
- Create a new Root Key in the Key Protect instance.
88
- Create a new Standard Key in the Key Protect instance.
9-
10-
<!-- Add your example and link to it from the module's main readme file. -->

examples/default/main.tf

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,35 @@ module "resource_group" {
1010
}
1111

1212
##############################################################################
13-
# Key Protect module
13+
# Key Protect instance
1414
##############################################################################
1515

16-
module "key_protect_module" {
17-
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-key-protect.git?ref=v1.2.0"
18-
key_protect_name = "${var.prefix}-key-protect"
16+
resource "ibm_resource_instance" "key_protect_instance" {
17+
name = "${var.prefix}-key-protect"
1918
resource_group_id = module.resource_group.resource_group_id
20-
region = var.region
19+
service = "kms"
20+
plan = "tiered-pricing"
21+
location = var.region
2122
tags = var.resource_tags
2223
}
2324

25+
##############################################################################
26+
# Key Protect root key
27+
##############################################################################
28+
2429
module "key_protect_root_key" {
2530
source = "../.."
26-
key_protect_instance_id = module.key_protect_module.key_protect_guid
31+
key_protect_instance_id = ibm_resource_instance.key_protect_instance.guid
2732
key_name = "${var.prefix}-root-key"
2833
}
2934

35+
##############################################################################
36+
# Key Protect standard key
37+
##############################################################################
38+
3039
module "key_protect_standard_key" {
3140
source = "../.."
32-
key_protect_instance_id = module.key_protect_module.key_protect_guid
41+
key_protect_instance_id = ibm_resource_instance.key_protect_instance.guid
3342
key_name = "${var.prefix}-standard-key"
3443
standard_key = true
3544
}

examples/default/outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
output "instance_id" {
66
description = "Key Protect Instance ID"
7-
value = module.key_protect_module.key_protect_guid
7+
value = ibm_resource_instance.key_protect_instance.id
8+
}
9+
10+
output "instance_guid" {
11+
description = "Key Protect Instance GUID"
12+
value = ibm_resource_instance.key_protect_instance.guid
813
}
914

1015
output "root_key_id" {

examples/default/provider.tf

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,3 @@ provider "ibm" {
22
ibmcloud_api_key = var.ibmcloud_api_key
33
region = var.region
44
}
5-
6-
data "ibm_iam_auth_token" "token_data" {
7-
}
8-
9-
provider "restapi" {
10-
uri = "https:"
11-
write_returns_object = false
12-
create_returns_object = false
13-
debug = false # set to true to show detailed logs, but use carefully as it might print sensitive values.
14-
headers = {
15-
Authorization = data.ibm_iam_auth_token.token_data.iam_access_token
16-
Bluemix-Instance = module.key_protect_module.key_protect_guid
17-
Content-Type = "application/vnd.ibm.kms.policy+json"
18-
}
19-
}

examples/default/version.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@ terraform {
66
source = "IBM-Cloud/ibm"
77
version = "1.48.0"
88
}
9-
restapi = {
10-
source = "Mastercard/restapi"
11-
version = "1.18.0"
12-
}
139
}
1410
}

module-metadata.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"dual_auth_delete_enabled": {
55
"name": "dual_auth_delete_enabled",
66
"type": "bool",
7-
"description": "Set as true to enable Dual Auth Delete",
7+
"description": "If set to true, Key Protect enables a dual authorization policy on a single key. Note: Once the dual authorization policy is set on the key, it cannot be reverted. A key with dual authorization policy enabled cannot be destroyed by using Terraform.",
88
"default": false,
99
"pos": {
1010
"filename": "variables.tf",
11-
"line": 44
11+
"line": 48
1212
}
1313
},
1414
"endpoint_type": {
@@ -38,7 +38,7 @@
3838
],
3939
"pos": {
4040
"filename": "variables.tf",
41-
"line": 50
41+
"line": 54
4242
}
4343
},
4444
"key_name": {
@@ -58,7 +58,7 @@
5858
"key_protect_instance_id": {
5959
"name": "key_protect_instance_id",
6060
"type": "string",
61-
"description": "ID of Key Protect Instance",
61+
"description": "ID or GUID of Key Protect Instance",
6262
"required": true,
6363
"source": [
6464
"ibm_kms_key.key.instance_id",
@@ -78,7 +78,7 @@
7878
"key_protect_key_ring_id": {
7979
"name": "key_protect_key_ring_id",
8080
"type": "string",
81-
"description": "ID of Key Ring where key is assigned",
81+
"description": "The ID of the key ring where you want to add your Key Protect key",
8282
"default": "default",
8383
"source": [
8484
"ibm_kms_key.key.key_ring_id"
@@ -92,7 +92,7 @@
9292
"rotation_interval_month": {
9393
"name": "rotation_interval_month",
9494
"type": "number",
95-
"description": "Interval in months to rotate the Key",
95+
"description": "The key rotation time interval in months. Rotation policy cannot be set for standard key, so value is ignored if var.standard_key is true",
9696
"default": 1,
9797
"pos": {
9898
"filename": "variables.tf",

tests/pr_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ import (
88
"github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper/testhelper"
99
)
1010

11+
// Use existing resource group for tests
1112
const resourceGroup = "geretain-test-key-protect-key"
12-
const defaultExampleTerraformDir = "examples/default"
13-
14-
func TestRunDefaultExample(t *testing.T) {
15-
t.Parallel()
13+
const terraformDir = "examples/default"
1614

15+
func setupOptions(t *testing.T, prefix string) *testhelper.TestOptions {
1716
options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
1817
Testing: t,
19-
TerraformDir: defaultExampleTerraformDir,
20-
Prefix: "kp-key",
18+
TerraformDir: terraformDir,
19+
Prefix: prefix,
2120
ResourceGroup: resourceGroup,
2221
})
2322

23+
return options
24+
}
25+
26+
func TestRunDefaultExample(t *testing.T) {
27+
t.Parallel()
28+
29+
options := setupOptions(t, "kp-key")
2430
output, err := options.RunTestConsistency()
2531
assert.Nil(t, err, "This should not have errored")
2632
assert.NotNil(t, output, "Expected some output")
2733
}
2834

29-
func TestRunUpgradeExample(t *testing.T) {
35+
func TestRunUpgrade(t *testing.T) {
3036
t.Parallel()
3137

32-
options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
33-
Testing: t,
34-
TerraformDir: defaultExampleTerraformDir,
35-
Prefix: "kp-key-upg",
36-
ResourceGroup: resourceGroup,
37-
})
38-
38+
options := setupOptions(t, "kp-key-upg")
3939
output, err := options.RunTestUpgrade()
4040
if !options.UpgradeTestSkipped {
4141
assert.Nil(t, err, "This should not have errored")

0 commit comments

Comments
 (0)