-
-
Notifications
You must be signed in to change notification settings - Fork 188
feat: Support aws_dynamodb_resource_policy
(closes #95)
#96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
antonbabenko
merged 5 commits into
terraform-aws-modules:master
from
drosin:feature/95-support-resource-policy
Mar 19, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# DynamoDB Table with resource-based policy example | ||
|
||
Configuration in this directory creates AWS DynamoDB table with a resource-based policy. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.72.1 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_disabled_dynamodb_table"></a> [disabled\_dynamodb\_table](#module\_disabled\_dynamodb\_table) | ../../ | n/a | | ||
| <a name="module_dynamodb_table"></a> [dynamodb\_table](#module\_dynamodb\_table) | ../../ | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_dynamodb_table_arn"></a> [dynamodb\_table\_arn](#output\_dynamodb\_table\_arn) | ARN of the DynamoDB table | | ||
| <a name="output_dynamodb_table_id"></a> [dynamodb\_table\_id](#output\_dynamodb\_table\_id) | ID of the DynamoDB table | | ||
| <a name="output_dynamodb_table_stream_arn"></a> [dynamodb\_table\_stream\_arn](#output\_dynamodb\_table\_stream\_arn) | The ARN of the Table Stream. Only available when var.stream\_enabled is true | | ||
| <a name="output_dynamodb_table_stream_label"></a> [dynamodb\_table\_stream\_label](#output\_dynamodb\_table\_stream\_label) | A timestamp, in ISO 8601 format of the Table Stream. Only available when var.stream\_enabled is true | | ||
<!-- END_TF_DOCS --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
module "dynamodb_table" { | ||
source = "../../" | ||
|
||
name = "my-table-${random_pet.this.id}" | ||
hash_key = "id" | ||
range_key = "title" | ||
table_class = "STANDARD" | ||
deletion_protection_enabled = false | ||
|
||
attributes = [ | ||
{ | ||
name = "id" | ||
type = "N" | ||
}, | ||
{ | ||
name = "title" | ||
type = "S" | ||
}, | ||
{ | ||
name = "age" | ||
type = "N" | ||
} | ||
] | ||
|
||
global_secondary_indexes = [ | ||
{ | ||
name = "TitleIndex" | ||
hash_key = "title" | ||
range_key = "age" | ||
projection_type = "INCLUDE" | ||
non_key_attributes = ["id"] | ||
|
||
on_demand_throughput = { | ||
max_write_request_units = 1 | ||
max_read_request_units = 1 | ||
} | ||
} | ||
] | ||
|
||
on_demand_throughput = { | ||
max_read_request_units = 1 | ||
max_write_request_units = 1 | ||
} | ||
|
||
resource_based_policy_json = <<POLICY | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "AllowDummyRoleAccess", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "arn:aws:iam::222222222222:role/DummyRole" | ||
}, | ||
"Action": "dynamodb:GetItem", | ||
"Resource": "arn:aws:dynamodb:eu-west-1:111111111111:table/DummyTable" | ||
drosin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
] | ||
} | ||
POLICY | ||
# the account ids and table name are placeholders and should be replaced with the actual values | ||
|
||
|
||
tags = { | ||
Terraform = "true" | ||
Environment = "staging" | ||
} | ||
} | ||
|
||
|
||
module "disabled_dynamodb_table" { | ||
source = "../../" | ||
|
||
create_table = false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "dynamodb_table_arn" { | ||
description = "ARN of the DynamoDB table" | ||
value = module.dynamodb_table.dynamodb_table_arn | ||
} | ||
|
||
output "dynamodb_table_id" { | ||
description = "ID of the DynamoDB table" | ||
value = module.dynamodb_table.dynamodb_table_id | ||
} | ||
|
||
output "dynamodb_table_stream_arn" { | ||
description = "The ARN of the Table Stream. Only available when var.stream_enabled is true" | ||
value = module.dynamodb_table.dynamodb_table_stream_arn | ||
} | ||
|
||
output "dynamodb_table_stream_label" { | ||
description = "A timestamp, in ISO 8601 format of the Table Stream. Only available when var.stream_enabled is true" | ||
value = module.dynamodb_table.dynamodb_table_stream_label | ||
} |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 5.72.1" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.