Skip to content

Commit 6d1ac83

Browse files
committed
Sync from management repo
1 parent 02b4f7d commit 6d1ac83

File tree

13 files changed

+120
-339
lines changed

13 files changed

+120
-339
lines changed

.github/workflows/stale-actions.yml

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

.pre-commit-config.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.64.0
3+
rev: v1.76.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_tflint
@@ -12,14 +12,13 @@ repos:
1212
- '--args=--only=terraform_documented_outputs'
1313
- '--args=--only=terraform_documented_variables'
1414
- '--args=--only=terraform_typed_variables'
15-
#- '--args=--only=terraform_module_pinned_source'
1615
- '--args=--only=terraform_naming_convention'
1716
- '--args=--only=terraform_required_providers'
1817
- '--args=--only=terraform_standard_module_structure'
1918
- '--args=--only=terraform_workspace_remote'
2019

2120
- repo: https://github.com/pre-commit/pre-commit-hooks
22-
rev: v4.1.0
21+
rev: v4.3.0
2322
hooks:
2423
- id: trailing-whitespace
2524
- id: end-of-file-fixer
@@ -31,7 +30,7 @@ repos:
3130
- id: requirements-txt-fixer
3231

3332
- repo: https://github.com/bridgecrewio/checkov.git
34-
rev: '2.0.914'
33+
rev: '2.1.280'
3534
hooks:
3635
- id: checkov
3736
verbose: true

README.md

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
### Versions
2626

