Skip to content

Commit b0b5a6b

Browse files
committed
feat: Add security_group_use_name_prefix variable to endpoint module
1 parent 10abed9 commit b0b5a6b

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

examples/complete/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module "vpc_endpoints" {
9393
vpc_id = module.vpc.vpc_id
9494

9595
create_security_group = true
96-
security_group_name_prefix = "${local.name}-vpc-endpoints-"
96+
security_group_name = "${local.name}-vpc-endpoints"
9797
security_group_description = "VPC endpoint security group"
9898
security_group_rules = {
9999
ingress_https = {
@@ -102,6 +102,10 @@ module "vpc_endpoints" {
102102
}
103103
}
104104

105+
security_group_tags = {
106+
Name = "example-name-override"
107+
}
108+
105109
endpoints = {
106110
s3 = {
107111
service = "s3"

modules/vpc-endpoints/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ No modules.
9898
| <a name="input_security_group_description"></a> [security\_group\_description](#input\_security\_group\_description) | Description of the security group created | `string` | `null` | no |
9999
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | Default security group IDs to associate with the VPC endpoints | `list(string)` | `[]` | no |
100100
| <a name="input_security_group_name"></a> [security\_group\_name](#input\_security\_group\_name) | Name to use on security group created. Conflicts with `security_group_name_prefix` | `string` | `null` | no |
101-
| <a name="input_security_group_name_prefix"></a> [security\_group\_name\_prefix](#input\_security\_group\_name\_prefix) | Name prefix to use on security group created. Conflicts with `security_group_name` | `string` | `null` | no |
102101
| <a name="input_security_group_rules"></a> [security\_group\_rules](#input\_security\_group\_rules) | Security group rules to add to the security group created | `any` | `{}` | no |
103102
| <a name="input_security_group_tags"></a> [security\_group\_tags](#input\_security\_group\_tags) | A map of additional tags to add to the security group created | `map(string)` | `{}` | no |
103+
| <a name="input_security_group_use_name_prefix"></a> [security\_group\_use\_name\_prefix](#input\_security\_group\_use\_name\_prefix) | Determines whether the security group name (`var.security_group_name`) is used as a prefix | `bool` | `true` | no |
104104
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | Default subnets IDs to associate with the VPC endpoints | `list(string)` | `[]` | no |
105105
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to use on all resources | `map(string)` | `{}` | no |
106106
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | Define maximum timeout for creating, updating, and deleting VPC endpoint resources | `map(string)` | `{}` | no |

modules/vpc-endpoints/main.tf

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
locals {
66
endpoints = { for k, v in var.endpoints : k => v if var.create && try(v.create, true) }
77

8-
security_group_ids = var.create && var.create_security_group ? concat(var.security_group_ids, [aws_security_group.this[0].id]) : var.security_group_ids
8+
security_group_ids = var.create && var.create_security_group ? concat(var.security_group_ids, [aws_security_group.this[0].id]) : var.security_group_ids
9+
security_group_name = try(coalesce(var.security_group_name), "")
910
}
1011

1112
data "aws_vpc_endpoint_service" "this" {
@@ -76,16 +77,12 @@ resource "aws_vpc_endpoint" "this" {
7677
resource "aws_security_group" "this" {
7778
count = var.create && var.create_security_group ? 1 : 0
7879

79-
name = var.security_group_name
80-
name_prefix = var.security_group_name_prefix
80+
name = var.security_group_use_name_prefix ? null : local.security_group_name
81+
name_prefix = var.security_group_use_name_prefix ? "${local.security_group_name}-" : null
8182
description = var.security_group_description
8283
vpc_id = var.vpc_id
8384

84-
tags = merge(
85-
var.tags,
86-
var.security_group_tags,
87-
{ "Name" = try(coalesce(var.security_group_name, var.security_group_name_prefix), "") },
88-
)
85+
tags = merge(var.tags, { Name = local.security_group_name }, var.security_group_tags, )
8986

9087
lifecycle {
9188
create_before_destroy = true

modules/vpc-endpoints/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ variable "security_group_name" {
5656
default = null
5757
}
5858

59-
variable "security_group_name_prefix" {
60-
description = "Name prefix to use on security group created. Conflicts with `security_group_name`"
61-
type = string
62-
default = null
59+
variable "security_group_use_name_prefix" {
60+
description = "Determines whether the security group name (`var.security_group_name`) is used as a prefix"
61+
type = bool
62+
default = true
6363
}
6464

6565
variable "security_group_description" {

0 commit comments

Comments
 (0)