Skip to content

Commit 8e0ee36

Browse files
committed
feat: aws elasticache redis service
1 parent 0016a68 commit 8e0ee36

19 files changed

+749
-187
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ help:
1818
# Usage:
1919
#
2020
# * [dev] `make generate`, generate README file.
21-
# - `make generate examples/hello-world` only generate README file under examples/hello-world directory.
21+
# - `make generate examples/standalone` only generate README file under examples/standalone directory.
2222
#
2323
# * [dev] `make lint`, check style and security.
2424
# - `LINT_DIRTY=true make lint` verify whether the code tree is dirty.
25-
# - `make lint examples/hello-world` only verify the code under examples/hello-world directory.
25+
# - `make lint examples/standalone` only verify the code under examples/standalone directory.
2626
#
2727
# * [dev] `make test`, execute unit testing.
28-
# - `make test example/hello-world` only test the code under examples/hello-world directory.
28+
# - `make test example/standalone` only test the code under examples/standalone directory.
2929
#
3030
# * [ci] `make ci`, execute `make generate`, `make lint` and `make test`.
3131
#

README.md

+51-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
# Awesome Walrus Template
1+
# AWS Elasticache Redis Template
22

3-
Start here to create an awesome Walrus template.
3+
Terraform module which deploys [Elasticache Redis](https://aws.amazon.com/elasticache/redis/) on AWS.
44

55
## Usage
66

77
```hcl
8-
8+
module "example" {
9+
source = "..."
10+
11+
infrastructure = {
12+
vpc_id = "..."
13+
kms_key_id = "..."
14+
domain_suffix = "..."
15+
}
16+
17+
architecture = "standalone"
18+
engine_version = "7.0"
19+
}
920
```
1021

1122
## Examples
1223

13-
- ...
14-
- ...
24+
- [Replication](./examples/replication)
25+
- [Standalone](./examples/standalone)
1526

1627
## Contributing
1728

@@ -23,38 +34,61 @@ Please read our [contributing guide](./docs/CONTRIBUTING.md) if you're intereste
2334
| Name | Version |
2435
|------|---------|
2536
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
37+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24.0 |
38+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.5.1 |
2639

2740
## Providers
2841

29-
No providers.
42+
| Name | Version |
43+
|------|---------|
44+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24.0 |
45+
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.5.1 |
3046

3147
## Modules
3248

33-
| Name | Source | Version |
34-
|------|--------|---------|
35-
| <a name="module_submodule"></a> [submodule](#module\_submodule) | ./modules/submodule | n/a |
49+
No modules.
3650

3751
## Resources
3852

39-
No resources.
53+
| Name | Type |
54+
|------|------|
55+
| [aws_elasticache_parameter_group.target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_parameter_group) | resource |
56+
| [aws_elasticache_replication_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group) | resource |
57+
| [aws_elasticache_subnet_group.target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |
58+
| [aws_security_group.target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
59+
| [aws_security_group_rule.target](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
60+
| [aws_service_discovery_instance.primary](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/service_discovery_instance) | resource |
61+
| [aws_service_discovery_instance.reader](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/service_discovery_instance) | resource |
62+
| [aws_service_discovery_service.primary](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/service_discovery_service) | resource |
63+
| [aws_service_discovery_service.reader](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/service_discovery_service) | resource |
64+
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
65+
| [random_string.name_suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
66+
| [aws_kms_key.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/kms_key) | data source |
67+
| [aws_service_discovery_dns_namespace.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/service_discovery_dns_namespace) | data source |
68+
| [aws_subnets.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnets) | data source |
69+
| [aws_vpc.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/vpc) | data source |
4070

4171
## Inputs
4272

4373
| Name | Description | Type | Default | Required |
4474
|------|-------------|------|---------|:--------:|
4575
| <a name="input_context"></a> [context](#input\_context) | Receive contextual information. When Walrus deploys, Walrus will inject specific contextual information into this field.<br><br>Examples:<pre>context:<br> project:<br> name: string<br> id: string<br> environment:<br> name: string<br> id: string<br> resource:<br> name: string<br> id: string</pre> | `map(any)` | `{}` | no |
76+
| <a name="input_infrastructure"></a> [infrastructure](#input\_infrastructure) | Specify the infrastructure information for deploying.<br><br>Examples:<pre>infrastructure:<br> vpc_id: string # the ID of the VPC where the MySQL service applies<br> kms_key_id: sting,optional # the ID of the KMS key which to encrypt the MySQL data<br> domain_suffix: string # a private DNS namespace of the CloudMap where to register the applied MySQL service</pre> | <pre>object({<br> vpc_id = string<br> kms_key_id = optional(string)<br> domain_suffix = string<br> })</pre> | n/a | yes |
77+
| <a name="input_architecture"></a> [architecture](#input\_architecture) | Specify the deployment architecture, select from standalone or replication. | `string` | `"standalone"` | no |
78+
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | Specify the deployment engine version. | `string` | `"7.0"` | no |
79+
| <a name="input_engine_parameters"></a> [engine\_parameters](#input\_engine\_parameters) | Specify the deployment parameters. | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
80+
| <a name="input_password"></a> [password](#input\_password) | Specify the account password. | `string` | `null` | no |
81+
| <a name="input_resources"></a> [resources](#input\_resources) | Specify the computing resources.<br>Examples:<pre>resources:<br> nodeType: string, optional # https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/CacheNodes.SupportedTypes.html</pre> | <pre>object({<br> nodeType = optional(string, "cache.t2.micro")<br> })</pre> | <pre>{<br> "nodeType": "cache.t2.micro"<br>}</pre> | no |
4682

4783
## Outputs
4884

4985
| Name | Description |
5086
|------|-------------|
51-
| <a name="output_walrus_project_name"></a> [walrus\_project\_name](#output\_walrus\_project\_name) | The name of project where deployed in Walrus. |
52-
| <a name="output_walrus_project_id"></a> [walrus\_project\_id](#output\_walrus\_project\_id) | The id of project where deployed in Walrus. |
53-
| <a name="output_walrus_environment_name"></a> [walrus\_environment\_name](#output\_walrus\_environment\_name) | The name of environment where deployed in Walrus. |
54-
| <a name="output_walrus_environment_id"></a> [walrus\_environment\_id](#output\_walrus\_environment\_id) | The id of environment where deployed in Walrus. |
55-
| <a name="output_walrus_resource_name"></a> [walrus\_resource\_name](#output\_walrus\_resource\_name) | The name of resource where deployed in Walrus. |
56-
| <a name="output_walrus_resource_id"></a> [walrus\_resource\_id](#output\_walrus\_resource\_id) | The id of resource where deployed in Walrus. |
57-
| <a name="output_submodule"></a> [submodule](#output\_submodule) | The message from submodule. |
87+
| <a name="output_context"></a> [context](#output\_context) | The input context, a map, which is used for orchestration. |
88+
| <a name="output_selector"></a> [selector](#output\_selector) | The selector, a map, which is used for dependencies or collaborations. |
89+
| <a name="output_endpoint_internal"></a> [endpoint\_internal](#output\_endpoint\_internal) | The internal endpoints, a string list, which are used for internal access. |
90+
| <a name="output_endpoint_internal_readonly"></a> [endpoint\_internal\_readonly](#output\_endpoint\_internal\_readonly) | The internal readonly endpoints, a string list, which are used for internal readonly access. |
91+
| <a name="output_password"></a> [password](#output\_password) | The password of redis service. |
5892
<!-- END_TF_DOCS -->
5993

6094
## License

examples/hello-world/README.md

-35
This file was deleted.

examples/hello-world/main.tf

-34
This file was deleted.

examples/hello-world/variables.tftest.hcl

-13
This file was deleted.

examples/replication/README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Replication Example
2+
3+
Deploy Redis service in replication architecture by root module.
4+
5+
```bash
6+
# setup infra
7+
$ terraform apply -auto-approve \
8+
-target=aws_vpc.example \
9+
-target=aws_subnet.example \
10+
-target=aws_kms_key.example \
11+
-target=aws_service_discovery_private_dns_namespace.example
12+
13+
# create service
14+
$ terraform apply -auto-approve
15+
```
16+
17+
<!-- BEGIN_TF_DOCS -->
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.24.0 |
24+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.5.1 |
25+
26+
## Providers
27+
28+
| Name | Version |
29+
|------|---------|
30+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.24.0 |
31+
32+
## Modules
33+
34+
| Name | Source | Version |
35+
|------|--------|---------|
36+
| <a name="module_this"></a> [this](#module\_this) | ../.. | n/a |
37+
38+
## Resources
39+
40+
| Name | Type |
41+
|------|------|
42+
| [aws_internet_gateway.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/internet_gateway) | resource |
43+
| [aws_kms_key.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
44+
| [aws_route.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route) | resource |
45+
| [aws_service_discovery_private_dns_namespace.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/service_discovery_private_dns_namespace) | resource |
46+
| [aws_subnet.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet) | resource |
47+
| [aws_vpc.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc) | resource |
48+
| [aws_availability_zones.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
49+
50+
## Inputs
51+
52+
No inputs.
53+
54+
## Outputs
55+
56+
| Name | Description |
57+
|------|-------------|
58+
| <a name="output_context"></a> [context](#output\_context) | n/a |
59+
| <a name="output_selector"></a> [selector](#output\_selector) | n/a |
60+
| <a name="output_endpoint_internal"></a> [endpoint\_internal](#output\_endpoint\_internal) | n/a |
61+
| <a name="output_endpoint_internal_readonly"></a> [endpoint\_internal\_readonly](#output\_endpoint\_internal\_readonly) | n/a |
62+
| <a name="output_password"></a> [password](#output\_password) | n/a |
63+
<!-- END_TF_DOCS -->

examples/replication/main.tf

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
random = {
6+
source = "hashicorp/random"
7+
version = ">= 3.5.1"
8+
}
9+
aws = {
10+
source = "hashicorp/aws"
11+
version = ">= 5.24.0"
12+
}
13+
}
14+
}
15+
16+
provider "aws" {}
17+
18+
data "aws_availability_zones" "selected" {
19+
state = "available"
20+
21+
lifecycle {
22+
postcondition {
23+
condition = length(self.names) > 0
24+
error_message = "Failed to get Avaialbe Zones"
25+
}
26+
}
27+
}
28+
29+
# create vpc.
30+
31+
resource "aws_vpc" "example" {
32+
instance_tenancy = "default"
33+
enable_dns_hostnames = true
34+
enable_dns_support = true
35+
cidr_block = "10.0.0.0/16"
36+
}
37+
38+
resource "aws_subnet" "example" {
39+
for_each = {
40+
for k, v in data.aws_availability_zones.selected.names : v => cidrsubnet(aws_vpc.example.cidr_block, 8, k)
41+
}
42+
43+
vpc_id = aws_vpc.example.id
44+
availability_zone = each.key
45+
cidr_block = each.value
46+
}
47+
48+
#resource "aws_internet_gateway" "example" {
49+
# vpc_id = aws_vpc.example.id
50+
#}
51+
#
52+
#resource "aws_route" "example" {
53+
# destination_cidr_block = "0.0.0.0/0"
54+
# route_table_id = aws_vpc.example.default_route_table_id
55+
# gateway_id = aws_internet_gateway.example.id
56+
#}
57+
58+
# create kms key.
59+
60+
resource "aws_kms_key" "example" {
61+
key_usage = "ENCRYPT_DECRYPT"
62+
customer_master_key_spec = "SYMMETRIC_DEFAULT"
63+
deletion_window_in_days = 7
64+
is_enabled = true
65+
enable_key_rotation = false
66+
multi_region = true
67+
description = "redis-encryption"
68+
}
69+
70+
# create private dns.
71+
72+
resource "aws_service_discovery_private_dns_namespace" "example" {
73+
name = "example-dev-dns"
74+
vpc = aws_vpc.example.id
75+
}
76+
77+
# create mysql service.
78+
79+
module "this" {
80+
source = "../.."
81+
82+
infrastructure = {
83+
vpc_id = aws_vpc.example.id
84+
kms_key_id = aws_kms_key.example.id
85+
domain_suffix = aws_service_discovery_private_dns_namespace.example.name
86+
}
87+
88+
architecture = "replication"
89+
90+
depends_on = [aws_service_discovery_private_dns_namespace.example]
91+
}
92+
93+
output "context" {
94+
value = module.this.context
95+
}
96+
97+
output "selector" {
98+
value = module.this.selector
99+
}
100+
101+
output "endpoint_internal" {
102+
value = module.this.endpoint_internal
103+
}
104+
105+
output "endpoint_internal_readonly" {
106+
value = module.this.endpoint_internal_readonly
107+
}
108+
109+
output "password" {
110+
value = nonsensitive(module.this.password)
111+
}

0 commit comments

Comments
 (0)