88
99# # Provision the SSM parameter to store the JSON data
1010resource  "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
2022resource  "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
2731resource  "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
3339resource  "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
4147resource  "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}
0 commit comments