From fd2053af80ec2738ca75350541df37e8acb2c2d6 Mon Sep 17 00:00:00 2001 From: Maciej Majewski Date: Wed, 19 Feb 2020 03:21:42 +0100 Subject: [PATCH] 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 Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com> --- README.md | 1 + docs/terraform.md | 1 + main.tf | 12 ++++++++---- variables.tf | 5 +++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d717db1..ab4987f 100644 --- a/README.md +++ b/README.md @@ -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) | `` | no | | attributes | Additional attributes (e.g. `state`) | list(string) | `` | 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 | `` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 985434e..f80d5aa 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -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) | `` | no | | attributes | Additional attributes (e.g. `state`) | list(string) | `` | 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 | `` | no | diff --git a/main.tf b/main.tf index f2d6f1a..b217ad4 100644 --- a/main.tf +++ b/main.tf @@ -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" @@ -149,6 +150,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" { lifecycle { ignore_changes = [ + billing_mode, read_capacity, write_capacity, ] @@ -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" @@ -177,6 +180,7 @@ resource "aws_dynamodb_table" "without_server_side_encryption" { lifecycle { ignore_changes = [ + billing_mode, read_capacity, write_capacity, ] diff --git a/variables.tf b/variables.tf index ced6ef6..83784d3 100644 --- a/variables.tf +++ b/variables.tf @@ -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"