|
| 1 | +# aws-terraform-dynamo |
| 2 | + |
| 3 | +This module creates an AWS DynamoDB table. |
| 4 | + |
| 5 | +## Basic Usage |
| 6 | + |
| 7 | +```HCL |
| 8 | +module "basic" { |
| 9 | + source = "git@github.com:rackspace-infrastructure-automation/aws-terraform-dynamo/?ref=v0.0.3" |
| 10 | +
|
| 11 | + attributes = [ |
| 12 | + { |
| 13 | + name = "TestHashKey" |
| 14 | + type = "S" |
| 15 | + }, |
| 16 | + ] |
| 17 | +
|
| 18 | + environment = "Test" |
| 19 | + hash_key = "MyHashKey" |
| 20 | + read_capacity_units = 10 |
| 21 | + table_name = "myexampletable" |
| 22 | + tags = "${local.tags}" |
| 23 | + write_capacity_units = 5 |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +## Known Bugs |
| 28 | + |
| 29 | +When using the index maps for GSI's and LSI's there is a bug in the Terraform AWS provider which stores the order of `non_key_attributes` in the state file in an order that may not match what you pass in. |
| 30 | + |
| 31 | +If a subsequent plan shows changes for your indexes look for lines similar to the below in the output: |
| 32 | + |
| 33 | +``` |
| 34 | +global_secondary_index.1708383685.non_key_attributes.0: "data2" => "" |
| 35 | +global_secondary_index.1708383685.non_key_attributes.1: "data1" => "" |
| 36 | +global_secondary_index.1708383685.non_key_attributes.2: "data3" => "" |
| 37 | +``` |
| 38 | + |
| 39 | +The input data was `["data1", "data2", "data3"]` and we can see that attributes 0, 1, and 2 do not follow this same order. |
| 40 | + |
| 41 | +The resolution at the moment is to edit the list in your map to match the order in the state file. This should result in a clean plan when no other changes are present. |
| 42 | + |
| 43 | +**References:** |
| 44 | + |
| 45 | +[global secondary index always recreated #3828](https://github.com/terraform-providers/terraform-provider-aws/issues/3828) |
| 46 | + |
| 47 | +[DynamoDB Non-Key Attributes Ordering #3807](https://github.com/terraform-providers/terraform-provider-aws/issues/3807) |
| 48 | + |
1 | 49 | ## Inputs |
2 | 50 |
|
3 | 51 | | Name | Description | Type | Default | Required | |
4 | 52 | |------|-------------|:----:|:-----:|:-----:| |
5 | | -| attributes | List of nested attribute definitions. Only required for hash_key (always) and range_key (if used) attributes. Attributes have name and type. Type must be a scalar type: S, N, or B for (S)tring, (N)umber or (B)inary data. i.e. [{ name=<hash_key> type=<data_type>}] | list | n/a | yes | |
| 53 | +| attributes | List of nested attribute definitions. Only required for hash_key's (always) and range_key's (if used) attributes. Attributes have name and type. Type must be a scalar type: S, N, or B for (S)tring, (N)umber or (B)inary data. i.e. [{ name=<hash_key> type=<data_type>}]. Terraform documentation: [A note about attributes](https://www.terraform.io/docs/providers/aws/r/dynamodb_table.html#a-note-about-attributes) | list | n/a | yes | |
6 | 54 | | enable\_pay\_per\_request | Controls how you are charged for read and write throughput and how you manage capacity. If True, DynamoDB charges you for the data reads and writes your application performs on your tables. You do not need to specify how much read and write throughput you expect your application to perform because DynamoDB instantly accommodates your workloads as they ramp up or down. [On-Demand Pricing](https://aws.amazon.com/dynamodb/pricing/on-demand/) If False, you specify the number of `read_capacity_units` and `write_capacity_units` per second that you expect your workload to require. [Provisioned Pricing](https://aws.amazon.com/dynamodb/pricing/provisioned/) | string | `"false"` | no | |
7 | | -| hash\_key | ** Forces new resource ** Must contain only alphanumberic characters, dash (-), underscore (_) or dot (.). Needs to be defined by type in attributes. | string | n/a | yes | |
| 55 | +| environment | Application environment for which this resource is being created. Preferred values are Development, Integration, PreProduction, Production, QA, Staging, or Test. | string | `"Development"` | no | |
| 56 | +| global\_secondary\_index\_maps | A list of maps for each [global secondary index (GSI)](https://www.terraform.io/docs/providers/aws/r/dynamodb_table.html#global_secondary_index-1). Please see [examples](./examples) for usage. | list | `<list>` | no | |
| 57 | +| hash\_key | **Forces new resource!** Must contain only alphanumberic characters, dash (-), underscore (_) or dot (.). Needs to be defined by type in attributes. | string | n/a | yes | |
| 58 | +| local\_secondary\_index\_maps | A list of maps for each [local secondary index (LSI)](https://www.terraform.io/docs/providers/aws/r/dynamodb_table.html#local_secondary_index-1). Please see [examples](./examples) for usage. | list | `<list>` | no | |
8 | 59 | | point\_in\_time\_recovery | Enable point in time recovery for the table. | string | `"false"` | no | |
9 | | -| range\_key | ** Forces new resource ** RangeType PrimaryKey Name. If used, it will need to be defined by type in attributes | string | `""` | no | |
| 60 | +| range\_key | **Forces new resource!** RangeType PrimaryKey Name. If used, it will need to be defined by type in attributes | string | `""` | no | |
10 | 61 | | read\_capacity\_units | Provisioned read throughput. Should be between 5 and 10000. Ignored if `enable_pay_per_request` is set to `true`. | string | `"5"` | no | |
11 | | -| table\_encryption | Server side table encryption at rest. i.e. true | false | string | `"true"` | no | |
| 62 | +| stream\_enabled | Enable the stream setting on the table. | string | `"false"` | no | |
| 63 | +| stream\_view\_type | If using `stream_enabled, you can specify a valid DynamoDB StreamViewType; must be one of: `KEYS_ONLY`, `NEW_IMAGE`. `OLD_IMAGE`, `NEW_AND_OLD_IMAGES` | string | `""` | no | |
| 64 | +| table\_encryption\_cmk | You may choose to use an [AWS Managed CMK](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-managed-cmk) by setting this to `true`. Otherwise, server side table encryption defaults to an [AWS Owned CMK](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-owned-cmk). | string | `"false"` | no | |
12 | 65 | | table\_name | The name of the table, this needs to be unique within a region. | string | n/a | yes | |
| 66 | +| tags | Custom tags to apply to all resources. | map | `<map>` | no | |
13 | 67 | | write\_capacity\_units | Provisioned write throughput. Should be between 5 and 10000. Ignored if `enable_pay_per_request` is set to `true`. | string | `"10"` | no | |
14 | 68 |
|
15 | 69 | ## Outputs |
16 | 70 |
|
17 | 71 | | Name | Description | |
18 | 72 | |------|-------------| |
| 73 | +| stream\_arn | ARN for the stream if `stream_enabled` was set to `true`, otherwise returns a string of "null". | |
19 | 74 | | table\_arn | Table ARN | |
20 | 75 | | table\_name | Table Name | |
21 | 76 |
|
0 commit comments