Skip to content

Commit 841cbbd

Browse files
feat: add parsed account ID field of the CRN (#18)
1 parent 3b7b2ac commit 841cbbd

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

examples/crn-parser/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ output "parsed_crn_resource" {
3636
value = module.crn_parser.resource
3737
description = "The parsed `resource` field of the Key Protect instance CRN"
3838
}
39+
40+
output "parsed_crn_account_id" {
41+
value = module.crn_parser.account_id
42+
description = "The parsed Account ID from the `scope` field of the Key Protect instance CRN"
43+
}

modules/crn-parser/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ No resources.
4242

4343
| Name | Description |
4444
|------|-------------|
45+
| <a name="output_account_id"></a> [account\_id](#output\_account\_id) | Account ID parsed from the CRN `scope` field |
4546
| <a name="output_ctype"></a> [ctype](#output\_ctype) | CRN `ctype` field |
4647
| <a name="output_region"></a> [region](#output\_region) | CRN `region` field |
4748
| <a name="output_resource"></a> [resource](#output\_resource) | CRN `resource` field |

modules/crn-parser/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ locals {
1111
service_instance = length(local.split_crn) > 7 ? local.split_crn[7] : null
1212
resource_type = length(local.split_crn) > 8 ? local.split_crn[8] : null
1313
resource = length(local.split_crn) > 9 ? local.split_crn[9] : null
14+
account_id = length(local.split_crn) > 6 ? (length(regexall("^a\\/.+$", local.split_crn[6])) > 0 ? split("/", local.split_crn[6])[1] : null) : null
1415
}

modules/crn-parser/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ output "resource" {
3636
value = local.resource == "" ? null : local.resource
3737
description = "CRN `resource` field"
3838
}
39+
40+
output "account_id" {
41+
value = local.account_id == "" ? null : local.account_id
42+
description = "Account ID parsed from the CRN `scope` field"
43+
}

tests/pr_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestRunCRNParserExample(t *testing.T) {
2323

2424
options := setupOptions(t, crnParserExample)
2525
options.TerraformVars = map[string]interface{}{
26-
"crn": "crn:version:cname:ctype:service-name:location:scope:service-instance:resource-type:resource",
26+
"crn": "crn:version:cname:ctype:service-name:location:a/scope:service-instance:resource-type:resource",
2727
}
2828

2929
output, err := options.RunTestConsistency()

0 commit comments

Comments
 (0)