|
1 | 1 | <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> |
4 | 4 | <a href="https://www.apache.org/licenses/LICENSE-2.0" alt="license"> |
5 | 5 | <img src="https://img.shields.io/github/license/tomarv2/terraform-aws-elasticache" /></a> |
6 | 6 | <a href="https://github.com/tomarv2/terraform-aws-elasticache/tags" alt="GitHub tag"> |
|
9 | 9 | <img src="https://img.shields.io/github/commit-activity/m/tomarv2/terraform-aws-elasticache" /></a> |
10 | 10 | <a href="https://stackoverflow.com/users/6679867/tomarv2" alt="Stack Exchange reputation"> |
11 | 11 | <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> |
14 | 12 | <a href="https://twitter.com/intent/follow?screen_name=varuntomar2019" alt="follow on Twitter"> |
15 | 13 | <img src="https://img.shields.io/twitter/follow/varuntomar2019?style=social&logo=twitter"></a> |
16 | 14 | </p> |
|
26 | 24 |
|
27 | 25 | ## Versions |
28 | 26 |
|
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) |
31 | 29 | - `main` branch: Provider versions not pinned to keep up with Terraform releases |
32 | 30 | - `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-aws-elasticache/tags" alt="GitHub tag"> |
33 | 31 | <img src="https://img.shields.io/github/v/tag/tomarv2/terraform-aws-elasticache" /></a> in your releases) |
34 | 32 |
|
35 | | -**NOTE:** |
| 33 | +## Usage |
36 | 34 |
|
37 | | -- Read more on [tfremote](https://github.com/tomarv2/tfremote) |
| 35 | +### Option 1: |
38 | 36 |
|
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: |
40 | 46 |
|
41 | | -Recommended method: |
| 47 | +#### Recommended method (stores remote state in S3 using `prjid` and `teamid` to create directory structure): |
42 | 48 |
|
43 | | -- Create python 3.6+ virtual environment |
| 49 | +- Create python 3.8+ virtual environment |
44 | 50 | ``` |
45 | 51 | python3 -m venv <venv name> |
46 | 52 | ``` |
47 | 53 |
|
48 | 54 | - Install package: |
49 | 55 | ``` |
50 | | -pip install tfremote |
| 56 | +pip install tfremote --upgrade |
51 | 57 | ``` |
52 | 58 |
|
53 | 59 | - Set below environment variables: |
54 | 60 | ``` |
55 | 61 | export TF_AWS_BUCKET=<remote state bucket name> |
56 | | -export TF_AWS_PROFILE=default |
57 | 62 | export TF_AWS_BUCKET_REGION=us-west-2 |
58 | | -``` |
| 63 | +export TF_AWS_PROFILE=<profile from ~/.ws/credentials> |
| 64 | +``` |
59 | 65 |
|
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 | +``` |
61 | 75 |
|
| 76 | +- Updated `examples` directory with required values. |
62 | 77 |
|
63 | 78 | - Run and verify the output before deploying: |
64 | 79 | ``` |
65 | | -tf -cloud aws plan |
| 80 | +tf -c=aws plan -var='teamid=foo' -var='prjid=bar' |
66 | 81 | ``` |
67 | 82 |
|
68 | 83 | - Run below to deploy: |
69 | 84 | ``` |
70 | | -tf -cloud aws apply |
| 85 | +tf -c=aws apply -var='teamid=foo' -var='prjid=bar' |
71 | 86 | ``` |
72 | 87 |
|
73 | 88 | - Run below to destroy: |
74 | 89 | ``` |
75 | | -tf -cloud aws destroy |
| 90 | +tf -c=aws destroy -var='teamid=foo' -var='prjid=bar' |
76 | 91 | ``` |
77 | 92 |
|
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 | +--- |
90 | 97 |
|
91 | | -##### Elasticache |
92 | 98 | ``` |
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 | +} |
95 | 107 |
|
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 |
103 | 110 | } |
104 | | -``` |
105 | 111 |
|
106 | | -##### Elasticache with Security Group |
107 | | -``` |
108 | 112 | module "redis" { |
109 | 113 | source = "../" |
110 | 114 |
|
111 | 115 | deploy_redis = true |
112 | 116 | 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] |
117 | 119 | # ---------------------------------------------- |
118 | 120 | # Note: Do not change teamid and prjid once set. |
119 | 121 | teamid = var.teamid |
120 | 122 | prjid = var.prjid |
121 | 123 | } |
122 | 124 |
|
123 | 125 | 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" |
125 | 127 |
|
126 | 128 | deploy_security_group = true |
127 | 129 |
|
128 | 130 | service_ports = [6379] |
129 | | - email = "demo@demo.com" |
130 | 131 | teamid = var.teamid |
131 | 132 | prjid = var.prjid |
132 | 133 | } |
133 | 134 | ``` |
134 | 135 |
|
135 | 136 | Please refer to examples directory [link](examples) for references. |
136 | 137 |
|
| 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 | + |
137 | 202 | **Note:** |
138 | 203 |
|
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) |
0 commit comments