Skip to content

Commit

Permalink
Add possibility to set billing mode for DynamoDB tables (#30)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Feb 19, 2020
1 parent d28ccb2 commit fd2053a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ Available targets:
| acl | The canned ACL to apply to the S3 bucket | string | `private` | no |
| additional_tag_map | Additional tags for appending to each tag map | map(string) | `<map>` | no |
| attributes | Additional attributes (e.g. `state`) | list(string) | `<list>` | no |
| billing_mode | DynamoDB billing mode | string | `PROVISIONED` | no |
| block_public_acls | Whether Amazon S3 should block public ACLs for this bucket | bool | `true` | no |
| block_public_policy | Whether Amazon S3 should block public bucket policies for this bucket | string | `true` | no |
| context | Default context to use for passing state between label invocations | object | `<map>` | no |
Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| acl | The canned ACL to apply to the S3 bucket | string | `private` | no |
| additional_tag_map | Additional tags for appending to each tag map | map(string) | `<map>` | no |
| attributes | Additional attributes (e.g. `state`) | list(string) | `<list>` | no |
| billing_mode | DynamoDB billing mode | string | `PROVISIONED` | no |
| block_public_acls | Whether Amazon S3 should block public ACLs for this bucket | bool | `true` | no |
| block_public_policy | Whether Amazon S3 should block public bucket policies for this bucket | string | `true` | no |
| context | Default context to use for passing state between label invocations | object | `<map>` | no |
Expand Down
12 changes: 8 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ module "dynamodb_table_label" {
resource "aws_dynamodb_table" "with_server_side_encryption" {
count = var.enable_server_side_encryption ? 1 : 0
name = module.dynamodb_table_label.id
read_capacity = var.read_capacity
write_capacity = var.write_capacity
billing_mode = var.billing_mode
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null

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

lifecycle {
ignore_changes = [
billing_mode,
read_capacity,
write_capacity,
]
Expand All @@ -165,8 +167,9 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
resource "aws_dynamodb_table" "without_server_side_encryption" {
count = var.enable_server_side_encryption ? 0 : 1
name = module.dynamodb_table_label.id
read_capacity = var.read_capacity
write_capacity = var.write_capacity
billing_mode = var.billing_mode
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null

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

lifecycle {
ignore_changes = [
billing_mode,
read_capacity,
write_capacity,
]
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ variable "acl" {
default = "private"
}

variable "billing_mode" {
default = "PROVISIONED"
description = "DynamoDB billing mode"
}

variable "read_capacity" {
default = 5
description = "DynamoDB read capacity units"
Expand Down

0 comments on commit fd2053a

Please sign in to comment.