Skip to content

Commit 6288ad7

Browse files
feat: added a new buckets submodule which supports creating multiple buckets (#265)
1 parent f921f5a commit 6288ad7

32 files changed

+760
-507
lines changed

.secrets.baseline

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2023-05-05T07:44:09Z",
6+
"generated_at": "2023-07-11T14:04:13Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
1010
},
1111
{
1212
"name": "ArtifactoryDetector"
1313
},
14+
{
15+
"name": "AzureStorageKeyDetector"
16+
},
1417
{
1518
"base64_limit": 4.5,
1619
"name": "Base64HighEntropyString"
@@ -28,6 +31,9 @@
2831
"ghe_instance": "github.ibm.com",
2932
"name": "GheDetector"
3033
},
34+
{
35+
"name": "GitHubTokenDetector"
36+
},
3137
{
3238
"hex_limit": 3,
3339
"name": "HexHighEntropyString"
@@ -48,6 +54,9 @@
4854
{
4955
"name": "MailchimpDetector"
5056
},
57+
{
58+
"name": "NpmDetector"
59+
},
5160
{
5261
"name": "PrivateKeyDetector"
5362
},
@@ -57,6 +66,9 @@
5766
{
5867
"name": "SoftlayerDetector"
5968
},
69+
{
70+
"name": "SquareOAuthDetector"
71+
},
6072
{
6173
"name": "StripeDetector"
6274
},
@@ -65,7 +77,7 @@
6577
}
6678
],
6779
"results": {},
68-
"version": "0.13.1+ibm.60.dss",
80+
"version": "0.13.1+ibm.61.dss",
6981
"word_list": {
7082
"file": null,
7183
"hash": null

README.md

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-cos?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-cos/releases/latest)
88
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
99

10-
You can use this module to provision and configure an [IBM Cloud Object Storage](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-getting-started-cloud-object-storage) instance or bucket.
10+
You can use this module to provision and configure a [Cloud Object Storage](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-getting-started-cloud-object-storage) instance and bucket.
1111

1212
You can configure the following aspects of your instances:
13-
1413
- [Bucket encryption](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-tutorial-kp-encrypt-bucket) - based on Key Protect keys
1514
- [Activity tracking](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-tracking-cos-events) and auditing
1615
- [Monitoring](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-monitoring-cos)
17-
- Data retention, [lifecycle](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-archive), and archiving options
16+
- Data retention, [lifecycle](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-archive) and archiving options
1817

1918
## Usage
2019

