Skip to content

Commit 80c2c51

Browse files
authored
Convert to TF 0.12. Add tests. Add Codefresh test pipeline (cloudposse#37)
* Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline
1 parent 5451158 commit 80c2c51

24 files changed

+600
-229
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
*.tfstate
66
*.tfstate.*
77

8-
# .tfvars files
9-
*.tfvars
10-
118
**/.idea
129
**/*.iml
1310

.travis.yml

-16
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2018 Cloud Posse, LLC
189+
Copyright 2018-2019 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

+43-41
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![Cloud Posse][logo]](https://cpco.io/homepage)
55

6-
# terraform-aws-dynamodb [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-dynamodb.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-dynamodb) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-dynamodb.svg)](https://github.com/cloudposse/terraform-aws-dynamodb/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
6+
# terraform-aws-dynamodb [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-dynamodb?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1cdacfa7e22eb4aa7ea776) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-dynamodb.svg)](https://github.com/cloudposse/terraform-aws-dynamodb/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)
77

88

99
Terraform module to provision a DynamoDB table with autoscaling.
@@ -48,6 +48,11 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are
4848

4949
## Usage
5050

51+
52+
**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases.
53+
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-dynamodb/releases).
54+
55+
5156
```hcl
5257
module "dynamodb_table" {
5358
source = "git::https://github.com/cloudposse/terraform-aws-dynamodb.git?ref=master"
@@ -62,7 +67,7 @@ module "dynamodb_table" {
6267
autoscale_max_read_capacity = 20
6368
autoscale_min_write_capacity = 5
6469
autoscale_max_write_capacity = 20
65-
enable_autoscaler = "true"
70+
enable_autoscaler = true
6671
}
6772
```
6873

@@ -84,7 +89,7 @@ module "dynamodb_table" {
8489
autoscale_max_read_capacity = 20
8590
autoscale_min_write_capacity = 5
8691
autoscale_max_write_capacity = 20
87-
enable_autoscaler = "true"
92+
enable_autoscaler = true
8893
8994
dynamodb_attributes = [
9095
{
@@ -95,22 +100,26 @@ module "dynamodb_table" {
95100
name = "HighWater"
96101
type = "N"
97102
},
103+
{
104+
name = "Timestamp"
105+
type = "S"
106+
}
98107
]
99108
100109
local_secondary_index_map = [
101-
{
102-
name = "TimestampSortIndex"
103-
range_key = "Timestamp"
104-
projection_type = "INCLUDE"
105-
non_key_attributes = ["HashKey", "RangeKey"]
106-
},
107-
{
108-
name = "HighWaterIndex"
109-
range_key = "Timestamp"
110-
projection_type = "INCLUDE"
111-
non_key_attributes = ["HashKey", "RangeKey"]
112-
}
113-
]
110+
{
111+
name = "TimestampSortIndex"
112+
range_key = "Timestamp"
113+
projection_type = "INCLUDE"
114+
non_key_attributes = ["HashKey", "RangeKey"]
115+
},
116+
{
117+
name = "HighWaterIndex"
118+
range_key = "Timestamp"
119+
projection_type = "INCLUDE"
120+
non_key_attributes = ["HashKey", "RangeKey"]
121+
}
122+
]
114123
115124
global_secondary_index_map = [
116125
{
@@ -121,14 +130,7 @@ module "dynamodb_table" {
121130
read_capacity = 5
122131
projection_type = "INCLUDE"
123132
non_key_attributes = ["HashKey", "RangeKey"]
124-
},
125-
{
126-
name = "HighWaterIndex"
127-
hash_key = "HighWater"
128-
write_capacity = 5
129-
read_capacity = 5
130-
projection_type = "KEYS_ONLY"
131-
},
133+
}
132134
]
133135
}
134136
```
@@ -152,32 +154,32 @@ Available targets:
152154

153155
| Name | Description | Type | Default | Required |
154156
|------|-------------|:----:|:-----:|:-----:|
155-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
156-
| autoscale_max_read_capacity | DynamoDB autoscaling max read capacity | string | `20` | no |
157-
| autoscale_max_write_capacity | DynamoDB autoscaling max write capacity | string | `20` | no |
158-
| autoscale_min_read_capacity | DynamoDB autoscaling min read capacity | string | `5` | no |
159-
| autoscale_min_write_capacity | DynamoDB autoscaling min write capacity | string | `5` | no |
160-
| autoscale_read_target | The target value (in %) for DynamoDB read autoscaling | string | `50` | no |
161-
| autoscale_write_target | The target value (in %) for DynamoDB write autoscaling | string | `50` | no |
157+
| attributes | Additional attributes (e.g. `policy` or `role`) | list(string) | `<list>` | no |
158+
| autoscale_max_read_capacity | DynamoDB autoscaling max read capacity | number | `20` | no |
159+
| autoscale_max_write_capacity | DynamoDB autoscaling max write capacity | number | `20` | no |
160+
| autoscale_min_read_capacity | DynamoDB autoscaling min read capacity | number | `5` | no |
161+
| autoscale_min_write_capacity | DynamoDB autoscaling min write capacity | number | `5` | no |
162+
| autoscale_read_target | The target value (in %) for DynamoDB read autoscaling | number | `50` | no |
163+
| autoscale_write_target | The target value (in %) for DynamoDB write autoscaling | number | `50` | no |
162164
| billing_mode | DynamoDB Billing mode. Can be PROVISIONED or PAY_PER_REQUEST | string | `PROVISIONED` | no |
163165
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
164-
| dynamodb_attributes | Additional DynamoDB attributes in the form of a list of mapped values | list | `<list>` | no |
166+
| dynamodb_attributes | Additional DynamoDB attributes in the form of a list of mapped values | object | `<list>` | no |
165167
| enable_autoscaler | Flag to enable/disable DynamoDB autoscaling | string | `true` | no |
166-
| enable_encryption | Enable DynamoDB server-side encryption | string | `true` | no |
167-
| enable_point_in_time_recovery | Enable DynamoDB point in time recovery | string | `true` | no |
168-
| enable_streams | Enable DynamoDB streams | string | `false` | no |
169-
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
170-
| global_secondary_index_map | Additional global secondary indexes in the form of a list of mapped values | list | `<list>` | no |
168+
| enable_encryption | Enable DynamoDB server-side encryption | bool | `true` | no |
169+
| enable_point_in_time_recovery | Enable DynamoDB point in time recovery | bool | `true` | no |
170+
| enable_streams | Enable DynamoDB streams | bool | `false` | no |
171+
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
172+
| global_secondary_index_map | Additional global secondary indexes in the form of a list of mapped values | object | `<list>` | no |
171173
| hash_key | DynamoDB table Hash Key | string | - | yes |
172174
| hash_key_type | Hash Key type, which must be a scalar type: `S`, `N`, or `B` for (S)tring, (N)umber or (B)inary data | string | `S` | no |
173-
| local_secondary_index_map | Additional local secondary indexes in the form of a list of mapped values | list | `<list>` | no |
175+
| local_secondary_index_map | Additional local secondary indexes in the form of a list of mapped values | object | `<list>` | no |
174176
| name | Name (e.g. `app` or `cluster`) | string | - | yes |
175-
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
177+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
176178
| range_key | DynamoDB table Range Key | string | `` | no |
177179
| range_key_type | Range Key type, which must be a scalar type: `S`, `N`, or `B` for (S)tring, (N)umber or (B)inary data | string | `S` | no |
178-
| stage | Stage (e.g. `prod`, `dev`, `staging`, `infra`) | string | - | yes |
180+
| stage | Stage (e.g. `prod`, `dev`, `staging`, `infra`) | string | `` | no |
179181
| stream_view_type | When an item in the table is modified, what information is written to the stream | string | `` | no |
180-
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
182+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map(string) | `<map>` | no |
181183
| ttl_attribute | DynamoDB table TTL attribute | string | `Expires` | no |
182184

183185
## Outputs

README.yaml

+23-26
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ github_repo: cloudposse/terraform-aws-dynamodb
3333

3434
# Badges to display
3535
badges:
36-
- name: "Build Status"
37-
image: "https://travis-ci.org/cloudposse/terraform-aws-dynamodb.svg?branch=master"
38-
url: "https://travis-ci.org/cloudposse/terraform-aws-dynamodb"
36+
- name: "Codefresh Build Status"
37+
image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-dynamodb?type=cf-1"
38+
url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1cdacfa7e22eb4aa7ea776"
3939
- name: "Latest Release"
4040
image: "https://img.shields.io/github/release/cloudposse/terraform-aws-dynamodb.svg"
4141
url: "https://github.com/cloudposse/terraform-aws-dynamodb/releases/latest"
@@ -92,7 +92,7 @@ usage: |-
9292
autoscale_max_read_capacity = 20
9393
autoscale_min_write_capacity = 5
9494
autoscale_max_write_capacity = 20
95-
enable_autoscaler = "true"
95+
enable_autoscaler = true
9696
}
9797
```
9898
@@ -114,7 +114,7 @@ usage: |-
114114
autoscale_max_read_capacity = 20
115115
autoscale_min_write_capacity = 5
116116
autoscale_max_write_capacity = 20
117-
enable_autoscaler = "true"
117+
enable_autoscaler = true
118118
119119
dynamodb_attributes = [
120120
{
@@ -125,22 +125,26 @@ usage: |-
125125
name = "HighWater"
126126
type = "N"
127127
},
128+
{
129+
name = "Timestamp"
130+
type = "S"
131+
}
128132
]
129133
130134
local_secondary_index_map = [
131-
{
132-
name = "TimestampSortIndex"
133-
range_key = "Timestamp"
134-
projection_type = "INCLUDE"
135-
non_key_attributes = ["HashKey", "RangeKey"]
136-
},
137-
{
138-
name = "HighWaterIndex"
139-
range_key = "Timestamp"
140-
projection_type = "INCLUDE"
141-
non_key_attributes = ["HashKey", "RangeKey"]
142-
}
143-
]
135+
{
136+
name = "TimestampSortIndex"
137+
range_key = "Timestamp"
138+
projection_type = "INCLUDE"
139+
non_key_attributes = ["HashKey", "RangeKey"]
140+
},
141+
{
142+
name = "HighWaterIndex"
143+
range_key = "Timestamp"
144+
projection_type = "INCLUDE"
145+
non_key_attributes = ["HashKey", "RangeKey"]
146+
}
147+
]
144148
145149
global_secondary_index_map = [
146150
{
@@ -151,14 +155,7 @@ usage: |-
151155
read_capacity = 5
152156
projection_type = "INCLUDE"
153157
non_key_attributes = ["HashKey", "RangeKey"]
154-
},
155-
{
156-
name = "HighWaterIndex"
157-
hash_key = "HighWater"
158-
write_capacity = 5
159-
read_capacity = 5
160-
projection_type = "KEYS_ONLY"
161-
},
158+
}
162159
]
163160
}
164161
```

codefresh/test.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '1.0'
2+
3+
stages:
4+
- Prepare
5+
- Test
6+
7+
steps:
8+
wait:
9+
title: Wait
10+
stage: Prepare
11+
image: codefresh/cli:latest
12+
commands:
13+
- codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id'
14+
retry:
15+
maxAttempts: 10
16+
delay: 20
17+
exponentialFactor: 1.1
18+
19+
main_clone:
20+
title: "Clone repository"
21+
type: git-clone
22+
stage: Prepare
23+
description: "Initialize"
24+
repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}
25+
git: CF-default
26+
revision: ${{CF_REVISION}}
27+
28+
clean_init:
29+
title: Prepare build-harness and test-harness
30+
image: ${{TEST_IMAGE}}
31+
stage: Prepare
32+
commands:
33+
- cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
34+
- make init
35+
- git -C build-harness checkout master
36+
- make -C test/ clean init TEST_HARNESS_BRANCH=master
37+
- make -C test/src clean init
38+
- find . -type d -name '.terraform' | xargs rm -rf
39+
- find . -type f -name 'terraform.tfstate*' -exec rm -f {} \;
40+
41+
test:
42+
type: "parallel"
43+
title: "Run tests"
44+
description: "Run all tests in parallel"
45+
stage: Test
46+
steps:
47+
test_readme_lint:
48+
title: "Test README.md updated"
49+
stage: "Test"
50+
image: ${{TEST_IMAGE}}
51+
description: Test "readme/lint"
52+
commands:
53+
- make readme/lint
54+
55+
test_module:
56+
title: Test module with bats
57+
image: ${{TEST_IMAGE}}
58+
stage: Test
59+
commands:
60+
- make -C test/ module
61+
62+
test_examples_complete:
63+
title: Test "examples/complete" with bats
64+
image: ${{TEST_IMAGE}}
65+
stage: Test
66+
commands:
67+
- make -C test/ examples/complete
68+
69+
test_examples_complete_terratest:
70+
title: Test "examples/complete" with terratest
71+
image: ${{TEST_IMAGE}}
72+
stage: Test
73+
commands:
74+
- make -C test/src

docs/terraform.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5-
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
6-
| autoscale_max_read_capacity | DynamoDB autoscaling max read capacity | string | `20` | no |
7-
| autoscale_max_write_capacity | DynamoDB autoscaling max write capacity | string | `20` | no |
8-
| autoscale_min_read_capacity | DynamoDB autoscaling min read capacity | string | `5` | no |
9-
| autoscale_min_write_capacity | DynamoDB autoscaling min write capacity | string | `5` | no |
10-
| autoscale_read_target | The target value (in %) for DynamoDB read autoscaling | string | `50` | no |
11-
| autoscale_write_target | The target value (in %) for DynamoDB write autoscaling | string | `50` | no |
5+
| attributes | Additional attributes (e.g. `policy` or `role`) | list(string) | `<list>` | no |
6+
| autoscale_max_read_capacity | DynamoDB autoscaling max read capacity | number | `20` | no |
7+
| autoscale_max_write_capacity | DynamoDB autoscaling max write capacity | number | `20` | no |
8+
| autoscale_min_read_capacity | DynamoDB autoscaling min read capacity | number | `5` | no |
9+
| autoscale_min_write_capacity | DynamoDB autoscaling min write capacity | number | `5` | no |
10+
| autoscale_read_target | The target value (in %) for DynamoDB read autoscaling | number | `50` | no |
11+
| autoscale_write_target | The target value (in %) for DynamoDB write autoscaling | number | `50` | no |
1212
| billing_mode | DynamoDB Billing mode. Can be PROVISIONED or PAY_PER_REQUEST | string | `PROVISIONED` | no |
1313
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
14-
| dynamodb_attributes | Additional DynamoDB attributes in the form of a list of mapped values | list | `<list>` | no |
14+
| dynamodb_attributes | Additional DynamoDB attributes in the form of a list of mapped values | object | `<list>` | no |
1515
| enable_autoscaler | Flag to enable/disable DynamoDB autoscaling | string | `true` | no |
16-
| enable_encryption | Enable DynamoDB server-side encryption | string | `true` | no |
17-
| enable_point_in_time_recovery | Enable DynamoDB point in time recovery | string | `true` | no |
18-
| enable_streams | Enable DynamoDB streams | string | `false` | no |
19-
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
20-
| global_secondary_index_map | Additional global secondary indexes in the form of a list of mapped values | list | `<list>` | no |
16+
| enable_encryption | Enable DynamoDB server-side encryption | bool | `true` | no |
17+
| enable_point_in_time_recovery | Enable DynamoDB point in time recovery | bool | `true` | no |
18+
| enable_streams | Enable DynamoDB streams | bool | `false` | no |
19+
| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no |
20+
| global_secondary_index_map | Additional global secondary indexes in the form of a list of mapped values | object | `<list>` | no |
2121
| hash_key | DynamoDB table Hash Key | string | - | yes |
2222
| hash_key_type | Hash Key type, which must be a scalar type: `S`, `N`, or `B` for (S)tring, (N)umber or (B)inary data | string | `S` | no |
23-
| local_secondary_index_map | Additional local secondary indexes in the form of a list of mapped values | list | `<list>` | no |
23+
| local_secondary_index_map | Additional local secondary indexes in the form of a list of mapped values | object | `<list>` | no |
2424
| name | Name (e.g. `app` or `cluster`) | string | - | yes |
25-
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
25+
| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no |
2626
| range_key | DynamoDB table Range Key | string | `` | no |
2727
| range_key_type | Range Key type, which must be a scalar type: `S`, `N`, or `B` for (S)tring, (N)umber or (B)inary data | string | `S` | no |
28-
| stage | Stage (e.g. `prod`, `dev`, `staging`, `infra`) | string | - | yes |
28+
| stage | Stage (e.g. `prod`, `dev`, `staging`, `infra`) | string | `` | no |
2929
| stream_view_type | When an item in the table is modified, what information is written to the stream | string | `` | no |
30-
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `<map>` | no |
30+
| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map(string) | `<map>` | no |
3131
| ttl_attribute | DynamoDB table TTL attribute | string | `Expires` | no |
3232

3333
## Outputs

examples/complete/.gitignore

-5
This file was deleted.

0 commit comments

Comments
 (0)