Skip to content

Commit 6c825ee

Browse files
committed
feat(key-value-store): add key-value-stroe module
1 parent 2455c07 commit 6c825ee

File tree

8 files changed

+218
-0
lines changed

8 files changed

+218
-0
lines changed

.github/labeler.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
- any-glob-to-any-file:
1010
- modules/cache-policy/**/*
1111

12+
":floppy_disk: key-value-store":
13+
- changed-files:
14+
- any-glob-to-any-file:
15+
- modules/key-value-store/**/*
16+
1217
":floppy_disk: origin-access-control":
1318
- changed-files:
1419
- any-glob-to-any-file:

.github/labels.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
- color: "fbca04"
4747
description: "This issue or pull request is related to cache-policy module."
4848
name: ":floppy_disk: cache-policy"
49+
- color: "fbca04"
50+
description: "This issue or pull request is related to key-value-store module."
51+
name: ":floppy_disk: key-value-store"
4952
- color: "fbca04"
5053
description: "This issue or pull request is related to origin-access-control module."
5154
name: ":floppy_disk: origin-access-control"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Terraform module which creates CloudFront related resources on AWS.
88

99
- [cache-policy](./modules/cache-policy)
1010
- [distribution](./modules/distribution)
11+
- [key-value-store](./modules/key-value-store)
1112
- [origin-access-control](./modules/origin-access-control)
1213
- [origin-request-policy](./modules/origin-request-policy)
1314
- [response-headers-policy](./modules/response-headers-policy)
@@ -19,6 +20,7 @@ Terraform Modules from [this package](https://github.com/tedilabs/terraform-aws-
1920

2021
- **AWS CloudFront**
2122
- Distribution
23+
- Key-value Store
2224
- Real-time Log Configuration (Comming soon!)
2325
- Origin Access
2426
- Origin Access Control

modules/key-value-store/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# key-value-store
2+
3+
This module creates following resources.
4+
5+
- `aws_cloudfront_key_value_store`
6+
- `aws_cloudfrontkeyvaluestore_key` (optional)
7+
- `aws_cloudfrontkeyvaluestore_keys_exclusive` (optional)
8+
9+
<!-- BEGIN_TF_DOCS -->
10+
## Requirements
11+
12+
| Name | Version |
13+
|------|---------|
14+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6 |
15+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.100 |
16+
17+
## Providers
18+
19+
| Name | Version |
20+
|------|---------|
21+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 6.10.0 |
22+
23+
## Modules
24+
25+
No modules.
26+
27+
## Resources
28+
29+
| Name | Type |
30+
|------|------|
31+
| [aws_cloudfront_key_value_store.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfront_key_value_store) | resource |
32+
| [aws_cloudfrontkeyvaluestore_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfrontkeyvaluestore_key) | resource |
33+
| [aws_cloudfrontkeyvaluestore_keys_exclusive.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudfrontkeyvaluestore_keys_exclusive) | resource |
34+
35+
## Inputs
36+
37+
| Name | Description | Type | Default | Required |
38+
|------|-------------|------|---------|:--------:|
39+
| <a name="input_name"></a> [name](#input\_name) | (Required) Unique name of the CloudFront Key-Value Store. | `string` | n/a | yes |
40+
| <a name="input_description"></a> [description](#input\_description) | (Optional) The description of the CloudFront Key-Value Store. | `string` | `"Managed by Terraform."` | no |
41+
| <a name="input_exclusive"></a> [exclusive](#input\_exclusive) | (Optional) Whether to manage all keys exclusively. If `true`, all keys not defined in the `keys` variable will be removed from the key-value store. If `false`, keys are managed individually and can coexist with keys managed outside of Terraform. Defaults to `false`. | `bool` | `false` | no |
42+
| <a name="input_items"></a> [items](#input\_items) | (Optional) A map of key-value pairs to store in the CloudFront Key-Value Store. The key is the key name and the value is the value to store. Defaults to `{}`. | `any` | `{}` | no |
43+
| <a name="input_timeouts"></a> [timeouts](#input\_timeouts) | (Optional) How long to wait for the CloudFront Key-Value Store to be created. | <pre>object({<br/> create = optional(string, "30m")<br/> })</pre> | `{}` | no |
44+
45+
## Outputs
46+
47+
| Name | Description |
48+
|------|-------------|
49+
| <a name="output_arn"></a> [arn](#output\_arn) | The ARN of the CloudFront Key-Value Store. |
50+
| <a name="output_description"></a> [description](#output\_description) | The description of the CloudFront Key-Value Store. |
51+
| <a name="output_etag"></a> [etag](#output\_etag) | The ETag of the CloudFront Key-Value Store. |
52+
| <a name="output_exclusive"></a> [exclusive](#output\_exclusive) | Whether all keys are managed exclusively. |
53+
| <a name="output_id"></a> [id](#output\_id) | The ID of the CloudFront Key-Value Store. |
54+
| <a name="output_items"></a> [items](#output\_items) | The map of key-value pairs stored in the CloudFront Key-Value Store. |
55+
| <a name="output_name"></a> [name](#output\_name) | The name of the CloudFront Key-Value Store. |
56+
| <a name="output_updated_at"></a> [updated\_at](#output\_updated\_at) | The date and time when the CloudFront Key-Value Store was last modified. |
57+
<!-- END_TF_DOCS -->

modules/key-value-store/main.tf

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
locals {
2+
metadata = {
3+
package = "terraform-aws-cloudfront"
4+
version = trimspace(file("${path.module}/../../VERSION"))
5+
module = basename(path.module)
6+
name = var.name
7+
}
8+
}
9+
10+
locals {
11+
items = {
12+
for k, v in var.items :
13+
k => jsonencode(v)
14+
}
15+
}
16+
17+
18+
###################################################
19+
# CloudFront Key-Value Store
20+
###################################################
21+
22+
resource "aws_cloudfront_key_value_store" "this" {
23+
name = var.name
24+
comment = var.description
25+
26+
timeouts {
27+
create = var.timeouts.create
28+
}
29+
}
30+
31+
32+
###################################################
33+
# CloudFront Key-Value Store Keys
34+
###################################################
35+
36+
resource "aws_cloudfrontkeyvaluestore_key" "this" {
37+
for_each = var.exclusive ? {} : local.items
38+
39+
key_value_store_arn = aws_cloudfront_key_value_store.this.arn
40+
41+
key = each.key
42+
value = each.value
43+
}
44+
45+
resource "aws_cloudfrontkeyvaluestore_keys_exclusive" "this" {
46+
count = var.exclusive ? 1 : 0
47+
48+
key_value_store_arn = aws_cloudfront_key_value_store.this.arn
49+
50+
dynamic "resource_key_value_pair" {
51+
for_each = local.items
52+
iterator = item
53+
54+
content {
55+
key = item.key
56+
value = item.value
57+
}
58+
}
59+
}

modules/key-value-store/outputs.tf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
output "id" {
2+
description = "The ID of the CloudFront Key-Value Store."
3+
value = aws_cloudfront_key_value_store.this.id
4+
}
5+
6+
output "arn" {
7+
description = "The ARN of the CloudFront Key-Value Store."
8+
value = aws_cloudfront_key_value_store.this.arn
9+
}
10+
11+
output "etag" {
12+
description = "The ETag of the CloudFront Key-Value Store."
13+
value = aws_cloudfront_key_value_store.this.etag
14+
}
15+
16+
output "name" {
17+
description = "The name of the CloudFront Key-Value Store."
18+
value = aws_cloudfront_key_value_store.this.name
19+
}
20+
21+
output "description" {
22+
description = "The description of the CloudFront Key-Value Store."
23+
value = aws_cloudfront_key_value_store.this.comment
24+
}
25+
26+
output "exclusive" {
27+
description = "Whether all keys are managed exclusively."
28+
value = var.exclusive
29+
}
30+
31+
output "items" {
32+
description = "The map of key-value pairs stored in the CloudFront Key-Value Store."
33+
value = local.items
34+
}
35+
36+
output "updated_at" {
37+
description = "The date and time when the CloudFront Key-Value Store was last modified."
38+
value = aws_cloudfront_key_value_store.this.last_modified_time
39+
}
40+
41+
# output "debug" {
42+
# value = {
43+
# for k, v in aws_cloudfront_key_value_store.this :
44+
# k => v
45+
# if !contains(["id", "arn", "name", "comment", "etag", "last_modified_time", "timeouts"], k)
46+
# }
47+
# }
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
variable "name" {
2+
description = "(Required) Unique name of the CloudFront Key-Value Store."
3+
type = string
4+
nullable = false
5+
}
6+
7+
variable "description" {
8+
description = "(Optional) The description of the CloudFront Key-Value Store."
9+
type = string
10+
default = "Managed by Terraform."
11+
nullable = false
12+
}
13+
14+
variable "exclusive" {
15+
description = "(Optional) Whether to manage all keys exclusively. If `true`, all keys not defined in the `keys` variable will be removed from the key-value store. If `false`, keys are managed individually and can coexist with keys managed outside of Terraform. Defaults to `false`."
16+
type = bool
17+
default = false
18+
nullable = false
19+
}
20+
21+
variable "items" {
22+
description = "(Optional) A map of key-value pairs to store in the CloudFront Key-Value Store. The key is the key name and the value is the value to store. Defaults to `{}`."
23+
type = any
24+
default = {}
25+
nullable = false
26+
}
27+
28+
variable "timeouts" {
29+
description = "(Optional) How long to wait for the CloudFront Key-Value Store to be created."
30+
type = object({
31+
create = optional(string, "30m")
32+
})
33+
default = {}
34+
nullable = false
35+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.6"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.100"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)