Skip to content

Commit a4d89d3

Browse files
authored
feat: Add data protection policy support (#43)
Co-authored-by: magreenbaum <magreenbaum>
1 parent 6a639ad commit a4d89d3

File tree

6 files changed

+50
-3
lines changed

6 files changed

+50
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ module "sns_topic" {
135135
| Name | Version |
136136
|------|---------|
137137
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
138-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.56 |
138+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.62 |
139139

140140
## Providers
141141

142142
| Name | Version |
143143
|------|---------|
144-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.56 |
144+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.62 |
145145

146146
## Modules
147147

@@ -152,6 +152,7 @@ No modules.
152152
| Name | Type |
153153
|------|------|
154154
| [aws_sns_topic.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
155+
| [aws_sns_topic_data_protection_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_data_protection_policy) | resource |
155156
| [aws_sns_topic_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_policy) | resource |
156157
| [aws_sns_topic_subscription.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic_subscription) | resource |
157158
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
@@ -166,6 +167,7 @@ No modules.
166167
| <a name="input_create"></a> [create](#input\_create) | Determines whether resources will be created (affects all resources) | `bool` | `true` | no |
167168
| <a name="input_create_subscription"></a> [create\_subscription](#input\_create\_subscription) | Determines whether an SNS subscription is created | `bool` | `true` | no |
168169
| <a name="input_create_topic_policy"></a> [create\_topic\_policy](#input\_create\_topic\_policy) | Determines whether an SNS topic policy is created | `bool` | `true` | no |
170+
| <a name="input_data_protection_policy"></a> [data\_protection\_policy](#input\_data\_protection\_policy) | A map of data protection policy statements | `string` | `null` | no |
169171
| <a name="input_delivery_policy"></a> [delivery\_policy](#input\_delivery\_policy) | The SNS delivery policy | `string` | `null` | no |
170172
| <a name="input_display_name"></a> [display\_name](#input\_display\_name) | The display name for the SNS topic | `string` | `null` | no |
171173
| <a name="input_enable_default_topic_policy"></a> [enable\_default\_topic\_policy](#input\_enable\_default\_topic\_policy) | Specifies whether to enable the default topic policy. Defaults to `true` | `bool` | `true` | no |

examples/complete/main.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ module "default_sns" {
2525
name = "${local.name}-default"
2626
signature_version = 2
2727

28+
data_protection_policy = jsonencode(
29+
{
30+
Description = "Deny Inbound Address"
31+
Name = "DenyInboundEmailAdressPolicy"
32+
Statement = [
33+
{
34+
"DataDirection" = "Inbound"
35+
"DataIdentifier" = [
36+
"arn:aws:dataprotection::aws:data-identifier/EmailAddress",
37+
]
38+
"Operation" = {
39+
"Deny" = {}
40+
}
41+
"Principal" = [
42+
"*",
43+
]
44+
"Sid" = "DenyInboundEmailAddress"
45+
},
46+
]
47+
Version = "2021-06-01"
48+
}
49+
)
50+
2851
tags = local.tags
2952
}
3053

main.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,14 @@ resource "aws_sns_topic_subscription" "this" {
154154
subscription_role_arn = try(each.value.subscription_role_arn, null)
155155
topic_arn = aws_sns_topic.this[0].arn
156156
}
157+
158+
################################################################################
159+
# Data Protection Policy
160+
################################################################################
161+
162+
resource "aws_sns_topic_data_protection_policy" "this" {
163+
count = var.create && var.data_protection_policy != null && !var.fifo_topic ? 1 : 0
164+
165+
arn = aws_sns_topic.this[0].arn
166+
policy = var.data_protection_policy
167+
}

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,13 @@ variable "subscriptions" {
177177
type = any
178178
default = {}
179179
}
180+
181+
################################################################################
182+
# Data Protection Policy
183+
################################################################################
184+
185+
variable "data_protection_policy" {
186+
description = "A map of data protection policy statements"
187+
type = string
188+
default = null
189+
}

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.56"
7+
version = ">= 4.62"
88
}
99
}
1010
}

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ module "wrapper" {
2626
topic_policy_statements = try(each.value.topic_policy_statements, var.defaults.topic_policy_statements, {})
2727
create_subscription = try(each.value.create_subscription, var.defaults.create_subscription, true)
2828
subscriptions = try(each.value.subscriptions, var.defaults.subscriptions, {})
29+
data_protection_policy = try(each.value.data_protection_policy, var.defaults.data_protection_policy, null)
2930
}

0 commit comments

Comments
 (0)