Skip to content

Commit 457fe53

Browse files
committed
refactor: publicly accessible
Signed-off-by: thxCode <[email protected]>
1 parent f53793e commit 457fe53

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

.tflint.hcl

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ plugin "terraform" {
33
version = "0.5.0"
44
source = "github.com/terraform-linters/tflint-ruleset-terraform"
55
}
6+
7+
plugin "aws" {
8+
enabled = true
9+
version = "0.27.0"
10+
source = "github.com/terraform-linters/tflint-ruleset-aws"
11+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ No modules.
7575
| Name | Description | Type | Default | Required |
7676
|------|-------------|------|---------|:--------:|
7777
| <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 |
78-
| <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 redis service applies<br> kms_key_id: string, optional # the ID of the KMS key which to encrypt the redis data<br> domain_suffix: string, optional # a private DNS namespace of the CloudMap where to register the applied redis service</pre> | <pre>object({<br> vpc_id = string<br> kms_key_id = optional(string)<br> domain_suffix = optional(string)<br> })</pre> | n/a | yes |
78+
| <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 Redis service applies<br> kms_key_id: string, optional # the ID of the KMS key which to encrypt the Redis data<br> domain_suffix: string, optional # a private DNS namespace of the CloudMap where to register the applied Redis service<br> publicly_accessible: bool # whether the Redis service is publicly accessible</pre> | <pre>object({<br> vpc_id = string<br> kms_key_id = optional(string)<br> domain_suffix = optional(string)<br> publicly_accessible = optional(bool, false)<br> })</pre> | n/a | yes |
7979
| <a name="input_architecture"></a> [architecture](#input\_architecture) | Specify the deployment architecture, select from standalone or replication. | `string` | `"standalone"` | no |
8080
| <a name="input_replication_readonly_replicas"></a> [replication\_readonly\_replicas](#input\_replication\_readonly\_replicas) | Specify the number of read-only replicas under the replication deployment. | `number` | `1` | no |
8181
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | Specify the deployment engine version. | `string` | `"7.0"` | no |

main.tf

+12-11
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ locals {
112112

113113
locals {
114114
version = coalesce(var.engine_version == "6.0" ? "6.x" : var.engine_version, "7.0")
115-
version_family_mapping = {
115+
version_family_map = {
116116
"6.x" = "redis6.x",
117117
"7.0" = "redis7",
118118
}
119+
publicly_accessible = try(var.infrastructure.publicly_accessible, false)
119120
}
120121

121122
# create security group.
@@ -132,12 +133,11 @@ resource "aws_security_group_rule" "target" {
132133
description = local.description
133134

134135
security_group_id = aws_security_group.target.id
135-
136-
type = "ingress"
137-
protocol = "tcp"
138-
cidr_blocks = [data.aws_vpc.selected.cidr_block]
139-
from_port = 6379
140-
to_port = 6379
136+
type = "ingress"
137+
protocol = "tcp"
138+
cidr_blocks = local.publicly_accessible ? ["0.0.0.0/0", data.aws_vpc.selected.cidr_block] : [data.aws_vpc.selected.cidr_block]
139+
from_port = 6379
140+
to_port = 6379
141141
}
142142

143143
resource "aws_elasticache_subnet_group" "target" {
@@ -165,7 +165,7 @@ resource "aws_elasticache_parameter_group" "target" {
165165
description = local.description
166166
tags = local.tags
167167

168-
family = local.version_family_mapping[local.version]
168+
family = local.version_family_map[local.version]
169169

170170
dynamic "parameter" {
171171
for_each = local.parameters
@@ -189,6 +189,7 @@ resource "aws_elasticache_replication_group" "default" {
189189

190190
num_cache_clusters = local.architecture == "replication" ? local.replication_readonly_replicas + 1 : 1
191191

192+
engine = "redis"
192193
engine_version = local.version
193194
parameter_group_name = aws_elasticache_parameter_group.target.name
194195
auth_token = local.password
@@ -198,10 +199,10 @@ resource "aws_elasticache_replication_group" "default" {
198199
transit_encryption_enabled = true
199200
at_rest_encryption_enabled = try(data.aws_kms_key.selected[0].arn != null, true)
200201
kms_key_id = try(data.aws_kms_key.selected[0].arn, null)
201-
snapshot_window = "00:00-05:00"
202-
snapshot_retention_limit = 5
203202

204-
apply_immediately = true
203+
apply_immediately = true
204+
snapshot_window = "00:00-05:00"
205+
snapshot_retention_limit = 5
205206
}
206207

207208
resource "aws_service_discovery_service" "primary" {

schema.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ components:
3434
required:
3535
- vpc_id
3636
properties:
37+
publicly_accessible:
38+
description: |
39+
Specify whether to enable public access. If enabled, the Redis service can be accessed from the public network.
40+
default: false
41+
nullable: true
42+
title: Publicly Accessible
43+
type: boolean
44+
x-walrus-ui:
45+
order: 4
3746
domain_suffix:
3847
title: Domain Suffix
3948
type: string

variables.tf

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ Specify the infrastructure information for deploying.
3535
Examples:
3636
```
3737
infrastructure:
38-
vpc_id: string # the ID of the VPC where the redis service applies
39-
kms_key_id: string, optional # the ID of the KMS key which to encrypt the redis data
40-
domain_suffix: string, optional # a private DNS namespace of the CloudMap where to register the applied redis service
38+
vpc_id: string # the ID of the VPC where the Redis service applies
39+
kms_key_id: string, optional # the ID of the KMS key which to encrypt the Redis data
40+
domain_suffix: string, optional # a private DNS namespace of the CloudMap where to register the applied Redis service
41+
publicly_accessible: bool # whether the Redis service is publicly accessible
4142
```
4243
EOF
4344
type = object({
44-
vpc_id = string
45-
kms_key_id = optional(string)
46-
domain_suffix = optional(string)
45+
vpc_id = string
46+
kms_key_id = optional(string)
47+
domain_suffix = optional(string)
48+
publicly_accessible = optional(bool, false)
4749
})
4850
}
4951

0 commit comments

Comments
 (0)