Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 98e7fd6

Browse files
authored
feat: added the ability to scope attachments to a resource group using new input resource_groups_scope<br>* added the ability to set the attachment schedule using the new attachment_schedule input variable (#148)
1 parent 9352492 commit 98e7fd6

File tree

4 files changed

+91
-16
lines changed

4 files changed

+91
-16
lines changed

ibm_catalog.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@
232232
{
233233
"key": "profile_attachments"
234234
},
235+
{
236+
"key": "resource_groups_scope"
237+
},
238+
{
239+
"key": "attachment_schedule",
240+
"options": [
241+
{
242+
"displayname": "Daily",
243+
"value": "daily"
244+
},
245+
{
246+
"displayname": "Weekly",
247+
"value": "every_7_days"
248+
},
249+
{
250+
"displayname": "Monthly",
251+
"value": "every_30_days"
252+
},
253+
{
254+
"displayname": "Never",
255+
"value": "none"
256+
}
257+
]
258+
},
235259
{
236260
"key": "provision_scc_workload_protection"
237261
},

solutions/instances/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ This solution supports provisioning and configuring the following infrastructure
3939
| [ibm_en_topic.en_topic](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.67.1/docs/resources/en_topic) | resource |
4040
| [ibm_en_destinations.en_destinations](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.67.1/docs/data-sources/en_destinations) | data source |
4141
| [ibm_iam_account_settings.iam_account_settings](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.67.1/docs/data-sources/iam_account_settings) | data source |
42+
| [ibm_resource_group.group](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.67.1/docs/data-sources/resource_group) | data source |
4243
| [ibm_resource_instance.scc_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.67.1/docs/data-sources/resource_instance) | data source |
4344

4445
### Inputs
4546

4647
| Name | Description | Type | Default | Required |
4748
|------|-------------|------|---------|:--------:|
4849
| <a name="input_add_bucket_name_suffix"></a> [add\_bucket\_name\_suffix](#input\_add\_bucket\_name\_suffix) | Whether to add a generated 4-character suffix to the created Security and Compliance Center Object Storage bucket name. Applies only if not specifying an existing bucket. Set to `false` not to add the suffix to the bucket name in the `scc_cos_bucket_name` variable. | `bool` | `true` | no |
50+
| <a name="input_attachment_schedule"></a> [attachment\_schedule](#input\_attachment\_schedule) | The scanning schedule. Possible values: `daily`, `every_7_days`, `every_30_days`, `none`. | `string` | `"daily"` | no |
4951
| <a name="input_cos_instance_access_tags"></a> [cos\_instance\_access\_tags](#input\_cos\_instance\_access\_tags) | A list of access tags to apply to the Object Storage instance. Applies only if not specifying an existing instance. | `list(string)` | `[]` | no |
5052
| <a name="input_cos_instance_name"></a> [cos\_instance\_name](#input\_cos\_instance\_name) | The name for the Object Storage instance. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<name>` format. | `string` | `"base-security-services-cos"` | no |
5153
| <a name="input_cos_instance_tags"></a> [cos\_instance\_tags](#input\_cos\_instance\_tags) | The list of tags to add to the Object Storage instance. Applies only if not specifying an existing instance. | `list(string)` | `[]` | no |
@@ -65,6 +67,7 @@ This solution supports provisioning and configuring the following infrastructure
6567
| <a name="input_profile_attachments"></a> [profile\_attachments](#input\_profile\_attachments) | The list of Security and Compliance Center profile attachments to create that are scoped to your IBM Cloud account. The attachment schedule runs daily and defaults to the latest version of the specified profile attachments. | `list(string)` | <pre>[<br> "IBM Cloud Framework for Financial Services"<br>]</pre> | no |
6668
| <a name="input_provision_scc_workload_protection"></a> [provision\_scc\_workload\_protection](#input\_provision\_scc\_workload\_protection) | Whether to provision a Workload Protection instance. | `bool` | `true` | no |
6769
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of a new or an existing resource group in which to provision resources to. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<name>` format. | `string` | n/a | yes |
70+
| <a name="input_resource_groups_scope"></a> [resource\_groups\_scope](#input\_resource\_groups\_scope) | The resource group to associate with the Security and Compliance Center profile attachments. If not specified, the attachments are scoped to the current account ID. Only one resource group is allowed. | `list(string)` | `[]` | no |
6871
| <a name="input_scc_cos_bucket_access_tags"></a> [scc\_cos\_bucket\_access\_tags](#input\_scc\_cos\_bucket\_access\_tags) | The list of access tags to add to the Security and Compliance Center Object Storage bucket. | `list(string)` | `[]` | no |
6972
| <a name="input_scc_cos_bucket_class"></a> [scc\_cos\_bucket\_class](#input\_scc\_cos\_bucket\_class) | The storage class of the newly provisioned Security and Compliance Center Object Storage bucket. Possible values: `standard`, `vault`, `cold`, `smart`, `onerate_active`. [Learn more](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-classes). | `string` | `"smart"` | no |
7073
| <a name="input_scc_cos_bucket_name"></a> [scc\_cos\_bucket\_name](#input\_scc\_cos\_bucket\_name) | The name for the Security and Compliance Center Object Storage bucket. Bucket names must globally unique. If `add_bucket_name_suffix` is true, a 4-character string is added to this name to ensure it's globally unique. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<name>` format. | `string` | `"base-security-services-bucket"` | no |

solutions/instances/main.tf

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,47 @@ module "scc" {
171171
# SCC Attachment
172172
#######################################################################################################################
173173

174+
locals {
175+
resource_group_supplied = length(var.resource_groups_scope) == 1
176+
}
177+
178+
data "ibm_resource_group" "group" {
179+
count = local.resource_group_supplied ? 1 : 0
180+
name = var.resource_groups_scope[0]
181+
}
182+
183+
locals {
184+
account_scope = {
185+
environment = "ibm-cloud"
186+
properties = [
187+
{
188+
name = "scope_type"
189+
value = "account"
190+
},
191+
{
192+
name = "scope_id"
193+
value = data.ibm_iam_account_settings.iam_account_settings.account_id
194+
},
195+
]
196+
}
197+
198+
resource_group_scope = {
199+
environment = "ibm-cloud"
200+
properties = [
201+
{
202+
name = "scope_type"
203+
value = "account.resource_group"
204+
},
205+
{
206+
name = "scope_id"
207+
value = local.resource_group_supplied ? data.ibm_resource_group.group[0].id : null
208+
},
209+
]
210+
}
211+
212+
scope = local.resource_group_supplied ? [local.account_scope, local.resource_group_scope] : [local.account_scope]
213+
}
214+
174215
# Data source to account settings
175216
data "ibm_iam_account_settings" "iam_account_settings" {}
176217

@@ -186,22 +227,8 @@ module "create_profile_attachment" {
186227
scc_instance_id = local.scc_instance_guid
187228
attachment_name = "${each.value + 1} daily full account attachment"
188229
attachment_description = "SCC profile attachment scoped to your specific IBM Cloud account id ${data.ibm_iam_account_settings.iam_account_settings.account_id} with a daily attachment schedule."
189-
attachment_schedule = "daily"
190-
scope = [
191-
{
192-
environment = "ibm-cloud"
193-
properties = [
194-
{
195-
name = "scope_type"
196-
value = "account"
197-
},
198-
{
199-
name = "scope_id"
200-
value = data.ibm_iam_account_settings.iam_account_settings.account_id
201-
},
202-
]
203-
}
204-
]
230+
attachment_schedule = var.attachment_schedule
231+
scope = local.scope
205232
}
206233

207234
#######################################################################################################################

solutions/instances/variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,27 @@ variable "profile_attachments" {
226226
default = ["IBM Cloud Framework for Financial Services"]
227227
}
228228

229+
variable "resource_groups_scope" {
230+
type = list(string)
231+
description = "The resource group to associate with the Security and Compliance Center profile attachments. If not specified, the attachments are scoped to the current account ID. Only one resource group is allowed."
232+
default = []
233+
validation {
234+
condition = length(var.resource_groups_scope) <= 1
235+
error_message = "Only one resource group is allowed."
236+
}
237+
}
238+
239+
variable "attachment_schedule" {
240+
type = string
241+
description = "The scanning schedule. Possible values: `daily`, `every_7_days`, `every_30_days`, `none`."
242+
default = "daily"
243+
244+
validation {
245+
condition = contains(["daily", "every_7_days", "every_30_days", "none"], var.attachment_schedule)
246+
error_message = "You can set the schedule only to `daily`, `every_7_days`, `every_30_days`, or `none`."
247+
}
248+
}
249+
229250
########################################################################################################################
230251
# SCC Workload Protection variables
231252
########################################################################################################################

0 commit comments

Comments
 (0)