Skip to content

Commit cc17a35

Browse files
committed
cleanup
2 parents a182185 + 7100417 commit cc17a35

17 files changed

+285
-172
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ _testmain.go
7979
/test/run.out
8080
/test/times.out
8181

82+
<<<<<<< HEAD
8283
# Python
8384
# Editors
8485
.vscode/

.pre-commit-config.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
repos:
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.60.0
4+
hooks:
5+
- id: terraform_fmt
6+
- id: terraform_tflint
7+
args:
8+
- '--args=--only=terraform_deprecated_interpolation'
9+
- '--args=--only=terraform_deprecated_index'
10+
- '--args=--only=terraform_unused_declarations'
11+
- '--args=--only=terraform_comment_syntax'
12+
- '--args=--only=terraform_documented_outputs'
13+
- '--args=--only=terraform_documented_variables'
14+
- '--args=--only=terraform_typed_variables'
15+
- '--args=--only=terraform_module_pinned_source'
16+
- '--args=--only=terraform_naming_convention'
17+
- '--args=--only=terraform_required_providers'
18+
- '--args=--only=terraform_standard_module_structure'
19+
- '--args=--only=terraform_workspace_remote'
20+
21+
- repo: https://github.com/pre-commit/pre-commit-hooks
22+
rev: v4.1.0
23+
hooks:
24+
- id: trailing-whitespace
25+
- id: end-of-file-fixer
26+
- id: check-docstring-first
27+
- id: check-yaml
28+
- id: debug-statements
29+
- id: double-quote-string-fixer
30+
- id: name-tests-test
31+
- id: requirements-txt-fixer
32+
33+
- repo: https://github.com/bridgecrewio/checkov.git
34+
rev: '2.0.914'
35+
hooks:
36+
- id: checkov
37+
verbose: true
38+
args: [-d, '.', --framework, 'terraform', --skip-check, 'CKV2_AWS_5,CKV_AWS_134', --download-external-modules, 'True']

README.md

Lines changed: 115 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<p align="center">
2-
<a href="https://github.com/tomarv2/terraform-aws-elasticache/actions/workflows/security_scans.yml" alt="Security Scans">
3-
<img src="https://github.com/tomarv2/terraform-aws-elasticache/actions/workflows/security_scans.yml/badge.svg?branch=main" /></a>
2+
<a href="https://github.com/tomarv2/terraform-aws-elasticache/actions/workflows/pre-commit.yml" alt="Pre Commit">
3+
<img src="https://github.com/tomarv2/terraform-aws-elasticache/actions/workflows/pre-commit.yml/badge.svg?branch=main" /></a>
44
<a href="https://www.apache.org/licenses/LICENSE-2.0" alt="license">
55
<img src="https://img.shields.io/github/license/tomarv2/terraform-aws-elasticache" /></a>
66
<a href="https://github.com/tomarv2/terraform-aws-elasticache/tags" alt="GitHub tag">
@@ -9,8 +9,6 @@
99
<img src="https://img.shields.io/github/commit-activity/m/tomarv2/terraform-aws-elasticache" /></a>
1010
<a href="https://stackoverflow.com/users/6679867/tomarv2" alt="Stack Exchange reputation">
1111
<img src="https://img.shields.io/stackexchange/stackoverflow/r/6679867"></a>
12-
<a href="https://discord.gg/XH975bzN" alt="chat on Discord">
13-
<img src="https://img.shields.io/discord/813961944443912223?logo=discord"></a>
1412
<a href="https://twitter.com/intent/follow?screen_name=varuntomar2019" alt="follow on Twitter">
1513
<img src="https://img.shields.io/twitter/follow/varuntomar2019?style=social&logo=twitter"></a>
1614
</p>
@@ -26,114 +24,181 @@
2624

2725
## Versions
2826

