Skip to content

Commit 6f3ee51

Browse files
committed
feat: Update subnet group configuration and move from sub-module to root module
1 parent 4af4f5c commit 6f3ee51

File tree

9 files changed

+32
-128
lines changed

9 files changed

+32
-128
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Terraform module which creates AWS ElastiCache resources.
44

5+
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
6+
57
## Usage
68

79
See [`examples`](https://github.com/clowdhaus/terraform-aws-elasticache/tree/main/examples) directory for working examples to reference:
@@ -39,9 +41,7 @@ Examples codified under the [`examples`](https://github.com/clowdhaus/terraform-
3941

4042
## Modules
4143

42-
| Name | Source | Version |
43-
|------|--------|---------|
44-
| <a name="module_subnet_group"></a> [subnet\_group](#module\_subnet\_group) | ./modules/subnet_group | n/a |
44+
No modules.
4545

4646
## Resources
4747

@@ -50,6 +50,7 @@ Examples codified under the [`examples`](https://github.com/clowdhaus/terraform-
5050
| [aws_elasticache_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster) | resource |
5151
| [aws_elasticache_parameter_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_parameter_group) | resource |
5252
| [aws_elasticache_replication_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group) | resource |
53+
| [aws_elasticache_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
5354

5455
## Inputs
5556

@@ -104,7 +105,7 @@ Examples codified under the [`examples`](https://github.com/clowdhaus/terraform-
104105
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | (Redis only) Number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them | `number` | `null` | no |
105106
| <a name="input_snapshot_window"></a> [snapshot\_window](#input\_snapshot\_window) | (Redis only) Daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. Example: `05:00-09:00` | `string` | `null` | no |
106107
| <a name="input_subnet_group_description"></a> [subnet\_group\_description](#input\_subnet\_group\_description) | Description for the Elasticache subnet group | `string` | `null` | no |
107-
| <a name="input_subnet_group_name"></a> [subnet\_group\_name](#input\_subnet\_group\_name) | Name of the subnet group to be used for the cache cluster. Changing this value will re-create the resource | `string` | `null` | no |
108+
| <a name="input_subnet_group_name"></a> [subnet\_group\_name](#input\_subnet\_group\_name) | The name of the subnet group. If `create_subnet_group` is `true`, this is the name assigned to the subnet group created. Otherwise, this is the name of an existing subnet group | `string` | `null` | no |
108109
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | List of VPC Subnet IDs for the Elasticache subnet group | `list(string)` | `[]` | no |
109110
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
110111
| <a name="input_transit_encryption_enabled"></a> [transit\_encryption\_enabled](#input\_transit\_encryption\_enabled) | Enable encryption in-transit. Supported only with Memcached versions `1.6.12` and later, running in a VPC | `bool` | `null` | no |
@@ -128,7 +129,6 @@ Examples codified under the [`examples`](https://github.com/clowdhaus/terraform-
128129
| <a name="output_rep_group_member_clusters"></a> [rep\_group\_member\_clusters](#output\_rep\_group\_member\_clusters) | Identifiers of all the nodes that are part of this replication group |
129130
| <a name="output_rep_group_primary_endpoint_address"></a> [rep\_group\_primary\_endpoint\_address](#output\_rep\_group\_primary\_endpoint\_address) | Address of the endpoint for the primary node in the replication group, if the cluster mode is disabled |
130131
| <a name="output_rep_group_reader_endpoint_address"></a> [rep\_group\_reader\_endpoint\_address](#output\_rep\_group\_reader\_endpoint\_address) | Address of the endpoint for the reader node in the replication group, if the cluster mode is disabled |
131-
| <a name="output_subnet_group_ids"></a> [subnet\_group\_ids](#output\_subnet\_group\_ids) | The ElastiCache subnet group IDs |
132132
| <a name="output_subnet_group_name"></a> [subnet\_group\_name](#output\_subnet\_group\_name) | The ElastiCache subnet group name |
133133
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
134134

main.tf

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ resource "aws_elasticache_cluster" "this" {
3939
notification_topic_arn = local.in_replication_group ? null : var.notification_topic_arn
4040
num_cache_nodes = local.in_replication_group ? null : var.num_cache_nodes
4141
outpost_mode = var.outpost_mode
42-
parameter_group_name = local.in_replication_group ? null : var.parameter_group_name
42+
parameter_group_name = local.in_replication_group ? null : local.parameter_group_name
4343
port = local.in_replication_group ? null : coalesce(var.port, local.port)
4444
preferred_availability_zones = var.preferred_availability_zones
4545
preferred_outpost_arn = var.preferred_outpost_arn
@@ -100,7 +100,7 @@ resource "aws_elasticache_replication_group" "this" {
100100
notification_topic_arn = var.notification_topic_arn
101101
num_cache_clusters = var.num_cache_clusters
102102
num_node_groups = local.in_global_replication_group ? null : var.num_node_groups
103-
parameter_group_name = local.in_global_replication_group ? null : var.parameter_group_name
103+
parameter_group_name = local.in_global_replication_group ? null : local.parameter_group_name
104104
port = coalesce(var.port, local.port)
105105
preferred_cache_cluster_azs = var.preferred_cache_cluster_azs
106106
replicas_per_node_group = var.replicas_per_node_group
@@ -122,6 +122,10 @@ resource "aws_elasticache_replication_group" "this" {
122122
# Parameter Group
123123
################################################################################
124124

125+
locals {
126+
parameter_group_name = var.create && var.create_parameter_group ? aws_elasticache_parameter_group.this[0].id : var.parameter_group_name
127+
}
128+
125129
resource "aws_elasticache_parameter_group" "this" {
126130
count = var.create && var.create_parameter_group ? 1 : 0
127131

@@ -150,18 +154,12 @@ resource "aws_elasticache_parameter_group" "this" {
150154
# Subnet Group
151155
################################################################################
152156

153-
locals {
154-
identifier = local.in_replication_group ? var.replication_group_id : var.cluster_id
155-
subnet_group_name = var.create_subnet_group ? module.subnet_group.name : var.subnet_group_name
156-
parameter_group_name = var.create_parameter_group ? module.parameter_group.id : var.parameter_group_name
157-
}
158-
159-
module "subnet_group" {
160-
source = "./modules/subnet_group"
157+
resource "aws_elasticache_subnet_group" "this" {
158+
count = var.create && var.create_subnet_group ? 1 : 0
161159

162-
create = var.create_subnet_group
163-
identifier = local.identifier
164160
name = var.subnet_group_name
165-
description = var.subnet_group_description
161+
description = coalesce(var.subnet_group_description, "ElastiCache subnet group")
166162
subnet_ids = var.subnet_ids
163+
164+
tags = var.tags
167165
}

modules/subnet_group/README.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

modules/subnet_group/main.tf

Lines changed: 0 additions & 11 deletions
This file was deleted.

modules/subnet_group/outputs.tf

Whitespace-only changes.

modules/subnet_group/variables.tf

Lines changed: 0 additions & 29 deletions
This file was deleted.

modules/subnet_group/versions.tf

Lines changed: 0 additions & 10 deletions
This file was deleted.

outputs.tf

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ output "rep_group_reader_endpoint_address" {
6565
description = "Address of the endpoint for the reader node in the replication group, if the cluster mode is disabled"
6666
value = try(aws_elasticache_replication_group.this[0].reader_endpoint_address, null)
6767
}
68-
################################################################################
69-
# Subnet Group
70-
################################################################################
71-
72-
output "subnet_group_name" {
73-
description = "The ElastiCache subnet group name"
74-
value = module.subnet_group.name
75-
}
76-
77-
output "subnet_group_ids" {
78-
description = "The ElastiCache subnet group IDs"
79-
value = module.subnet_group.ids
80-
}
8168

8269
################################################################################
8370
# Parameter Group
@@ -92,3 +79,12 @@ output "parameter_group_id" {
9279
description = "The ElastiCache parameter group name"
9380
value = try(aws_elasticache_parameter_group.this[0].id, null)
9481
}
82+
83+
################################################################################
84+
# Subnet Group
85+
################################################################################
86+
87+
output "subnet_group_name" {
88+
description = "The ElastiCache subnet group name"
89+
value = try(aws_elasticache_subnet_group.this[0].name, null)
90+
}

variables.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ variable "snapshot_window" {
170170
default = null
171171
}
172172

173-
variable "subnet_group_name" {
174-
description = "Name of the subnet group to be used for the cache cluster. Changing this value will re-create the resource"
175-
type = string
176-
default = null
177-
}
178-
179173
variable "transit_encryption_enabled" {
180174
description = "Enable encryption in-transit. Supported only with Memcached versions `1.6.12` and later, running in a VPC"
181175
type = bool
@@ -326,14 +320,20 @@ variable "create_subnet_group" {
326320
default = false
327321
}
328322

323+
variable "subnet_group_name" {
324+
description = "The name of the subnet group. If `create_subnet_group` is `true`, this is the name assigned to the subnet group created. Otherwise, this is the name of an existing subnet group"
325+
type = string
326+
default = null
327+
}
328+
329329
variable "subnet_group_description" {
330330
description = "Description for the Elasticache subnet group"
331331
type = string
332332
default = null
333333
}
334334

335335
variable "subnet_ids" {
336-
description = "List of VPC Subnet IDs for the Elasticache subnet group "
336+
description = "List of VPC Subnet IDs for the Elasticache subnet group"
337337
type = list(string)
338338
default = []
339339
}

0 commit comments

Comments
 (0)