Skip to content

Commit d596c25

Browse files
authored
feat!: Added import table feature and AWS provider v5 upgrade (#77)
Co-authored-by: magreenbaum <magreenbaum>
1 parent 03b38ee commit d596c25

File tree

18 files changed

+320
-11
lines changed

18 files changed

+320
-11
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,21 @@ Users of Terragrunt can achieve similar results by using modules provided in the
5353
- [Basic example](https://github.com/terraform-aws-modules/terraform-aws-dynamodb-table/tree/master/examples/basic)
5454
- [Autoscaling example](https://github.com/terraform-aws-modules/terraform-aws-dynamodb-table/tree/master/examples/autoscaling)
5555
- [Global tables example](https://github.com/terraform-aws-modules/terraform-aws-dynamodb-table/tree/master/examples/global-tables)
56+
- [S3 import examples](https://github.com/terraform-aws-modules/terraform-aws-dynamodb-table/tree/master/examples/s3-import)
5657

5758
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
5859
## Requirements
5960

6061
| Name | Version |
6162
|------|---------|
6263
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
63-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.59 |
64+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
6465

6566
## Providers
6667

6768
| Name | Version |
6869
|------|---------|
69-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.59 |
70+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.21 |
7071

7172
## Modules
7273

@@ -104,6 +105,7 @@ No modules.
104105
| <a name="input_global_secondary_indexes"></a> [global\_secondary\_indexes](#input\_global\_secondary\_indexes) | Describe a GSI for the table; subject to the normal limits on the number of GSIs, projected attributes, etc. | `any` | `[]` | no |
105106
| <a name="input_hash_key"></a> [hash\_key](#input\_hash\_key) | The attribute to use as the hash (partition) key. Must also be defined as an attribute | `string` | `null` | no |
106107
| <a name="input_ignore_changes_global_secondary_index"></a> [ignore\_changes\_global\_secondary\_index](#input\_ignore\_changes\_global\_secondary\_index) | Whether to ignore changes lifecycle to global secondary indices, useful for provisioned tables with scaling | `bool` | `false` | no |
108+
| <a name="input_import_table"></a> [import\_table](#input\_import\_table) | Configurations for importing s3 data into a new table. | `any` | `{}` | no |
107109
| <a name="input_local_secondary_indexes"></a> [local\_secondary\_indexes](#input\_local\_secondary\_indexes) | Describe an LSI on the table; these can only be allocated at creation so you cannot change this definition after you have created the resource. | `any` | `[]` | no |
108110
| <a name="input_name"></a> [name](#input\_name) | Name of the DynamoDB table | `string` | `null` | no |
109111
| <a name="input_point_in_time_recovery_enabled"></a> [point\_in\_time\_recovery\_enabled](#input\_point\_in\_time\_recovery\_enabled) | Whether to enable point-in-time recovery | `bool` | `false` | no |

examples/autoscaling/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.69 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
2424
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2525

2626
## Providers

examples/autoscaling/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 = ">= 3.69"
7+
version = ">= 5.21"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/basic/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.69 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
2424
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2525

2626
## Providers

examples/basic/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 = ">= 3.69"
7+
version = ">= 5.21"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/global-tables/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ Note that this example may create resources which can cost money (AWS Elastic IP
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.23 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
2424
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
2525

2626
## Providers
2727

2828
| Name | Version |
2929
|------|---------|
30-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.23 |
31-
| <a name="provider_aws.euwest2"></a> [aws.euwest2](#provider\_aws.euwest2) | >= 4.23 |
30+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.21 |
31+
| <a name="provider_aws.euwest2"></a> [aws.euwest2](#provider\_aws.euwest2) | >= 5.21 |
3232
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
3333

3434
## Modules

examples/global-tables/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.23"
7+
version = ">= 5.21"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/s3-import/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# DynamoDB Table s3 import example
2+
3+
Configuration in this directory creates an AWS DynamoDB table created from s3 imports (both json and csv examples).
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
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.
16+
17+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
18+
## Requirements
19+
20+
| Name | Version |
21+
|------|---------|
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
24+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |
25+
26+
## Providers
27+
28+
| Name | Version |
29+
|------|---------|
30+
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |
31+
32+
## Modules
33+
34+
| Name | Source | Version |
35+
|------|--------|---------|
36+
| <a name="module_import_csv_table"></a> [import\_csv\_table](#module\_import\_csv\_table) | ../../ | n/a |
37+
| <a name="module_import_json_table"></a> [import\_json\_table](#module\_import\_json\_table) | ../../ | n/a |
38+
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.15 |
39+
| <a name="module_s3_import_object_csv"></a> [s3\_import\_object\_csv](#module\_s3\_import\_object\_csv) | terraform-aws-modules/s3-bucket/aws//modules/object | ~> 3.15 |
40+
| <a name="module_s3_import_object_json"></a> [s3\_import\_object\_json](#module\_s3\_import\_object\_json) | terraform-aws-modules/s3-bucket/aws//modules/object | ~> 3.15 |
41+
42+
## Resources
43+
44+
| Name | Type |
45+
|------|------|
46+
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
47+
48+
## Inputs
49+
50+
No inputs.
51+
52+
## Outputs
53+
54+
| Name | Description |
55+
|------|-------------|
56+
| <a name="output_import_csv_table_arn"></a> [import\_csv\_table\_arn](#output\_import\_csv\_table\_arn) | ARN of the DynamoDB table |
57+
| <a name="output_import_csv_table_id"></a> [import\_csv\_table\_id](#output\_import\_csv\_table\_id) | ID of the DynamoDB table |
58+
| <a name="output_import_csv_table_stream_arn"></a> [import\_csv\_table\_stream\_arn](#output\_import\_csv\_table\_stream\_arn) | The ARN of the Table Stream. Only available when var.stream\_enabled is true |
59+
| <a name="output_import_csv_table_stream_label"></a> [import\_csv\_table\_stream\_label](#output\_import\_csv\_table\_stream\_label) | A timestamp, in ISO 8601 format of the Table Stream. Only available when var.stream\_enabled is true |
60+
| <a name="output_import_json_table_arn"></a> [import\_json\_table\_arn](#output\_import\_json\_table\_arn) | ARN of the DynamoDB table |
61+
| <a name="output_import_json_table_id"></a> [import\_json\_table\_id](#output\_import\_json\_table\_id) | ID of the DynamoDB table |
62+
| <a name="output_import_json_table_stream_arn"></a> [import\_json\_table\_stream\_arn](#output\_import\_json\_table\_stream\_arn) | The ARN of the Table Stream. Only available when var.stream\_enabled is true |
63+
| <a name="output_import_json_table_stream_label"></a> [import\_json\_table\_stream\_label](#output\_import\_json\_table\_stream\_label) | A timestamp, in ISO 8601 format of the Table Stream. Only available when var.stream\_enabled is true |
64+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

examples/s3-import/files/sample.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
id;title
2+
02;csv
3+
03;csvtest

examples/s3-import/files/sample.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{"Item":
2+
{
3+
"id":{"N":"01"},
4+
"title":{"S":"example1"}
5+
}}
6+
7+
{"Item":
8+
{
9+
"id":{"N":"02"},
10+
"title":{"S":"example2"}
11+
}}

examples/s3-import/main.tf

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
resource "random_pet" "this" {
6+
length = 2
7+
}
8+
9+
module "import_json_table" {
10+
source = "../../"
11+
12+
name = "import-json-${random_pet.this.id}"
13+
hash_key = "id"
14+
range_key = "title"
15+
table_class = "STANDARD"
16+
deletion_protection_enabled = false
17+
18+
attributes = [
19+
{
20+
name = "id"
21+
type = "N"
22+
},
23+
{
24+
name = "title"
25+
type = "S"
26+
},
27+
]
28+
29+
import_table = {
30+
input_format = "DYNAMODB_JSON"
31+
input_compression_type = "NONE"
32+
bucket = module.s3_bucket.s3_bucket_id
33+
key_prefix = "import-json-${random_pet.this.id}"
34+
}
35+
36+
tags = {
37+
Terraform = "true"
38+
Environment = "staging"
39+
}
40+
}
41+
42+
module "import_csv_table" {
43+
source = "../../"
44+
45+
name = "import-csv-${random_pet.this.id}"
46+
hash_key = "id"
47+
range_key = "title"
48+
table_class = "STANDARD"
49+
deletion_protection_enabled = false
50+
51+
attributes = [
52+
{
53+
name = "id"
54+
type = "N"
55+
},
56+
{
57+
name = "title"
58+
type = "S"
59+
},
60+
]
61+
62+
import_table = {
63+
input_format = "CSV"
64+
input_compression_type = "NONE"
65+
bucket = module.s3_bucket.s3_bucket_id
66+
key_prefix = "import-csv-${random_pet.this.id}"
67+
input_format_options = {
68+
csv = {
69+
delimiter = ";"
70+
}
71+
}
72+
}
73+
74+
tags = {
75+
Terraform = "true"
76+
Environment = "staging"
77+
}
78+
}
79+
80+
module "s3_bucket" {
81+
source = "terraform-aws-modules/s3-bucket/aws"
82+
version = "~> 3.15"
83+
84+
bucket = "import-example-${random_pet.this.id}"
85+
86+
force_destroy = true
87+
}
88+
89+
module "s3_import_object_json" {
90+
source = "terraform-aws-modules/s3-bucket/aws//modules/object"
91+
version = "~> 3.15"
92+
93+
bucket = module.s3_bucket.s3_bucket_id
94+
key = "import-json-${random_pet.this.id}/sample.json"
95+
96+
content_base64 = filebase64("./files/sample.json")
97+
}
98+
99+
module "s3_import_object_csv" {
100+
source = "terraform-aws-modules/s3-bucket/aws//modules/object"
101+
version = "~> 3.15"
102+
103+
bucket = module.s3_bucket.s3_bucket_id
104+
key = "import-csv-${random_pet.this.id}/sample.csv"
105+
106+
content_base64 = filebase64("./files/sample.csv")
107+
}

examples/s3-import/outputs.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
output "import_json_table_arn" {
2+
description = "ARN of the DynamoDB table"
3+
value = module.import_json_table.dynamodb_table_arn
4+
}
5+
6+
output "import_json_table_id" {
7+
description = "ID of the DynamoDB table"
8+
value = module.import_json_table.dynamodb_table_id
9+
}
10+
11+
output "import_json_table_stream_arn" {
12+
description = "The ARN of the Table Stream. Only available when var.stream_enabled is true"
13+
value = module.import_json_table.dynamodb_table_stream_arn
14+
}
15+
16+
output "import_json_table_stream_label" {
17+
description = "A timestamp, in ISO 8601 format of the Table Stream. Only available when var.stream_enabled is true"
18+
value = module.import_json_table.dynamodb_table_stream_label
19+
}
20+
21+
output "import_csv_table_arn" {
22+
description = "ARN of the DynamoDB table"
23+
value = module.import_csv_table.dynamodb_table_arn
24+
}
25+
26+
output "import_csv_table_id" {
27+
description = "ID of the DynamoDB table"
28+
value = module.import_csv_table.dynamodb_table_id
29+
}
30+
31+
output "import_csv_table_stream_arn" {
32+
description = "The ARN of the Table Stream. Only available when var.stream_enabled is true"
33+
value = module.import_csv_table.dynamodb_table_stream_arn
34+
}
35+
36+
output "import_csv_table_stream_label" {
37+
description = "A timestamp, in ISO 8601 format of the Table Stream. Only available when var.stream_enabled is true"
38+
value = module.import_csv_table.dynamodb_table_stream_label
39+
}

examples/s3-import/variables.tf

Whitespace-only changes.

examples/s3-import/versions.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.21"
8+
}
9+
random = {
10+
source = "hashicorp/random"
11+
version = ">= 2.0"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)