Skip to content

Commit 2e1128e

Browse files
committed
feat: added the sharing of resource tagging information
1 parent 0cf74af commit 2e1128e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

modules/shared/parameters.tf

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
locals {
3+
## A map of the subnets and their tagging
4+
subnet_map = merge({
5+
for k, v in aws_subnet.subnets : v.id => v.tags
6+
})
7+
}
8+
9+
## Provision the SSM parameter to store the JSON data
10+
resource "aws_ssm_parameter" "current" {
11+
name = format("%s/%s/%s", var.parameter_store_prefix, var.vpc_id, var.name)
12+
description = "Used to share resource related tags with other accounts"
13+
type = "String"
14+
value = jsonencode(local.subnet_map)
15+
tags = local.tags
16+
}
17+
18+
## Provision the RAM share to distribute the SSM parameter
19+
resource "aws_ram_resource_share" "ssm_parameter_share" {
20+
allow_external_principals = false
21+
name = format("ssm-parameter-share-%s", var.name)
22+
tags = local.tags
23+
}
24+
25+
## Associate the Parameter Store value with the RAM resource share
26+
resource "aws_ram_resource_association" "ssm_parameter_association" {
27+
resource_share_arn = aws_ram_resource_share.ssm_parameter_share.arn
28+
resource_arn = aws_ssm_parameter.current.arn
29+
}
30+
31+
## Associate the principals with the RAM share
32+
resource "aws_ram_principal_association" "ssm_parameter_accounts" {
33+
for_each = toset(var.share.accounts)
34+
35+
principal = each.value
36+
resource_share_arn = aws_ram_resource_share.this.arn
37+
}
38+
39+
## Associate the principals with the RAM share
40+
resource "aws_ram_principal_association" "ssm_parameter_organizational_units" {
41+
for_each = toset(var.share.organizational_units)
42+
43+
principal = each.value
44+
resource_share_arn = aws_ram_resource_share.this.arn
45+
}

modules/shared/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ variable "share" {
2020
default = {}
2121
}
2222

23+
variable "parameter_store_prefix" {
24+
description = "The prefix to use for the SSM parameter store"
25+
type = string
26+
default = "/lz/network/shared"
27+
}
28+
2329
variable "permitted_subnets" {
2430
description = "A collection of additional subnets to allow access to"
2531
type = list(string)

0 commit comments

Comments
 (0)