Skip to content

Commit 6548954

Browse files
committed
chore: ensure the parameter store sharing is optional
1 parent f59a65b commit 6548954

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

modules/shared/parameters.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ locals {
88

99
## Provision the SSM parameter to store the JSON data
1010
resource "aws_ssm_parameter" "current" {
11+
count = var.enable_parameter_store ? 1 : 0
12+
1113
name = format("%s/%s/%s", var.parameter_store_prefix, var.vpc_id, var.name)
1214
description = "Used to share resource related tags with other accounts"
1315
type = "String"
@@ -18,29 +20,33 @@ resource "aws_ssm_parameter" "current" {
1820

1921
## Provision the RAM share to distribute the SSM parameter
2022
resource "aws_ram_resource_share" "ssm_parameter_share" {
23+
count = var.enable_parameter_store ? 1 : 0
24+
2125
allow_external_principals = false
2226
name = format("ssm-parameter-share-%s", var.name)
2327
tags = local.tags
2428
}
2529

2630
## Associate the Parameter Store value with the RAM resource share
2731
resource "aws_ram_resource_association" "ssm_parameter_association" {
28-
resource_share_arn = aws_ram_resource_share.ssm_parameter_share.arn
29-
resource_arn = aws_ssm_parameter.current.arn
32+
count = var.enable_parameter_store ? 1 : 0
33+
34+
resource_share_arn = aws_ram_resource_share.ssm_parameter_share[0].arn
35+
resource_arn = aws_ssm_parameter.current[0].arn
3036
}
3137

3238
## Associate the principals with the RAM share
3339
resource "aws_ram_principal_association" "ssm_parameter_accounts" {
34-
for_each = toset(var.share.accounts)
40+
for_each = var.enable_parameter_store ? toset(var.share.accounts) : toset([])
3541

3642
principal = each.value
37-
resource_share_arn = aws_ram_resource_share.this.arn
43+
resource_share_arn = aws_ram_resource_share.ssm_parameter_share[0].arn
3844
}
3945

4046
## Associate the principals with the RAM share
4147
resource "aws_ram_principal_association" "ssm_parameter_organizational_units" {
42-
for_each = toset(var.share.organizational_units)
48+
for_each = var.enable_parameter_store ? toset(var.share.organizational_units) : toset([])
4349

4450
principal = each.value
45-
resource_share_arn = aws_ram_resource_share.this.arn
51+
resource_share_arn = aws_ram_resource_share.ssm_parameter_share[0].arn
4652
}

modules/shared/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ variable "vpc_id" {
99
type = string
1010
}
1111

12+
variable "enable_parameter_store" {
13+
description = "Whether to share information via the SSM parameter store"
14+
type = bool
15+
default = true
16+
}
17+
1218
variable "share" {
1319
description = "The principals to share the provisioned subnets with"
1420
type = object({

0 commit comments

Comments
 (0)