File tree 5 files changed +27
-19
lines changed
5 files changed +27
-19
lines changed Original file line number Diff line number Diff line change 1
1
data "aws_iam_policy_document" "read" {
2
+ count = var. output_policies ? 1 : 0
2
3
statement {
3
4
effect = " Allow"
4
5
resources = [
@@ -15,6 +16,7 @@ data "aws_iam_policy_document" "read" {
15
16
}
16
17
17
18
data "aws_iam_policy_document" "scan" {
19
+ count = var. output_policies ? 1 : 0
18
20
statement {
19
21
effect = " Allow"
20
22
resources = [
@@ -28,6 +30,7 @@ data "aws_iam_policy_document" "scan" {
28
30
}
29
31
30
32
data "aws_iam_policy_document" "write" {
33
+ count = var. output_policies ? 1 : 0
31
34
statement {
32
35
effect = " Allow"
33
36
resources = [aws_dynamodb_table . this . arn ]
@@ -40,6 +43,7 @@ data "aws_iam_policy_document" "write" {
40
43
}
41
44
42
45
data "aws_iam_policy_document" "delete" {
46
+ count = var. output_policies ? 1 : 0
43
47
statement {
44
48
effect = " Allow"
45
49
resources = [aws_dynamodb_table . this . arn ]
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ resource "aws_dynamodb_table" "this" {
19
19
hash_key = var. hash_key . name
20
20
range_key = try (var. range_key . name , null )
21
21
22
+ deletion_protection_enabled = var. deletion_protection_enabled
23
+
22
24
dynamic "ttl" {
23
25
for_each = var. ttl_attribute != null ? [var . ttl_attribute ] : []
24
26
content {
@@ -88,10 +90,6 @@ resource "aws_dynamodb_table" "this" {
88
90
stream_view_type = var. stream_settings . enabled && var. stream_settings . kinesis == null ? var. stream_settings . view_type : null
89
91
90
92
tags = var. tags
91
-
92
- lifecycle {
93
- prevent_destroy = true
94
- }
95
93
}
96
94
97
95
resource "aws_dynamodb_kinesis_streaming_destination" "this" {
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ output "table" {
3
3
}
4
4
5
5
output "policies" {
6
- value = {
7
- read = data.aws_iam_policy_document.read,
8
- scan = data.aws_iam_policy_document.scan,
9
- write = data.aws_iam_policy_document.write,
10
- delete = data.aws_iam_policy_document.delete,
11
- }
6
+ value = var . output_policies ? {
7
+ read = data.aws_iam_policy_document.read[ 0 ] ,
8
+ scan = data.aws_iam_policy_document.scan[ 0 ] ,
9
+ write = data.aws_iam_policy_document.write[ 0 ] ,
10
+ delete = data.aws_iam_policy_document.delete[ 0 ] ,
11
+ } : null
12
12
}
Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ variable "name" {
2
2
description = " Name of the DynamoDB Table"
3
3
type = string
4
4
}
5
+
5
6
variable "hash_key" {
6
7
description = " Hash key configuration."
7
8
type = object ({
8
9
name = string
9
10
type = optional (string , " S" )
10
11
})
11
12
}
13
+
12
14
variable "range_key" {
13
15
description = " Range key configuration"
14
16
type = object ({
@@ -68,6 +70,12 @@ variable "local_secondary_indexes" {
68
70
default = {}
69
71
}
70
72
73
+ variable "deletion_protection_enabled" {
74
+ description = " Enable deletion protection"
75
+ type = bool
76
+ default = true
77
+ }
78
+
71
79
variable "point_in_time_recovery_enabled" {
72
80
description = " Enable point-in-time recovery (recommended)"
73
81
type = bool
@@ -110,4 +118,10 @@ variable "tags" {
110
118
description = " Resource tags for the table"
111
119
type = map (string )
112
120
default = null
113
- }
121
+ }
122
+
123
+ variable "output_policies" {
124
+ description = " Generate default set of policies for the table"
125
+ type = bool
126
+ default = false
127
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments