Skip to content

Commit 6640637

Browse files
authored
Merge pull request #7 from synapsestudios/6-prefix-dynamo-table
Inherit dynamo table name from s3 bucket name
2 parents 06b5ddc + aaef559 commit 6640637

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ No modules.
8484

8585
| Name | Description | Type | Default | Required |
8686
|------|-------------|------|---------|:--------:|
87-
| <a name="input_bucket_prefix"></a> [bucket\_prefix](#input\_bucket\_prefix) | The name to give the bucket where the statefile will be stored (Must be 32 characters or less) | `string` | n/a | yes |
87+
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | The name to give the bucket and Dynamo table where the statefile and locks will be stored (Must be 23 characters or less) | `string` | n/a | yes |
8888
| <a name="input_principal_arns"></a> [principal\_arns](#input\_principal\_arns) | List of ARNs to grant access to the KMS key (if use\_kms is true) | `list(string)` | `[]` | no |
8989
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to the resources | `map(string)` | `{}` | no |
9090
| <a name="input_use_kms"></a> [use\_kms](#input\_use\_kms) | Whether to use KMS encryption or not | `bool` | `false` | no |
@@ -93,6 +93,7 @@ No modules.
9393

9494
| Name | Description |
9595
|------|-------------|
96+
| <a name="output_dynamo_table_name"></a> [dynamo\_table\_name](#output\_dynamo\_table\_name) | The name of the dynamoDB table |
9697
| <a name="output_kms_key_id"></a> [kms\_key\_id](#output\_kms\_key\_id) | The provisioned KMS key id |
9798
| <a name="output_s3_bucket_id"></a> [s3\_bucket\_id](#output\_s3\_bucket\_id) | The name of the s3 terraform backend bucket |
9899
<!-- END_TF_DOCS -->

dynamo.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_dynamodb_table" "this" {
2-
name = "terraform_state_lock"
2+
name = aws_s3_bucket.this.bucket
33
hash_key = "LockID"
44
billing_mode = "PAY_PER_REQUEST"
55

log.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_s3_bucket" "this-logs" {
2-
bucket_prefix = "${var.bucket_prefix}-logs"
2+
bucket_prefix = "${var.name_prefix}-tf-state-logs"
33
tags = var.tags
44
}
55

main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "aws_s3_bucket" "this" {
2-
bucket_prefix = var.bucket_prefix
2+
bucket_prefix = "${var.name_prefix}-tf-state"
33
tags = var.tags
44
}
55

outputs.tf

+5
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ output "s3_bucket_id" {
77
value = aws_s3_bucket.this.id
88
description = "The name of the s3 terraform backend bucket"
99
}
10+
11+
output "dynamo_table_name" {
12+
value = aws_dynamodb_table.this.name
13+
description = "The name of the dynamoDB table"
14+
}

variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
variable "bucket_prefix" {
1+
variable "name_prefix" {
22
type = string
3-
description = "The name to give the bucket where the statefile will be stored (Must be 32 characters or less)"
3+
description = "The name to give the bucket and Dynamo table where the statefile and locks will be stored (Must be 23 characters or less)"
44
}
55

66
variable "use_kms" {

0 commit comments

Comments
 (0)