Skip to content

Commit fd2053a

Browse files
maciejmajewskimaximmiactions-bot
authored
Add possibility to set billing mode for DynamoDB tables (#30)
* Add possibility to set billing mode for DynamoDB tables * Updated README.md Co-authored-by: Maxim Mironenko <simixido@gmail.com> Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com>
1 parent d28ccb2 commit fd2053a

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Available targets:
161161
| acl | The canned ACL to apply to the S3 bucket | string | `private` | no |
162162
| additional_tag_map | Additional tags for appending to each tag map | map(string) | `<map>` | no |
163163
| attributes | Additional attributes (e.g. `state`) | list(string) | `<list>` | no |
164+
| billing_mode | DynamoDB billing mode | string | `PROVISIONED` | no |
164165
| block_public_acls | Whether Amazon S3 should block public ACLs for this bucket | bool | `true` | no |
165166
| block_public_policy | Whether Amazon S3 should block public bucket policies for this bucket | string | `true` | no |
166167
| context | Default context to use for passing state between label invocations | object | `<map>` | no |

docs/terraform.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
| acl | The canned ACL to apply to the S3 bucket | string | `private` | no |
66
| additional_tag_map | Additional tags for appending to each tag map | map(string) | `<map>` | no |
77
| attributes | Additional attributes (e.g. `state`) | list(string) | `<list>` | no |
8+
| billing_mode | DynamoDB billing mode | string | `PROVISIONED` | no |
89
| block_public_acls | Whether Amazon S3 should block public ACLs for this bucket | bool | `true` | no |
910
| block_public_policy | Whether Amazon S3 should block public bucket policies for this bucket | string | `true` | no |
1011
| context | Default context to use for passing state between label invocations | object | `<map>` | no |

main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ module "dynamodb_table_label" {
133133
resource "aws_dynamodb_table" "with_server_side_encryption" {
134134
count = var.enable_server_side_encryption ? 1 : 0
135135
name = module.dynamodb_table_label.id
136-
read_capacity = var.read_capacity
137-
write_capacity = var.write_capacity
136+
billing_mode = var.billing_mode
137+
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
138+
write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null
138139

139140
# https://www.terraform.io/docs/backends/types/s3.html#dynamodb_table
140141
hash_key = "LockID"
@@ -149,6 +150,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
149150

150151
lifecycle {
151152
ignore_changes = [
153+
billing_mode,
152154
read_capacity,
153155
write_capacity,
154156
]
@@ -165,8 +167,9 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
165167
resource "aws_dynamodb_table" "without_server_side_encryption" {
166168
count = var.enable_server_side_encryption ? 0 : 1
167169
name = module.dynamodb_table_label.id
168-
read_capacity = var.read_capacity
169-
write_capacity = var.write_capacity
170+
billing_mode = var.billing_mode
171+
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
172+
write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null
170173

171174
# https://www.terraform.io/docs/backends/types/s3.html#dynamodb_table
172175
hash_key = "LockID"
@@ -177,6 +180,7 @@ resource "aws_dynamodb_table" "without_server_side_encryption" {
177180

178181
lifecycle {
179182
ignore_changes = [
183+
billing_mode,
180184
read_capacity,
181185
write_capacity,
182186
]

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ variable "acl" {
9393
default = "private"
9494
}
9595

96+
variable "billing_mode" {
97+
default = "PROVISIONED"
98+
description = "DynamoDB billing mode"
99+
}
100+
96101
variable "read_capacity" {
97102
default = 5
98103
description = "DynamoDB read capacity units"

0 commit comments

Comments
 (0)