29-
- Module tested for Terraform 0.14.
30-
- AWS provider version [3.29.0](https://registry.terraform.io/providers/hashicorp/aws/latest)
27+
- Module tested for Terraform 1.0.1.
28+
- AWS provider version [3.63](https://registry.terraform.io/providers/hashicorp/aws/latest)
3129
- `main` branch: Provider versions not pinned to keep up with Terraform releases
3230
- `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-aws-elasticache/tags" alt="GitHub tag">
3331
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-aws-elasticache" /></a> in your releases)
3432

35-
**NOTE:**
33+
## Usage
3634

37-
- Read more on [tfremote](https://github.com/tomarv2/tfremote)
35+
### Option 1:
3836

39-
## Usage
37+
```
38+
terrafrom init
39+
terraform plan -var='teamid=tryme' -var='prjid=project1'
40+
terraform apply -var='teamid=tryme' -var='prjid=project1'
41+
terraform destroy -var='teamid=tryme' -var='prjid=project1'
42+
```
43+
**Note:** With this option please take care of remote state storage
44+
45+
### Option 2:
4046

41-
Recommended method:
47+
#### Recommended method (stores remote state in S3 using `prjid` and `teamid` to create directory structure):
4248

43-
- Create python 3.6+ virtual environment
49+
- Create python 3.8+ virtual environment
4450
```
4551
python3 -m venv <venv name>
4652
```
4753

4854
- Install package:
4955
```
50-
pip install tfremote
56+
pip install tfremote --upgrade
5157
```
5258

5359
- Set below environment variables:
5460
```
5561
export TF_AWS_BUCKET=<remote state bucket name>
56-
export TF_AWS_PROFILE=default
5762
export TF_AWS_BUCKET_REGION=us-west-2
58-
```
63+
export TF_AWS_PROFILE=<profile from ~/.ws/credentials>
64+
```
5965

60-
- Updated `examples` directory with required values .
66+
or
67+
68+
- Set below environment variables:
69+
```
70+
export TF_AWS_BUCKET=<remote state bucket name>
71+
export TF_AWS_BUCKET_REGION=us-west-2
72+
export AWS_ACCESS_KEY_ID=<aws_access_key_id>
73+
export AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>
74+
```
6175

76+
- Updated `examples` directory with required values.
6277

6378
- Run and verify the output before deploying:
6479
```
65-
tf -cloud aws plan
80+
tf -c=aws plan -var='teamid=foo' -var='prjid=bar'
6681
```
6782

6883
- Run below to deploy:
6984
```
70-
tf -cloud aws apply
85+
tf -c=aws apply -var='teamid=foo' -var='prjid=bar'
7186
```
7287

7388
- Run below to destroy:
7489
```
75-
tf -cloud aws destroy
90+
tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'
7691
```
7792

78-
> ❗️ **Important** - Two variables are required for using `tf` package:
79-
>
80-
> - teamid
81-
> - prjid
82-
>
83-
> These variables are required to set backend path in the remote storage.
84-
> Variables can be defined using:
85-
>
86-
> - As `inline variables` e.g.: `-var='teamid=demo-team' -var='prjid=demo-project'`
87-
> - Inside `.tfvars` file e.g.: `-var-file=<tfvars file location> `
88-
>
89-
> For more information refer to [Terraform documentation](https://www.terraform.io/docs/language/values/variables.html)
93+
**NOTE:**
94+
95+
- Read more on [tfremote](https://github.com/tomarv2/tfremote)
96+
---
9097

91-
##### Elasticache
9298
```
93-
module "redis" {
94-
source = "../"
99+
terraform {
100+
required_version = ">= 1.0.1"
101+
required_providers {
102+
aws = {
103+
version = "~> 3.63"
104+
}
105+
}
106+
}
95107
96-
security_group_ids = [<existing security group name>]
97-
account_id = "123456789012"
98-
email = "demo@demo.com"
99-
# ----------------------------------------------
100-
# Note: Do not change teamid and prjid once set.
101-
teamid = var.teamid
102-
prjid = var.prjid
108+
provider "aws" {
109+
region = var.region
103110
}
104-
```
105111
106-
##### Elasticache with Security Group
107-
```
108112
module "redis" {
109113
source = "../"
110114
111115
deploy_redis = true
112116
deploy_redis_parameter_group = true
113-
114-
security_group_ids = [module.security_group.security_group_id]
115-
account_id = "123456789012"
116-
email = "demo@demo.com"
117+
118+
security_group_ids = [module.security_group.security_group_id]
117119
# ----------------------------------------------
118120
# Note: Do not change teamid and prjid once set.
119121
teamid = var.teamid
120122
prjid = var.prjid
121123
}
122124
123125
module "security_group" {
124-
source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.1"
126+
source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.6"
125127
126128
deploy_security_group = true
127129
128130
service_ports = [6379]
129-
email = "demo@demo.com"
130131
teamid = var.teamid
131132
prjid = var.prjid
132133
}
133134
```
134135

135136
Please refer to examples directory [link](examples) for references.
136137

138+
## Requirements
139+
140+
| Name | Version |
141+
|------|---------|
142+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.1 |
143+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.63 |
144+
145+
## Providers
146+
147+
| Name | Version |
148+
|------|---------|
149+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.63 |
150+
151+
## Modules
152+
153+
| Name | Source | Version |
154+
|------|--------|---------|
155+
| <a name="module_global"></a> [global](#module\_global) | git::git@github.com:tomarv2/terraform-global.git//aws | v0.0.1 |
156+
157+
## Resources
158+
159+
| Name | Type |
160+
|------|------|
161+
| [aws_elasticache_cluster.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster) | resource |
162+
| [aws_elasticache_parameter_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_parameter_group) | resource |
163+
| [aws_elasticache_subnet_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
164+
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
165+
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
166+
167+
## Inputs
168+
169+
| Name | Description | Type | Default | Required |
170+
|------|-------------|------|---------|:--------:|
171+
| <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 |
172+
| <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 |
173+
| <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 |
174+
| <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 |
175+
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | Group identifier. ElastiCache converts this name to lowercase | `string` | `null` | no |
176+
| <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 |
177+
| <a name="input_deploy_redis"></a> [deploy\_redis](#input\_deploy\_redis) | feature flag, true or false | `bool` | `true` | no |
178+
| <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 |
179+
| <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 |
180+
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | Version of engine | `string` | `"5.0.6"` | no |
181+
| <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 |
182+
| <a name="input_node_type"></a> [node\_type](#input\_node\_type) | The compute and memory capacity of the nodes | `string` | `"cache.t2.micro"` | no |
183+
| <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 |
184+
| <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 |
185+
| <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 |
186+
| <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 |
187+
| <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 |
188+
| <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 |
189+
| <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 |
190+
| <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 |
191+
| <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 |
192+
| <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 |
193+
194+
## Outputs
195+
196+
| Name | Description |
197+
|------|-------------|
198+
| <a name="output_aws_elasticache_parameter_group"></a> [aws\_elasticache\_parameter\_group](#output\_aws\_elasticache\_parameter\_group) | Elasticache Parameter Group |
199+
| <a name="output_elasticache_cluster_address"></a> [elasticache\_cluster\_address](#output\_elasticache\_cluster\_address) | Elasticache Cluster address |
200+
| <a name="output_elasticache_id"></a> [elasticache\_id](#output\_elasticache\_id) | Elasticache Id |
201+
137202
**Note:**
138203

139-
- For more information on redis: [link](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/cluster-create-determine-requirements.html#redis-cluster-configuration)
204+
- For more information on redis: [link](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/cluster-create-determine-requirements.html#redis-cluster-configuration)

examples/test.tf renamed to examples/main.tf

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1+
terraform {
2+
required_version = ">= 1.0.1"
3+
required_providers {
4+
aws = {
5+
version = "~> 3.63"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
region = var.region
12+
}
13+
114
module "redis" {
215
source = "../"
316

417
deploy_redis = true
518
deploy_redis_parameter_group = true
619

7-
security_group_ids = [module.security_group.security_group_id]
8-
account_id = "755921336062"
9-
email = "varun.tomar@databricks.com"
20+
security_group_ids = [module.security_group.security_group_id]
1021
# ----------------------------------------------
1122
# Note: Do not change teamid and prjid once set.
1223
teamid = var.teamid
1324
prjid = var.prjid
1425
}
1526

1627
module "security_group" {
17-
source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.1"
28+
source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.6"
1829

1930
deploy_security_group = true
2031

2132
service_ports = [6379]
22-
email = "varun.tomar@databricks.com"
2333
teamid = var.teamid
2434
prjid = var.prjid
2535
}
26-

examples/output.tf

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

examples/outputs.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "elasticache_id" {
2+
description = "Elasticache Id"
3+
value = module.redis.elasticache_id
4+
}
5+
6+
output "elasticache_cluster_address" {
7+
description = "Elasticache Cluster address"
8+
value = module.redis.elasticache_cluster_address
9+
}
10+
11+
output "aws_elasticache_parameter_group" {
12+
description = "Elasticache Parameter Group"
13+
value = module.redis.aws_elasticache_parameter_group
14+
}
15+
16+
output "security_group_id" {
17+
description = "Security group Id"
18+
value = module.security_group.security_group_id
19+
}

examples/remote_backend.tf

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

examples/variables.tf

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
variable "teamid" {
2-
description = "(Required) Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply'"
2+
description = "Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply'"
3+
type = string
34
}
45

56
variable "prjid" {
6-
description = "(Required) Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply'"
7+
description = "Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply'"
8+
type = string
9+
}
10+
11+
variable "region" {
12+
description = "AWS region to create resources"
13+
default = "us-west-2"
14+
type = string
715
}

0 commit comments

Comments
 (0)