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

Commit 79a2ba6

Browse files
authored
fix: do not create COS auth policy if passing existing SCC instance (#167)
1 parent f36ffb9 commit 79a2ba6

File tree

8 files changed

+19
-7
lines changed

8 files changed

+19
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ You need the following permissions to run this module.
107107
| <a name="input_region"></a> [region](#input\_region) | Region where SCC instance will be created | `string` | `"us-south"` | no |
108108
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The id of the resource group to create the SCC instance | `string` | n/a | yes |
109109
| <a name="input_resource_tags"></a> [resource\_tags](#input\_resource\_tags) | A list of tags applied to the resources created by the module | `list(string)` | `[]` | no |
110-
| <a name="input_skip_cos_iam_authorization_policy"></a> [skip\_cos\_iam\_authorization\_policy](#input\_skip\_cos\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits the SCC instance created by this module to write access to the provided COS instance | `bool` | `false` | no |
110+
| <a name="input_skip_cos_iam_authorization_policy"></a> [skip\_cos\_iam\_authorization\_policy](#input\_skip\_cos\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits the SCC instance created by this module to write access to the provided COS instance. This value will get ignored if an existing SCC instance is passed. | `bool` | `false` | no |
111111
| <a name="input_skip_scc_wp_auth_policy"></a> [skip\_scc\_wp\_auth\_policy](#input\_skip\_scc\_wp\_auth\_policy) | Set to true to skip the creation of an IAM authorization policy that permits the SCC instance created by this solution read access to the workload protection instance. Only used if `attach_wp_to_scc_instance` is set to true. | `bool` | `false` | no |
112112
| <a name="input_wp_instance_crn"></a> [wp\_instance\_crn](#input\_wp\_instance\_crn) | Optionally pass the CRN of an existing SCC Workload Protection instance to attach it to the SCC instance. | `string` | `null` | no |
113113

examples/complete/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module "resource_group" {
1414
##############################################################################
1515

1616
module "cos" {
17+
count = var.existing_scc_instance_crn == null ? 1 : 0
1718
source = "terraform-ibm-modules/cos/ibm"
1819
version = "8.11.15"
1920
cos_instance_name = "${var.prefix}-cos"
@@ -51,6 +52,7 @@ module "scc_wp" {
5152
resource_tags = var.resource_tags
5253
}
5354

55+
5456
##############################################################################
5557
# SCC instance
5658
##############################################################################
@@ -63,8 +65,8 @@ module "create_scc_instance" {
6365
resource_tags = var.resource_tags
6466
existing_scc_instance_crn = var.existing_scc_instance_crn
6567
access_tags = var.access_tags
66-
cos_bucket = module.cos.bucket_name
67-
cos_instance_crn = module.cos.cos_instance_id
68+
cos_bucket = var.existing_scc_instance_crn == null ? module.cos[0].bucket_name : null
69+
cos_instance_crn = var.existing_scc_instance_crn == null ? module.cos[0].cos_instance_id : null
6870
en_instance_crn = module.event_notification.crn
6971
skip_cos_iam_authorization_policy = false
7072
attach_wp_to_scc_instance = true

examples/complete/moved.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
moved {
2+
from = module.cos
3+
to = module.cos[0]
4+
}

examples/complete/outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ output "en_crn" {
4444

4545
output "cos_instance_id" {
4646
description = "The COS instance ID created in this example"
47-
value = module.cos.cos_instance_id
47+
value = var.existing_scc_instance_crn == null ? module.cos[0].cos_instance_id : null
4848
}
4949

5050
output "cos_bucket" {
5151
description = "The COS bucket created in this example"
52-
value = module.cos.bucket_name
52+
value = var.existing_scc_instance_crn == null ? module.cos[0].bucket_name : null
5353
depends_on = [module.create_scc_instance]
5454
}
5555

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ locals {
4949
}
5050

5151
resource "ibm_iam_authorization_policy" "scc_cos_s2s_access" {
52-
count = var.skip_cos_iam_authorization_policy ? 0 : 1
52+
count = var.existing_scc_instance_crn != null || var.skip_cos_iam_authorization_policy ? 0 : 1
5353
source_service_name = "compliance"
5454
source_resource_instance_id = local.scc_instance_guid
5555
roles = ["Writer"]

tests/existing-resources/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ output "resource_group_id" {
77
value = module.resource_group.resource_group_id
88
}
99

10+
output "prefix" {
11+
description = "Prefix to append to all resources created by this example"
12+
value = var.prefix
13+
}
14+
1015
output "resource_group_name" {
1116
description = "The name of the resource group where SCC instance is created by this module"
1217
value = module.resource_group.resource_group_name

tests/pr_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func TestRunExistingResourcesInstances(t *testing.T) {
153153
"region": region,
154154
"resource_group": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
155155
"existing_scc_instance_crn": terraform.Output(t, existingTerraformOptions, "crn"),
156+
"prefix": terraform.Output(t, existingTerraformOptions, "prefix"),
156157
},
157158
})
158159

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ variable "en_instance_crn" {
8888
variable "skip_cos_iam_authorization_policy" {
8989
type = bool
9090
default = false
91-
description = "Set to true to skip the creation of an IAM authorization policy that permits the SCC instance created by this module to write access to the provided COS instance"
91+
description = "Set to true to skip the creation of an IAM authorization policy that permits the SCC instance created by this module to write access to the provided COS instance. This value will get ignored if an existing SCC instance is passed."
9292
}
9393

9494
variable "skip_scc_wp_auth_policy" {

0 commit comments

Comments
 (0)