Skip to content

Commit a9dd4f2

Browse files
committed
feat: Make DynamoDB table creation optional
1 parent fdc40f8 commit a9dd4f2

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ See [the official document](https://www.terraform.io/docs/backends/types/s3.html
9696

9797
| Name | Description | Type | Required |
9898
|------|-------------|------|:--------:|
99+
| <a name="input_create_dynamodb_table"></a> [create\_dynamodb\_table](#input\_create\_dynamodb\_table) | Whether or not to create the DynamoDB table for state locking (it's deprecated for Terraform 1.11+). | `bool` | no |
99100
| <a name="input_dynamodb_deletion_protection_enabled"></a> [dynamodb\_deletion\_protection\_enabled](#input\_dynamodb\_deletion\_protection\_enabled) | Whether or not to enable deletion protection on the DynamoDB table | `bool` | no |
100101
| <a name="input_dynamodb_enable_server_side_encryption"></a> [dynamodb\_enable\_server\_side\_encryption](#input\_dynamodb\_enable\_server\_side\_encryption) | Whether or not to enable encryption at rest using an AWS managed KMS customer master key (CMK) | `bool` | no |
101102
| <a name="input_dynamodb_table_billing_mode"></a> [dynamodb\_table\_billing\_mode](#input\_dynamodb\_table\_billing\_mode) | Controls how you are charged for read and write throughput and how you manage capacity. | `string` | no |

dynamo.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ locals {
1010
}
1111

1212
resource "aws_dynamodb_table" "lock" {
13+
count = var.create_dynamodb_table ? 1 : 0
14+
1315
name = var.dynamodb_table_name
1416
billing_mode = var.dynamodb_table_billing_mode
1517
hash_key = local.lock_key_id

migrations.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# --------------------------------------------------------------------------------------------------
2-
# Migrations to 0.7.0
2+
# Migrations
33
# --------------------------------------------------------------------------------------------------
44

55
moved {
@@ -22,3 +22,7 @@ moved {
2222
to = aws_s3_bucket_policy.replica_force_ssl[0]
2323
}
2424

25+
moved {
26+
from = aws_dynamodb_table.lock
27+
to = aws_dynamodb_table.lock[0]
28+
}

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ output "replica_bucket" {
2020

2121
output "dynamodb_table" {
2222
description = "The DynamoDB table to manage lock states."
23-
value = aws_dynamodb_table.lock
23+
value = var.create_dynamodb_table ? aws_dynamodb_table.lock[0] : null
2424
}
2525

2626
output "kms_key_replica" {

policy.tf

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ data "aws_iam_policy_document" "terraform" {
2626
resources = ["${aws_s3_bucket.state.arn}/*"]
2727
}
2828

29-
statement {
30-
actions = [
31-
"dynamodb:GetItem",
32-
"dynamodb:PutItem",
33-
"dynamodb:DeleteItem",
34-
"dynamodb:DescribeTable"
35-
]
36-
resources = [aws_dynamodb_table.lock[0].arn]
29+
dynamic "statement" {
30+
for_each = var.create_dynamodb_table ? [1] : []
31+
content {
32+
actions = [
33+
"dynamodb:GetItem",
34+
"dynamodb:PutItem",
35+
"dynamodb:DeleteItem",
36+
"dynamodb:DescribeTable"
37+
]
38+
resources = [aws_dynamodb_table.lock[0].arn]
39+
}
3740
}
3841

3942
statement {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ variable "s3_logging_target_prefix" {
154154
# DynamoDB Table for State Locking
155155
#---------------------------------------------------------------------------------------------------
156156

157+
variable "create_dynamodb_table" {
158+
description = "Whether or not to create the DynamoDB table for state locking (it's deprecated for Terraform 1.11+)."
159+
type = bool
160+
default = true
161+
}
162+
157163
variable "dynamodb_table_name" {
158164
description = "The name of the DynamoDB table to use for state locking."
159165
type = string

0 commit comments

Comments
 (0)