Skip to content

Commit 6d04c3a

Browse files
authored
Merge pull request #6 from samstav/samstav-patch-2
note on using an existing dynamo table for locking
2 parents 5a81037 + 2a3508b commit 6d04c3a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ module "backend" {
4949
}
5050
```
5151

52+
### if using _existing_ backend resources (instead of creating new ones)
53+
54+
#### re-using a DynamoDB lock table across multiple terraform-managed projects
55+
56+
One of the resources created and managed by this module is the DynamoDB Table for [terraform locking](https://www.terraform.io/docs/state/locking.html). This module provides a default name: `terraform-lock`. This table may actually be re-used across multiple different projects. In the case that you already have a DynamoDB table you would like to use for locking (or perhaps you are already using this module in another project), you can simply import that dynamodb table:
57+
58+
```
59+
$ terraform import module.backend.aws_dynamodb_table.tf_backend_state_lock_table[0] terraform-lock
60+
```
61+
62+
_(The `[0]` is needed because it is a "conditional resource" and you must refer to the 'count' index when importing, which is always `[0]`)_
63+
64+
Where `backend` is your chosen `terraform-aws-backend` module instance name, and `terraform-lock` is the DynamoDB table name you use for tf state locking.
65+
66+
If you attempt to apply this module without importing the existing DynamoDB table with the same name, you will run into the following error:
67+
68+
```
69+
Error: Error applying plan:
70+
71+
1 error(s) occurred:
72+
73+
* module.backend.aws_dynamodb_table.tf_backend_state_lock_table: 1 error(s) occurred:
74+
75+
* aws_dynamodb_table.tf_backend_state_lock_table: ResourceInUseException: Table already exists: terraform-lock
76+
status code: 400, request id: F35KO0U78JJOIWEJFNJNJHSLDBFF66Q9ASUAAJG
77+
```
78+
5279
### commands are the fun part
5380

5481
The following commands will get you up and running:

0 commit comments

Comments
 (0)