2727
- Module tested for Terraform 1.0.1.
28-
- AWS provider version [3.74](https://registry.terraform.io/providers/hashicorp/aws/latest)
28+
- AWS provider version [4.35](https://registry.terraform.io/providers/hashicorp/aws/latest)
2929
- `main` branch: Provider versions not pinned to keep up with Terraform releases
3030
- `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-aws-elasticache/tags" alt="GitHub tag">
3131
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-aws-elasticache" /></a> in your releases)
@@ -91,43 +91,6 @@ tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'
9191
```
9292

9393
**Note:** Read more on [tfremote](https://github.com/tomarv2/tfremote)
94-
```
95-
terraform {
96-
required_version = ">= 1.0.1"
97-
required_providers {
98-
aws = {
99-
version = "~> 3.74"
100-
}
101-
}
102-
}
103-
104-
provider "aws" {
105-
region = var.region
106-
}
107-
108-
module "redis" {
109-
source = "../"
110-
111-
deploy_redis = true
112-
deploy_redis_parameter_group = true
113-
114-
security_group_ids = [module.security_group.security_group_id]
115-
# ----------------------------------------------
116-
# Note: Do not change teamid and prjid once set.
117-
teamid = var.teamid
118-
prjid = var.prjid
119-
}
120-
121-
module "security_group" {
122-
source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.6"
123-
124-
deploy_security_group = true
125-
126-
service_ports = [6379]
127-
teamid = var.teamid
128-
prjid = var.prjid
129-
}
130-
```
13194

13295
Please refer to examples directory [link](examples) for references.
13396

@@ -138,65 +101,25 @@ Please refer to examples directory [link](examples) for references.
138101
<!-- BEGIN_TF_DOCS -->
139102
## Requirements
140103

141-
| Name | Version |
142-
|------|---------|
143-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.1 |
144-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.74 |
104+
No requirements.
145105

146106
## Providers
147107

148-
| Name | Version |
149-
|------|---------|
150-
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.74 |
108+
No providers.
151109

152110
## Modules
153111

154-
| Name | Source | Version |
155-
|------|--------|---------|
156-
| <a name="module_global"></a> [global](#module\_global) | git::git@github.com:tomarv2/terraform-global.git//aws | v0.0.1 |
112+
No modules.
157113

158114
## Resources
159115

160-
| Name | Type |
161-
|------|------|
162-
| [aws_elasticache_cluster.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster) | resource |
163-
| [aws_elasticache_parameter_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_parameter_group) | resource |
164-
| [aws_elasticache_subnet_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
165-
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
166-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
116+
No resources.
167117

168118
## Inputs
169119

170-
| Name | Description | Type | Default | Required |
171-
|------|-------------|------|---------|:--------:|
172-
| <a name="input_apply_immediately"></a> [apply\_immediately](#input\_apply\_immediately) | Specifies whether any database modifications are applied immediately, or during the next maintenance window. Default is false. | `bool` | `true` | no |
173-
| <a name="input_availability_zone"></a> [availability\_zone](#input\_availability\_zone) | The Availability Zone for the cache cluster. If you want to create cache nodes in multi-az, use preferred\_availability\_zones instead. Default: System chosen Availability Zone. Changing this value will re-create the resource. | `string` | `null` | no |
174-
| <a name="input_az_mode"></a> [az\_mode](#input\_az\_mode) | (Memcached only) Specifies whether the nodes in this Memcached node group are created in a single Availability Zone or created across multiple Availability Zones in the cluster's region. Valid values for this parameter are single-az or cross-az, default is single-az. If you want to choose cross-az, num\_cache\_nodes must be greater than 1. | `string` | `null` | no |
175-
| <a name="input_cache_nodes"></a> [cache\_nodes](#input\_cache\_nodes) | The initial number of cache nodes that the cache cluster will have. For Redis, this value must be 1. For Memcache, this value must be between 1 and 20. | `number` | `1` | no |
176-
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | Group identifier. ElastiCache converts this name to lowercase | `string` | `null` | no |
177-
| <a name="input_cluster_mode_enabled"></a> [cluster\_mode\_enabled](#input\_cluster\_mode\_enabled) | Flag to enable/disable creation of a native redis cluster. `automatic_failover_enabled` must be set to `true`. Only 1 `cluster_mode` block is allowed | `bool` | `false` | no |
178-
| <a name="input_deploy_redis"></a> [deploy\_redis](#input\_deploy\_redis) | Feature flag, true or false | `bool` | `true` | no |
179-
| <a name="input_deploy_redis_parameter_group"></a> [deploy\_redis\_parameter\_group](#input\_deploy\_redis\_parameter\_group) | Feature flag, true or false | `bool` | `true` | no |
180-
| <a name="input_engine"></a> [engine](#input\_engine) | Name of the cache engine to be used for this cache cluster. Valid values for this parameter are memcached or redis. | `string` | `"redis"` | no |
181-
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | Version of engine | `string` | `"5.0.6"` | no |
182-
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | Specifies the weekly time range for when maintenance on the cache cluster is performed. | `string` | `"mon:10:30-mon:11:30"` | no |
183-
| <a name="input_node_type"></a> [node\_type](#input\_node\_type) | The compute and memory capacity of the nodes | `string` | `"cache.t2.micro"` | no |
184-
| <a name="input_notification_topic_arn"></a> [notification\_topic\_arn](#input\_notification\_topic\_arn) | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: arn:aws:sns:us-east-1:012345678999:my\_sns\_topic. | `string` | `null` | no |
185-
| <a name="input_parameter"></a> [parameter](#input\_parameter) | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
186-
| <a name="input_parameter_group_family"></a> [parameter\_group\_family](#input\_parameter\_group\_family) | The family of the ElastiCache parameter group | `string` | `"redis5.0"` | no |
187-
| <a name="input_port"></a> [port](#input\_port) | The port number on which each of the cache nodes will accept connections. For Memcache the default is 11211, and for Redis the default port is 6379. | `number` | `6379` | no |
188-
| <a name="input_prjid"></a> [prjid](#input\_prjid) | Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply' | `string` | n/a | yes |
189-
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | One or more VPC security groups associated with the cache cluster | `string` | n/a | yes |
190-
| <a name="input_snapshot_arns"></a> [snapshot\_arns](#input\_snapshot\_arns) | A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my\_bucket/snapshot1.rdb | `list(any)` | <pre>[<br> ""<br>]</pre> | no |
191-
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_snapshot\_retention\_limit) | Number of days snapshot image will be retained | `number` | `5` | no |
192-
| <a name="input_snapshot_window"></a> [snapshot\_window](#input\_snapshot\_window) | Daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. Example: 05:00-09:00. | `string` | `""` | no |
193-
| <a name="input_teamid"></a> [teamid](#input\_teamid) | Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply' | `string` | n/a | yes |
120+
No inputs.
194121

195122
## Outputs
196123

197-
| Name | Description |
198-
|------|-------------|
199-
| <a name="output_aws_elasticache_parameter_group"></a> [aws\_elasticache\_parameter\_group](#output\_aws\_elasticache\_parameter\_group) | Elasticache Parameter Group |
200-
| <a name="output_elasticache_cluster_address"></a> [elasticache\_cluster\_address](#output\_elasticache\_cluster\_address) | Elasticache Cluster address |
201-
| <a name="output_elasticache_id"></a> [elasticache\_id](#output\_elasticache\_id) | Elasticache Id |
124+
No outputs.
202125
<!-- END_TF_DOCS -->

examples/main.tf

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,59 @@ terraform {
22
required_version = ">= 1.0.1"
33
required_providers {
44
aws = {
5-
version = "~> 3.74"
5+
version = "~> 4.35"
66
}
77
}
88
}
99

1010
provider "aws" {
11-
region = var.region
11+
region = "us-west-2"
1212
}
1313

1414
module "redis" {
1515
source = "../"
1616

17-
deploy_redis = true
18-
deploy_redis_parameter_group = true
19-
20-
security_group_ids = [module.security_group.security_group_id]
21-
# ----------------------------------------------
22-
# Note: Do not change teamid and prjid once set.
23-
teamid = var.teamid
24-
prjid = var.prjid
17+
config = {
18+
demo = {
19+
security_group_ids = module.security_group.id
20+
engine_version = "6.2"
21+
family = "redis6.x"
22+
parameter_group_config = {
23+
activerehashing = {
24+
value = "yes"
25+
}
26+
}
27+
}
28+
}
2529
}
2630

2731
module "security_group" {
28-
source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.6"
29-
30-
deploy_security_group = true
31-
32-
service_ports = [6379]
33-
teamid = var.teamid
34-
prjid = var.prjid
32+
#source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.12"
33+
source = "../../terraform-aws-security-group"
34+
config = {
35+
demo_redis = {
36+
all_ingress_rules = [
37+
{
38+
description = "https"
39+
type = "ingress"
40+
from_port = 6379
41+
protocol = "tcp"
42+
to_port = 6379
43+
self = true
44+
cidr_blocks = []
45+
}
46+
]
47+
all_egress_rules = [
48+
{
49+
description = "outbound traffic"
50+
from_port = 0
51+
protocol = "-1"
52+
type = "egress"
53+
to_port = 0
54+
self = false
55+
cidr_blocks = ["0.0.0.0/0"]
56+
}
57+
]
58+
}
59+
}
3560
}

examples/outputs.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
output "elasticache_id" {
1+
output "cluster_id" {
2+
value = module.redis.cluster_id
23
description = "Elasticache Id"
3-
value = module.redis.elasticache_id
44
}
55

6-
output "elasticache_cluster_address" {
6+
output "cluster_address" {
7+
value = module.redis.cluster_address
78
description = "Elasticache Cluster address"
8-
value = module.redis.elasticache_cluster_address
99
}
1010

11-
output "aws_elasticache_parameter_group" {
11+
output "parameter_group" {
1212
description = "Elasticache Parameter Group"
13-
value = module.redis.aws_elasticache_parameter_group
13+
value = module.redis.parameter_group
1414
}
1515

1616
output "security_group_id" {
1717
description = "Security group Id"
18-
value = module.security_group.security_group_id
18+
value = module.security_group.id
1919
}

examples/variables.tf

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

main.tf

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,50 @@
22
#NOTE: For working with Redis (Cluster Mode Enabled) replication groups
33
# see the aws_elasticache_replication_group resource.
44
#
5-
resource "aws_elasticache_cluster" "default" {
6-
count = var.deploy_redis ? 1 : 0
5+
resource "aws_elasticache_cluster" "this" {
6+
for_each = var.config
7+
cluster_id = each.key
8+
engine = try(each.value.engine, "redis")
9+
node_type = try(each.value.node_type, "cache.t2.micro")
10+
num_cache_nodes = try(each.value.num_cache_nodes, 1)
11+
parameter_group_name = try(each.value.parameter_group_config, null) == null ? "" : join("", [for entry in aws_elasticache_parameter_group.this : entry.name])
12+
engine_version = try(each.value.engine_version, "6.2")
13+
port = try(each.value.port, 6379)
14+
#subnet_group_name = module.global.list_of_subnets[local.account_id][local.region]
15+
security_group_ids = try(each.value.security_group_ids, "")
16+
snapshot_arns = try(each.value.snapshot_arns, [])
17+
snapshot_window = try(each.value.snapshot_window, "")
18+
snapshot_retention_limit = try(each.value.snapshot_retention_limit, 5)
19+
az_mode = try(each.value.az_mode, null)
20+
availability_zone = try(each.value.availability_zone, null)
21+
notification_topic_arn = try(each.value.notification_topic_arn, null)
22+
apply_immediately = try(each.value.apply_immediately, true)
23+
maintenance_window = try(each.value.maintenance_window, "mon:10:30-mon:11:30")
24+
tags = merge(local.shared_tags, var.extra_tags)
25+
}
26+
27+
locals {
28+
parameter_group_settings = flatten([
29+
for instance, config in var.config : [
30+
for k, v in config.parameter_group_config : {
31+
name = instance
32+
family = try(config.family, "redis6.0")
33+
parameter_name = k
34+
parameter_value = v.value
35+
}
36+
]])
37+
}
38+
39+
resource "aws_elasticache_parameter_group" "this" {
40+
for_each = { for i in local.parameter_group_settings : i.parameter_name => i }
41+
name = each.value.name
42+
family = each.value.family
743

8-
cluster_id = var.cluster_id == null ? "${var.teamid}-${var.prjid}" : var.cluster_id
9-
engine = var.engine
10-
node_type = var.node_type
11-
num_cache_nodes = var.cache_nodes
12-
parameter_group_name = var.deploy_redis_parameter_group == true ? join("", aws_elasticache_parameter_group.default.*.name) : ""
13-
engine_version = var.engine_version
14-
port = var.port
15-
subnet_group_name = aws_elasticache_subnet_group.default.name
16-
security_group_ids = var.security_group_ids
17-
snapshot_arns = var.snapshot_arns == [""] ? [] : var.snapshot_arns
18-
snapshot_window = var.snapshot_window == "" ? null : var.snapshot_window
19-
snapshot_retention_limit = var.snapshot_retention_limit == "" ? null : var.snapshot_retention_limit
20-
az_mode = var.az_mode == null ? null : var.az_mode
21-
availability_zone = var.availability_zone == null ? null : var.availability_zone
22-
tags = merge(local.shared_tags)
23-
notification_topic_arn = var.notification_topic_arn == null ? null : var.notification_topic_arn
24-
apply_immediately = var.apply_immediately == "" ? true : var.apply_immediately
25-
maintenance_window = var.maintenance_window
44+
dynamic "parameter" {
45+
for_each = { for i in local.parameter_group_settings : i.parameter_name => i }
46+
content {
47+
name = parameter.value.parameter_name
48+
value = parameter.value.parameter_value
49+
}
50+
}
2651
}

0 commit comments

Comments
 (0)