Skip to content

Commit 7b22fc1

Browse files
committed
feat(security-group): support ram share
1 parent c20bebf commit 7b22fc1

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

modules/security-group/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This module creates following resources.
2626
| Name | Source | Version |
2727
|------|--------|---------|
2828
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | tedilabs/misc/aws//modules/resource-group | ~> 0.12.0 |
29+
| <a name="module_share"></a> [share](#module\_share) | tedilabs/organization/aws//modules/ram-share | ~> 0.4.0 |
2930

3031
## Resources
3132

@@ -49,6 +50,7 @@ This module creates following resources.
4950
| <a name="input_region"></a> [region](#input\_region) | (Optional) The region in which to create the module resources. If not provided, the module resources will be created in the provider's configured region. | `string` | `null` | no |
5051
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group) | (Optional) A configurations of Resource Group for this module. `resource_group` as defined below.<br/> (Optional) `enabled` - Whether to create Resource Group to find and group AWS resources which are created by this module. Defaults to `true`.<br/> (Optional) `name` - The name of Resource Group. A Resource Group name can have a maximum of 127 characters, including letters, numbers, hyphens, dots, and underscores. The name cannot start with `AWS` or `aws`. If not provided, a name will be generated using the module name and instance name.<br/> (Optional) `description` - The description of Resource Group. Defaults to `Managed by Terraform.`. | <pre>object({<br/> enabled = optional(bool, true)<br/> name = optional(string, "")<br/> description = optional(string, "Managed by Terraform.")<br/> })</pre> | `{}` | no |
5152
| <a name="input_revoke_rules_on_delete"></a> [revoke\_rules\_on\_delete](#input\_revoke\_rules\_on\_delete) | (Optional) Instruct Terraform to revoke all of the Security Groups attached ingress and egress rules before deleting the rule itself. This is normally not needed. | `bool` | `false` | no |
53+
| <a name="input_shares"></a> [shares](#input\_shares) | (Optional) A list of resource shares via RAM (Resource Access Manager). | <pre>list(object({<br/> name = optional(string)<br/><br/> permissions = optional(set(string), ["AWSRAMDefaultPermissionsSecurityGroup"])<br/><br/> external_principals_allowed = optional(bool, false)<br/> principals = optional(set(string), [])<br/><br/> tags = optional(map(string), {})<br/> }))</pre> | `[]` | no |
5254
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
5355
| <a name="input_vpc_associations"></a> [vpc\_associations](#input\_vpc\_associations) | (Optional) A set of VPC IDs to associate with the security group. | `set(string)` | `[]` | no |
5456

@@ -65,6 +67,7 @@ This module creates following resources.
6567
| <a name="output_owner_id"></a> [owner\_id](#output\_owner\_id) | The ID of the AWS account that owns the security group. |
6668
| <a name="output_region"></a> [region](#output\_region) | The AWS region this module resources resides in. |
6769
| <a name="output_resource_group"></a> [resource\_group](#output\_resource\_group) | The resource group created to manage resources in this module. |
70+
| <a name="output_sharing"></a> [sharing](#output\_sharing) | The configuration for sharing of the security group.<br/> `status` - An indication of whether the security group is shared with other AWS accounts, or was shared with the current account by another AWS account. Sharing is configured through AWS Resource Access Manager (AWS RAM). Values are `NOT_SHARED`, `SHARED_BY_ME` or `SHARED_WITH_ME`.<br/> `shares` - The list of resource shares via RAM (Resource Access Manager). |
6871
| <a name="output_vpc_associations"></a> [vpc\_associations](#output\_vpc\_associations) | A set |
6972
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | The ID of the associated VPC. |
7073
<!-- END_TF_DOCS -->

modules/security-group/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,15 @@ output "resource_group" {
9696
)
9797
)
9898
}
99+
100+
output "sharing" {
101+
description = <<EOF
102+
The configuration for sharing of the security group.
103+
`status` - An indication of whether the security group is shared with other AWS accounts, or was shared with the current account by another AWS account. Sharing is configured through AWS Resource Access Manager (AWS RAM). Values are `NOT_SHARED`, `SHARED_BY_ME` or `SHARED_WITH_ME`.
104+
`shares` - The list of resource shares via RAM (Resource Access Manager).
105+
EOF
106+
value = {
107+
status = length(module.share) > 0 ? "SHARED_BY_ME" : "NOT_SHARED"
108+
shares = module.share
109+
}
110+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
###################################################
2+
# Resource Sharing by RAM (Resource Access Manager)
3+
###################################################
4+
5+
module "share" {
6+
source = "tedilabs/organization/aws//modules/ram-share"
7+
version = "~> 0.4.0"
8+
9+
for_each = {
10+
for share in var.shares :
11+
share.name => share
12+
}
13+
14+
region = aws_security_group.this.region
15+
16+
name = "vpc.security-group.${var.name}.${each.key}"
17+
18+
resources = [
19+
aws_security_group.this.arn
20+
]
21+
22+
permissions = each.value.permissions
23+
24+
external_principals_allowed = each.value.external_principals_allowed
25+
principals = each.value.principals
26+
27+
resource_group = {
28+
enabled = false
29+
}
30+
module_tags_enabled = false
31+
32+
tags = merge(
33+
local.module_tags,
34+
var.tags,
35+
each.value.tags,
36+
)
37+
}

modules/security-group/variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,24 @@ variable "resource_group" {
169169
default = {}
170170
nullable = false
171171
}
172+
173+
174+
###################################################
175+
# Resource Sharing by RAM (Resource Access Manager)
176+
###################################################
177+
178+
variable "shares" {
179+
description = "(Optional) A list of resource shares via RAM (Resource Access Manager)."
180+
type = list(object({
181+
name = optional(string)
182+
183+
permissions = optional(set(string), ["AWSRAMDefaultPermissionsSecurityGroup"])
184+
185+
external_principals_allowed = optional(bool, false)
186+
principals = optional(set(string), [])
187+
188+
tags = optional(map(string), {})
189+
}))
190+
default = []
191+
nullable = false
192+
}

0 commit comments

Comments
 (0)