Skip to content

Commit 2a8f94c

Browse files
shemauSteve Peggs
andauthored
feat: tags support (#37)
* feat: tags support Add support for tags on cloud object storage and key protect instances Co-authored-by: Steve Peggs <peggs@uk.ibm.com>
1 parent 2163fa9 commit 2a8f94c

File tree

6 files changed

+86
-26
lines changed

6 files changed

+86
-26
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ You need the following permissions to run this module.
108108
| <a name="input_cos_key_ring_name"></a> [cos\_key\_ring\_name](#input\_cos\_key\_ring\_name) | A String containing the desired Key Ring Names as the key of the map for the key protect instance, this Key Protect Key is used to encrypt the data in the COS Bucket | `string` | `"cos-key-ring"` | no |
109109
| <a name="input_cos_location"></a> [cos\_location](#input\_cos\_location) | Location of the cloud object storage instance | `string` | `"global"` | no |
110110
| <a name="input_cos_plan"></a> [cos\_plan](#input\_cos\_plan) | Plan to be used for creating cloud object storage instance | `string` | `"standard"` | no |
111+
| <a name="input_cos_tags"></a> [cos\_tags](#input\_cos\_tags) | Optional list of tags to be added to cloud object storage instance. | `list(string)` | `[]` | no |
111112
| <a name="input_create_cos_instance"></a> [create\_cos\_instance](#input\_create\_cos\_instance) | Set as true to create a new Cloud Object Storage instance | `bool` | `true` | no |
112113
| <a name="input_create_key_protect_instance"></a> [create\_key\_protect\_instance](#input\_create\_key\_protect\_instance) | Set as true to create a new Key Protect instance, this instance will store the Key used to encrypt the data in the COS Bucket | `bool` | `true` | no |
113114
| <a name="input_create_key_protect_key"></a> [create\_key\_protect\_key](#input\_create\_key\_protect\_key) | Set as true to create a new Key Protect Key, this Key Protect Key is used to encrypt the COS Bucket | `bool` | `true` | no |
@@ -116,6 +117,7 @@ You need the following permissions to run this module.
116117
| <a name="input_expire_days"></a> [expire\_days](#input\_expire\_days) | Specifies the number of days when the expire rule action takes effect. | `number` | `365` | no |
117118
| <a name="input_key_protect_instance_name"></a> [key\_protect\_instance\_name](#input\_key\_protect\_instance\_name) | Name to set as the instance name if creating a Key Protect instance, otherwise name of an existing Key Protect instance to use, this instance will store the Key used to encrypt the data in the COS Bucket | `string` | `null` | no |
118119
| <a name="input_key_protect_key_crn"></a> [key\_protect\_key\_crn](#input\_key\_protect\_key\_crn) | CRN of the Key Protect Key to use if not creating a Key in this module, this Key Protect Key is used to encrypt the data in the COS Bucket | `string` | `null` | no |
120+
| <a name="input_key_protect_tags"></a> [key\_protect\_tags](#input\_key\_protect\_tags) | Optional list of tags to be added to Key Protect instance. | `list(string)` | `[]` | no |
119121
| <a name="input_object_versioning_enabled"></a> [object\_versioning\_enabled](#input\_object\_versioning\_enabled) | Enable object versioning to keep multiple versions of an object in a bucket. Cannot be used with retention rule. | `bool` | `false` | no |
120122
| <a name="input_region"></a> [region](#input\_region) | Name of the Region to deploy in to | `string` | `"us-south"` | no |
121123
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the environment will be created | `string` | n/a | yes |

examples/bucket-without-tracking-monitoring/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module "resource_group" {
66
}
77

88
# Create COS bucket with:
9-
# - Retention
109
# - Encryption
1110
# Create COS bucket without:
11+
# - Retention
1212
# - Monitoring
1313
# - Activity Tracking
1414

@@ -18,4 +18,6 @@ module "cos" {
1818
resource_group_id = module.resource_group.resource_group_id
1919
region = var.region
2020
encryption_enabled = true
21+
cos_tags = var.resource_tags
22+
retention_enabled = false
2123
}

examples/bucket-without-tracking-monitoring/variables.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ variable "resource_group" {
2828
default = null
2929
}
3030

31-
# tflint-ignore: terraform_unused_declarations
3231
variable "resource_tags" {
3332
type = list(string)
3433
description = "Optional list of tags to be added to created resources"
35-
default = []
34+
default = ["test-wo-mon"]
3635
}

main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module "kp_all_inclusive" {
4949
key_protect_instance_name = var.key_protect_instance_name == null ? "${var.environment_name}-kp" : var.key_protect_instance_name
5050
create_key_protect_instance = var.create_key_protect_instance
5151
key_map = local.key_map
52+
resource_tags = var.key_protect_tags
5253
}
5354

5455
# Resource to create COS instance if create_cos_instance is true
@@ -59,6 +60,7 @@ resource "ibm_resource_instance" "cos_instance" {
5960
service = "cloud-object-storage"
6061
plan = var.cos_plan
6162
location = var.cos_location
63+
tags = var.cos_tags
6264
}
6365

6466
locals {
@@ -91,6 +93,7 @@ resource "ibm_iam_authorization_policy" "policy" {
9193
# - Encryption
9294
# - Monitoring
9395
# - Activity Tracking
96+
# - Versioning
9497
resource "ibm_cos_bucket" "cos_bucket" {
9598
count = var.encryption_enabled ? 1 : 0
9699
depends_on = [ibm_iam_authorization_policy.policy]

module-metadata.json

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"default": 90,
1818
"pos": {
1919
"filename": "variables.tf",
20-
"line": 159
20+
"line": 171
2121
}
2222
},
2323
"archive_type": {
@@ -27,7 +27,7 @@
2727
"default": "Glacier",
2828
"pos": {
2929
"filename": "variables.tf",
30-
"line": 165
30+
"line": 177
3131
}
3232
},
3333
"bucket_infix": {
@@ -61,7 +61,7 @@
6161
],
6262
"pos": {
6363
"filename": "variables.tf",
64-
"line": 141
64+
"line": 153
6565
}
6666
},
6767
"cos_key_ring_name": {
@@ -71,7 +71,7 @@
7171
"default": "cos-key-ring",
7272
"pos": {
7373
"filename": "variables.tf",
74-
"line": 135
74+
"line": 147
7575
}
7676
},
7777
"cos_location": {
@@ -106,6 +106,26 @@
106106
"line": 53
107107
}
108108
},
109+
"cos_tags": {
110+
"name": "cos_tags",
111+
"type": "list(string)",
112+
"description": "Optional list of tags to be added to cloud object storage instance.",
113+
"default": [],
114+
"source": [
115+
"ibm_resource_instance.cos_instance.tags"
116+
],
117+
"pos": {
118+
"filename": "variables.tf",
119+
"line": 69
120+
},
121+
"min_length": 1,
122+
"max_length": 128,
123+
"matches": "^[A-Za-z0-9:_ .-]+$",
124+
"computed": true,
125+
"elem": {
126+
"type": "TypeString"
127+
}
128+
},
109129
"create_cos_instance": {
110130
"name": "create_cos_instance",
111131
"type": "bool",
@@ -131,7 +151,7 @@
131151
],
132152
"pos": {
133153
"filename": "variables.tf",
134-
"line": 123
154+
"line": 129
135155
}
136156
},
137157
"create_key_protect_key": {
@@ -141,7 +161,7 @@
141161
"default": true,
142162
"pos": {
143163
"filename": "variables.tf",
144-
"line": 147
164+
"line": 159
145165
}
146166
},
147167
"encryption_enabled": {
@@ -156,7 +176,7 @@
156176
],
157177
"pos": {
158178
"filename": "variables.tf",
159-
"line": 117
179+
"line": 123
160180
}
161181
},
162182
"environment_name": {
@@ -183,7 +203,7 @@
183203
"default": 365,
184204
"pos": {
185205
"filename": "variables.tf",
186-
"line": 175
206+
"line": 187
187207
}
188208
},
189209
"key_protect_instance_name": {
@@ -197,7 +217,7 @@
197217
],
198218
"pos": {
199219
"filename": "variables.tf",
200-
"line": 129
220+
"line": 135
201221
}
202222
},
203223
"key_protect_key_crn": {
@@ -206,7 +226,27 @@
206226
"description": "CRN of the Key Protect Key to use if not creating a Key in this module, this Key Protect Key is used to encrypt the data in the COS Bucket",
207227
"pos": {
208228
"filename": "variables.tf",
209-
"line": 153
229+
"line": 165
230+
}
231+
},
232+
"key_protect_tags": {
233+
"name": "key_protect_tags",
234+
"type": "list(string)",
235+
"description": "Optional list of tags to be added to Key Protect instance.",
236+
"default": [],
237+
"source": [
238+
"module.kp_all_inclusive.module.key_protect.ibm_resource_instance.key_protect_instance.tags"
239+
],
240+
"pos": {
241+
"filename": "variables.tf",
242+
"line": 141
243+
},
244+
"min_length": 1,
245+
"max_length": 128,
246+
"matches": "^[A-Za-z0-9:_ .-]+$",
247+
"computed": true,
248+
"elem": {
249+
"type": "TypeString"
210250
}
211251
},
212252
"object_versioning_enabled": {
@@ -216,7 +256,7 @@
216256
"default": false,
217257
"pos": {
218258
"filename": "variables.tf",
219-
"line": 111
259+
"line": 117
220260
}
221261
},
222262
"region": {
@@ -273,7 +313,7 @@
273313
"default": 90,
274314
"pos": {
275315
"filename": "variables.tf",
276-
"line": 75
316+
"line": 81
277317
}
278318
},
279319
"retention_enabled": {
@@ -283,7 +323,7 @@
283323
"default": true,
284324
"pos": {
285325
"filename": "variables.tf",
286-
"line": 69
326+
"line": 75
287327
}
288328
},
289329
"retention_maximum": {
@@ -293,7 +333,7 @@
293333
"default": 350,
294334
"pos": {
295335
"filename": "variables.tf",
296-
"line": 85
336+
"line": 91
297337
}
298338
},
299339
"retention_minimum": {
@@ -303,7 +343,7 @@
303343
"default": 90,
304344
"pos": {
305345
"filename": "variables.tf",
306-
"line": 95
346+
"line": 101
307347
}
308348
},
309349
"retention_permanent": {
@@ -313,7 +353,7 @@
313353
"default": false,
314354
"pos": {
315355
"filename": "variables.tf",
316-
"line": 105
356+
"line": 111
317357
}
318358
},
319359
"sysdig_crn": {
@@ -436,7 +476,7 @@
436476
},
437477
"pos": {
438478
"filename": "main.tf",
439-
"line": 94
479+
"line": 97
440480
}
441481
},
442482
"ibm_cos_bucket.cos_bucket1": {
@@ -453,7 +493,7 @@
453493
},
454494
"pos": {
455495
"filename": "main.tf",
456-
"line": 168
496+
"line": 171
457497
}
458498
},
459499
"ibm_iam_authorization_policy.policy": {
@@ -465,7 +505,7 @@
465505
},
466506
"pos": {
467507
"filename": "main.tf",
468-
"line": 80
508+
"line": 82
469509
}
470510
},
471511
"ibm_resource_instance.cos_instance": {
@@ -477,14 +517,15 @@
477517
"location": "cos_location",
478518
"name": "environment_name",
479519
"plan": "cos_plan",
480-
"resource_group_id": "resource_group_id"
520+
"resource_group_id": "resource_group_id",
521+
"tags": "cos_tags"
481522
},
482523
"provider": {
483524
"name": "ibm"
484525
},
485526
"pos": {
486527
"filename": "main.tf",
487-
"line": 55
528+
"line": 56
488529
}
489530
}
490531
},
@@ -504,7 +545,7 @@
504545
},
505546
"pos": {
506547
"filename": "main.tf",
507-
"line": 71
548+
"line": 73
508549
}
509550
}
510551
},
@@ -518,7 +559,8 @@
518559
"key_protect_instance_name": "key_protect_instance_name",
519560
"prefix": "environment_name",
520561
"region": "region",
521-
"resource_group_id": "resource_group_id"
562+
"resource_group_id": "resource_group_id",
563+
"resource_tags": "key_protect_tags"
522564
},
523565
"managed_resources": {},
524566
"data_resources": {

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ variable "cos_location" {
6666
default = "global"
6767
}
6868

69+
variable "cos_tags" {
70+
description = "Optional list of tags to be added to cloud object storage instance."
71+
type = list(string)
72+
default = []
73+
}
74+
6975
variable "retention_enabled" {
7076
description = "Retention enabled for COS bucket"
7177
type = bool
@@ -132,6 +138,12 @@ variable "key_protect_instance_name" {
132138
default = null
133139
}
134140

141+
variable "key_protect_tags" {
142+
description = "Optional list of tags to be added to Key Protect instance."
143+
type = list(string)
144+
default = []
145+
}
146+
135147
variable "cos_key_ring_name" {
136148
description = "A String containing the desired Key Ring Names as the key of the map for the key protect instance, this Key Protect Key is used to encrypt the data in the COS Bucket"
137149
type = string

0 commit comments

Comments
 (0)