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

Commit 9352492

Browse files
authored
feat: added support to use existing SCC instance using new input variable existing_scc_instance_crn (#138)
1 parent adf483e commit 9352492

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

solutions/instances/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ 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_instance.scc_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/1.67.1/docs/data-sources/resource_instance) | data source |
4243

4344
### Inputs
4445

@@ -56,6 +57,7 @@ This solution supports provisioning and configuring the following infrastructure
5657
| <a name="input_existing_monitoring_crn"></a> [existing\_monitoring\_crn](#input\_existing\_monitoring\_crn) | The CRN of an IBM Cloud Monitoring instance to to send Security and Compliance Object Storage bucket metrics to, as well as Workload Protection data. If no value passed, metrics are sent to the instance associated to the container's location unless otherwise specified in the Metrics Router service configuration. Ignored if using existing Object Storage bucket and not provisioning Workload Protection. | `string` | `null` | no |
5758
| <a name="input_existing_scc_cos_bucket_name"></a> [existing\_scc\_cos\_bucket\_name](#input\_existing\_scc\_cos\_bucket\_name) | The name of an existing bucket inside the existing Object Storage instance to use for Security and Compliance Center. If not specified, a bucket is created. | `string` | `null` | no |
5859
| <a name="input_existing_scc_cos_kms_key_crn"></a> [existing\_scc\_cos\_kms\_key\_crn](#input\_existing\_scc\_cos\_kms\_key\_crn) | The CRN of an existing KMS key to use to encrypt the Security and Compliance Center Object Storage bucket. If no value is set for this variable, specify a value for either the `existing_kms_instance_crn` variable to create a key ring and key, or for the `existing_scc_cos_bucket_name` variable to use an existing bucket. | `string` | `null` | no |
60+
| <a name="input_existing_scc_instance_crn"></a> [existing\_scc\_instance\_crn](#input\_existing\_scc\_instance\_crn) | The CRN of an existing Security and Compliance Center instance. If not supplied, a new instance will be created. | `string` | `null` | no |
5961
| <a name="input_ibmcloud_api_key"></a> [ibmcloud\_api\_key](#input\_ibmcloud\_api\_key) | The IBM Cloud API key to deploy resources. | `string` | n/a | yes |
6062
| <a name="input_kms_endpoint_type"></a> [kms\_endpoint\_type](#input\_kms\_endpoint\_type) | The endpoint for communicating with the KMS instance. Possible values: `public`, `private.` | `string` | `"private"` | no |
6163
| <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 Object Storage buckets. Possible values: `public`, `private`m `direct`. If you specify `private`, enable virtual routing and forwarding in your account, and the Terraform runtime must have access to the the IBM Cloud private network. | `string` | `"private"` | no |

solutions/instances/main.tf

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,33 @@ module "cos" {
128128
# SCC Instance
129129
#######################################################################################################################
130130

131+
locals {
132+
parsed_existing_scc_instance_crn = var.existing_scc_instance_crn != null ? split(":", var.existing_scc_instance_crn) : []
133+
existing_scc_instance_guid = length(local.parsed_existing_scc_instance_crn) > 0 ? local.parsed_existing_scc_instance_crn[7] : null
134+
existing_scc_instance_region = length(local.parsed_existing_scc_instance_crn) > 0 ? local.parsed_existing_scc_instance_crn[5] : null
135+
136+
scc_instance_crn = var.existing_scc_instance_crn == null ? module.scc[0].crn : var.existing_scc_instance_crn
137+
scc_instance_guid = var.existing_scc_instance_crn == null ? module.scc[0].guid : local.existing_scc_instance_guid
138+
scc_instance_region = var.existing_scc_instance_crn == null ? var.scc_region : local.existing_scc_instance_region
139+
140+
}
141+
142+
moved {
143+
from = module.scc
144+
to = module.scc[0]
145+
}
146+
147+
data "ibm_resource_instance" "scc_instance" {
148+
count = var.existing_scc_instance_crn == null ? 0 : 1
149+
identifier = local.scc_instance_guid
150+
}
151+
131152
module "scc" {
153+
count = var.existing_scc_instance_crn == null ? 1 : 0
132154
source = "terraform-ibm-modules/scc/ibm"
133155
version = "1.6.3"
134156
resource_group_id = module.resource_group.resource_group_id
135-
region = var.scc_region
157+
region = local.scc_instance_region
136158
instance_name = local.scc_instance_name
137159
plan = var.scc_service_plan
138160
cos_bucket = local.cos_bucket_name
@@ -161,7 +183,7 @@ module "create_profile_attachment" {
161183
}
162184
profile_name = each.key
163185
profile_version = "latest"
164-
scc_instance_id = module.scc.guid
186+
scc_instance_id = local.scc_instance_guid
165187
attachment_name = "${each.value + 1} daily full account attachment"
166188
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."
167189
attachment_schedule = "daily"
@@ -221,7 +243,7 @@ resource "ibm_en_topic" "en_topic" {
221243
name = "SCC Topic"
222244
description = "Topic for SCC events routing"
223245
sources {
224-
id = module.scc.crn
246+
id = local.scc_instance_crn
225247
rules {
226248
enabled = true
227249
event_type_filter = "$.*"

solutions/instances/outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ output "resource_group_id" {
1414

1515
output "scc_id" {
1616
description = "SCC instance ID"
17-
value = module.scc.id
17+
value = var.existing_scc_instance_crn == null ? module.scc[0].id : var.existing_scc_instance_crn
1818
}
1919

2020
output "scc_guid" {
2121
description = "SCC instance guid"
22-
value = module.scc.guid
22+
value = var.existing_scc_instance_crn == null ? module.scc[0].guid : local.existing_scc_instance_guid
2323
}
2424

2525
output "scc_crn" {
2626
description = "SCC instance CRN"
27-
value = module.scc.crn
27+
value = var.existing_scc_instance_crn == null ? module.scc[0].crn : var.existing_scc_instance_crn
2828
}
2929

3030
output "scc_name" {
3131
description = "SCC instance name"
32-
value = module.scc.name
32+
value = var.existing_scc_instance_crn == null ? module.scc[0].name : data.ibm_resource_instance.scc_instance[0].name
3333
}
3434

3535
output "scc_workload_protection_id" {

solutions/instances/provider.tf

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

55
provider "ibm" {
66
ibmcloud_api_key = var.ibmcloud_api_key
7-
region = var.scc_region
7+
region = local.scc_instance_region
88
}
99

1010
provider "ibm" {

solutions/instances/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ variable "existing_activity_tracker_crn" {
167167
# SCC variables
168168
########################################################################################################################
169169

170+
variable "existing_scc_instance_crn" {
171+
type = string
172+
default = null
173+
description = "The CRN of an existing Security and Compliance Center instance. If not supplied, a new instance will be created."
174+
}
175+
170176
variable "scc_instance_name" {
171177
type = string
172178
default = "base-security-services-scc"

0 commit comments

Comments
 (0)