@@ -26,31 +25,72 @@ provider "ibm" {
2625
2726
# Creates:
2827
# - COS instance
29-
# - COS bucket with retention, encryption, monitoring and activity tracking
28+
# - COS buckets with retention, encryption, monitoring and activity tracking
3029
module "cos_module" {
31-
source = "terraform-ibm-modules/cos/ibm"
32-
version = "latest" # Replace "latest" with a release version to lock into a specific release
33-
resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX"
34-
region = "us-south"
35-
cos_instance_name = "my-cos-instance"
36-
bucket_name = "my-cos-bucket"
30+
source = "terraform-ibm-modules/cos/ibm"
31+
version = "latest" # Replace "latest" with a release version to lock into a specific release
32+
resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX"
33+
region = "us-south"
34+
cos_instance_name = "my-cos-instance"
35+
bucket_name = "my-cos-bucket"
3736
existing_kms_instance_guid = "xxxxxxxx-XXXX-XXXX-XXXX-xxxxxxxx"
3837
kms_key_crn = "crn:v1:bluemix:public:kms:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxxxxx-XXXX-XXXX-XXXX-xxxxxx:key:xxxxxx-XXXX-XXXX-XXXX-xxxxxx"
3938
sysdig_crn = "crn:v1:bluemix:public:sysdig-monitor:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX::"
4039
activity_tracker_crn = "crn:v1:bluemix:public:logdnaat:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX::"
4140
}
4241
43-
# Creates additional bucket in instance created above:
42+
# Creates additional buckets in existing instance:
4443
module "additional_cos_bucket" {
45-
source = "terraform-ibm-modules/cos/ibm"
44+
source = "terraform-ibm-modules/cos/ibm"
45+
version = "latest" # Replace "latest" with a release version to lock into a specific release
46+
resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX"
47+
region = "us-south"
48+
create_cos_instance = false
49+
sysdig_crn = "crn:v1:bluemix:public:sysdig-monitor:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX::"
50+
activity_tracker_crn = "crn:v1:bluemix:public:logdnaat:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX::"
51+
existing_cos_instance_id = module.cos_module.cos_instance_id
52+
kms_key_crn = "crn:v1:bluemix:public:kms:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxxxxx-XXXX-XXXX-XXXX-xxxxxx:key:xxxxxx-XXXX-XXXX-XXXX-xxxxxx"
53+
}
54+
55+
# Creates additional Cloud Object Storage buckets using the buckets sub module
56+
module "cos_buckets" {
57+
source = "terraform-ibm-modules/cos/ibm//modules/buckets"
4658
version = "latest" # Replace "latest" with a release version to lock into a specific release
47-
bucket_name = "additional-bucket"
48-
resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX"
49-
region = "us-south"
50-
sysdig_crn = "crn:v1:bluemix:public:sysdig-monitor:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX::"
51-
activity_tracker_crn = "crn:v1:bluemix:public:logdnaat:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX::"
52-
existing_cos_instance_id = module.cos_module.cos_instance_id
53-
kms_key_crn = "crn:v1:bluemix:public:kms:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxxxxx-XXXX-XXXX-XXXX-xxxxxx:key:xxxxxx-XXXX-XXXX-XXXX-xxxxxx"
59+
bucket_configs = [
60+
{
61+
bucket_name = "my-encrypted-bucket"
62+
kms_key_crn = "crn:v1:bluemix:public:kms:us-south:a/xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX:xxxxxx-XXXX-XXXX-XXXX-xxxxxx:key:xxxxxx-XXXX-XXXX-XXXX-xxxxxx"
63+
region_location = "us-south"
64+
resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX"
65+
resource_instance_id = module.cos_module.cos_instance_id
66+
},
67+
{
68+
bucket_name = "my-versioned-bucket"
69+
kms_encryption_enabled = false
70+
region_location = "us-south"
71+
resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX"
72+
resource_instance_id = module.cos_module.cos_instance_id
73+
object_versioning = {
74+
enable = true
75+
}
76+
},
77+
{
78+
bucket_name = "my-archive-bucket"
79+
kms_encryption_enabled = false
80+
region_location = "us-south"
81+
resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX"
82+
resource_instance_id = module.cos_module.cos_instance_id
83+
archive_rule = {
84+
days = 90
85+
enable = true
86+
type = "Accelerated"
87+
}
88+
expire_rule = {
89+
days = 90
90+
enable = true
91+
}
92+
}
93+
]
5494
}
5595
```
5696

@@ -86,7 +126,7 @@ You need the following permissions to run this module.
86126

87127
- [ Basic Example](examples/basic)
88128
- [ Complete Example (multiple COS Buckets with retention, encryption, tracking and monitoring enabled)](examples/complete)
89-
- [ COS Bucket without encryption using an existing COS instance and Key Protect instance + Keys](examples/existing-resources)
129+
- [ Create Cloud Object Storage instance and a bucket](examples/existing-resources)
90130
- [ Financial Services Cloud Profile example](examples/fscloud)
91131
- [ One Rate Plan Example (COS Bucket with One Rate Plan)](examples/one-rate-plan)
92132
- [ Cloud Object Storage replication example](examples/replication)
@@ -141,13 +181,13 @@ You need the following permissions to run this module.
141181
| <a name="input_create_hmac_key"></a> [create\_hmac\_key](#input\_create\_hmac\_key) | Set as true to create a new HMAC key for the Cloud Object Storage instance. | `bool` | `true` | no |
142182
| <a name="input_cross_region_location"></a> [cross\_region\_location](#input\_cross\_region\_location) | Specify the cross-regional bucket location. Supported values are 'us', 'eu', and 'ap'. If you pass a value for this, ensure to set the value of var.region to null. | `string` | `null` | no |
143183
| <a name="input_existing_cos_instance_id"></a> [existing\_cos\_instance\_id](#input\_existing\_cos\_instance\_id) | The ID of an existing cloud object storage instance. Required if 'var.create\_cos\_instance' is false. | `string` | `null` | no |
144-
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Key Protect or Hyper Protect instance in which the key specified in var.kms\_key\_crn is coming from. Required if var.skip\_iam\_authorization\_policy is false in order to create an IAM Access Policy to allow Key protect or Hyper Protect to access the newly created COS instance. | `string` | `null` | no |
184+
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Key Protect or Hyper Protect instance in which the key specified in var.kms\_key\_crn is coming from. Required if var.skip\_iam\_authorization\_policy is false in order to create an IAM Access Policy to allow Key Protect or Hyper Protect to access the newly created COS instance. | `string` | `null` | no |
145185
| <a name="input_expire_days"></a> [expire\_days](#input\_expire\_days) | Specifies the number of days when the expire rule action takes effect. Only used if 'create\_cos\_bucket' is true. | `number` | `365` | no |
146186
| <a name="input_hmac_key_name"></a> [hmac\_key\_name](#input\_hmac\_key\_name) | The name of the hmac key to be created. | `string` | `"hmac-cos-key"` | no |
147187
| <a name="input_hmac_key_role"></a> [hmac\_key\_role](#input\_hmac\_key\_role) | The role you want to be associated with your new hmac key. Valid roles are 'Writer', 'Reader', 'Manager', 'Content Reader', 'Object Reader', 'Object Writer'. | `string` | `"Manager"` | no |
148188
| <a name="input_instance_cbr_rules"></a> [instance\_cbr\_rules](#input\_instance\_cbr\_rules) | (Optional, list) List of CBR rules to create for the instance | <pre>list(object({<br> description = string<br> account_id = string<br> rule_contexts = list(object({<br> attributes = optional(list(object({<br> name = string<br> value = string<br> }))) }))<br> enforcement_mode = string<br> tags = optional(list(object({<br> name = string<br> value = string<br> })), [])<br> operations = optional(list(object({<br> api_types = list(object({<br> api_type_id = string<br> }))<br> })))<br> }))</pre> | `[]` | no |
149189
| <a name="input_kms_encryption_enabled"></a> [kms\_encryption\_enabled](#input\_kms\_encryption\_enabled) | Set as true to use KMS key encryption to encrypt data in COS bucket (only applicable when var.create\_cos\_bucket is true). | `bool` | `true` | no |
150-
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | CRN of the KMS Key to use to encrypt the data in the COS Bucket. Required if var.encryption\_enabled and var.create\_cos\_bucket are true. | `string` | `null` | no |
190+
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | CRN of the KMS key to use to encrypt the data in the COS bucket. Required if var.encryption\_enabled and var.create\_cos\_bucket are true. | `string` | `null` | no |
151191
| <a name="input_management_endpoint_type_for_bucket"></a> [management\_endpoint\_type\_for\_bucket](#input\_management\_endpoint\_type\_for\_bucket) | The type of endpoint for the IBM terraform provider to use to manage the bucket. (public, private, direct) | `string` | `"public"` | no |
152192
| <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. Only used if 'create\_cos\_bucket' is true. | `bool` | `false` | no |
153193
| <a name="input_region"></a> [region](#input\_region) | The region to provision the bucket. If you pass a value for this, do not pass one for var.cross\_region\_location. | `string` | `"us-south"` | no |
@@ -167,11 +207,11 @@ You need the following permissions to run this module.
167207
|------|-------------|
168208
| <a name="output_bucket_crn"></a> [bucket\_crn](#output\_bucket\_crn) | Bucket CRN |
169209
| <a name="output_bucket_id"></a> [bucket\_id](#output\_bucket\_id) | Bucket id |
170-
| <a name="output_bucket_name"></a> [bucket\_name](#output\_bucket\_name) | Bucket Name |
210+
| <a name="output_bucket_name"></a> [bucket\_name](#output\_bucket\_name) | Bucket name |
171211
| <a name="output_bucket_storage_class"></a> [bucket\_storage\_class](#output\_bucket\_storage\_class) | Bucket Storage Class |
172212
| <a name="output_cos_instance_guid"></a> [cos\_instance\_guid](#output\_cos\_instance\_guid) | The GUID of the Cloud Object Storage Instance where the buckets are created |
173213
| <a name="output_cos_instance_id"></a> [cos\_instance\_id](#output\_cos\_instance\_id) | The ID of the Cloud Object Storage Instance where the buckets are created |
174-
| <a name="output_kms_key_crn"></a> [kms\_key\_crn](#output\_kms\_key\_crn) | The CRN of the KMS Key used to encrypt the COS Bucket |
214+
| <a name="output_kms_key_crn"></a> [kms\_key\_crn](#output\_kms\_key\_crn) | The CRN of the KMS key used to encrypt the COS bucket |
175215
| <a name="output_resource_group_id"></a> [resource\_group\_id](#output\_resource\_group\_id) | Resource Group ID |
176216
| <a name="output_s3_endpoint_direct"></a> [s3\_endpoint\_direct](#output\_s3\_endpoint\_direct) | S3 direct endpoint |
177217
| <a name="output_s3_endpoint_private"></a> [s3\_endpoint\_private](#output\_s3\_endpoint\_private) | S3 private endpoint |

common-dev-assets

Submodule common-dev-assets updated 56 files

examples/basic/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Basic Example
22

3-
An example that will:
4-
- Create a new resource group (if existing one is not passed in).
5-
- Create a new Cloud Object Storage instance and a bucket.
3+
This example creates the following infrastructure:
4+
- A new resource group, if one is not passed in.
5+
- A new Cloud Object Storage instance and a bucket in a resource group and region.

examples/basic/main.tf

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ module "resource_group" {
1111
}
1212

1313
##############################################################################
14-
# Create COS
14+
# Create Cloud Object Storage instance and a bucket
1515
##############################################################################
1616

17-
module "cos_bucket" {
17+
module "cos" {
1818
source = "../../"
1919
resource_group_id = module.resource_group.resource_group_id
2020
region = var.region
@@ -25,3 +25,20 @@ module "cos_bucket" {
2525
retention_enabled = false
2626
kms_encryption_enabled = false
2727
}
28+
29+
##############################################################################
30+
# Create Cloud Object Storage bucket using sub module
31+
##############################################################################
32+
33+
module "buckets" {
34+
source = "../../modules/buckets"
35+
bucket_configs = [
36+
{
37+
bucket_name = "${var.prefix}-bucket-module"
38+
kms_encryption_enabled = false
39+
region_location = var.region
40+
resource_group_id = module.resource_group.resource_group_id
41+
resource_instance_id = module.cos.cos_instance_id
42+
}
43+
]
44+
}

examples/basic/outputs.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
output "bucket_name" {
2-
description = "Bucket Name"
3-
value = module.cos_bucket.bucket_name
2+
description = "Bucket name"
3+
value = module.cos.bucket_name
44
}
55

66
output "bucket_crn" {
77
description = "Bucket CRN"
8-
value = module.cos_bucket.bucket_crn
8+
value = module.cos.bucket_crn
99
}
1010

1111
output "bucket_id" {
1212
description = "Bucket id"
13-
value = module.cos_bucket.bucket_id
13+
value = module.cos.bucket_id
14+
}
15+
16+
output "buckets" {
17+
description = "Bucket from sub module"
18+
value = module.buckets.buckets
1419
}

examples/complete/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Complete Example (multiple COS Buckets with retention, encryption, tracking and monitoring enabled)
22

3-
An end-to-end example that will:
4-
- Create a new resource group (if existing one is not passed in).
5-
- Create Sysdig and Activity Tracker instances in the given resource group and region.
6-
- Create a new Key Protect instance (with metrics enabled), Key Ring, and Key in the given resource group and region.
7-
- Create a new Cloud Object Storage instance in the given resource group and region.
8-
- Create an IAM Access Policy to allow Key Protect to access COS instance.
9-
- Create COS bucket-1 with:
3+
This example creates the following infrastructure:
4+
- A new resource group, if one is not passed in.
5+
- A Sysdig and Activity Tracker instances in a resource group and region.
6+
- A new Key Protect instance (with metrics enabled), Key Ring, and Key in a resource group and region.
7+
- A new Cloud Object Storage instance in a resource group and region.
8+
- An IAM Access Policy to allow Key Protect to access COS instance.
9+
- COS bucket-1 with:
1010
- Encryption
1111
- Monitoring
1212
- Activity Tracking
13-
- Create COS bucket-2 with:
13+
- COS bucket-2 with:
1414
- Cross Region Location
1515
- Encryption
1616
- Monitoring
1717
- Activity Tracking
18-
- Create a Sample VPC.
19-
- Create Context Based Restriction(CBR) to only allow buckets to be accessible from the VPC.
18+
- A sample VPC.
19+
- A Context Based Restriction(CBR) to only allow buckets to be accessible from the VPC.

examples/complete/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module "cbr_zone" {
103103
}]
104104
}
105105

106-
# Create COS instance and Key protect instance.
106+
# Create COS instance and Key Protect instance.
107107
# Create COS bucket-1 with:
108108
# - Encryption
109109
# - Monitoring

examples/complete/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
output "bucket_name1" {
2-
description = "Bucket Name"
2+
description = "Bucket name"
33
value = module.cos_bucket1.bucket_name
44
}
55

66
output "bucket_name2" {
7-
description = "Bucket Name"
7+
description = "Bucket name"
88
value = module.cos_bucket2.bucket_name
99
}

examples/existing-resources/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# COS Bucket without encryption using an existing COS instance and Key Protect instance + Keys
1+
# Create Cloud Object Storage instance and a bucket
22

3-
An end-to-end example that will:
4-
- Create a new resource group (if existing one is not passed in).
5-
- Create a new Key Protect instance, Key Ring, and Key in the given resource group and region.
6-
- Using the terraform-ibm-cos module, create a new Cloud Object Storage instance in the given resource group and region (with no buckets).
7-
- Create an IAM Access Policy to allow Key Protect to access COS instance (outside of the terraform-ibm-cos module).
8-
- Using the terraform-ibm-cos module, create a COS Bucket without encryption using the existing COS instance, Key Protect instance + Keys created at the start of this example.
3+
This example creates the following infrastructure:
4+
- A new resource group, if one is not passed in.
5+
- A Key Protect instance, key ring, and key in a resource group and region.
6+
- An IAM access policy to allow Cloud Object Storage to access Key Protect for the encryption key.
7+
- A Cloud Object Storage instance with no buckets in a resource group and region.
8+
This example uses the code in the root `terraform-ibm-cos` module.
9+
- Cloud Object Storage buckets with encryption, versioning and archiving respectively.

0 commit comments

Comments
 (0)