Skip to content

Commit

Permalink
Merge pull request #7 from synapsestudios/6-prefix-dynamo-table
Browse files Browse the repository at this point in the history
Inherit dynamo table name from s3 bucket name
  • Loading branch information
chrisshiplet authored Feb 22, 2023
2 parents 06b5ddc + aaef559 commit 6640637
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <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 |
| <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 |
| <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 |
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to the resources | `map(string)` | `{}` | no |
| <a name="input_use_kms"></a> [use\_kms](#input\_use\_kms) | Whether to use KMS encryption or not | `bool` | `false` | no |
Expand All @@ -93,6 +93,7 @@ No modules.

| Name | Description |
|------|-------------|
| <a name="output_dynamo_table_name"></a> [dynamo\_table\_name](#output\_dynamo\_table\_name) | The name of the dynamoDB table |
| <a name="output_kms_key_id"></a> [kms\_key\_id](#output\_kms\_key\_id) | The provisioned KMS key id |
| <a name="output_s3_bucket_id"></a> [s3\_bucket\_id](#output\_s3\_bucket\_id) | The name of the s3 terraform backend bucket |
<!-- END_TF_DOCS -->
2 changes: 1 addition & 1 deletion dynamo.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_dynamodb_table" "this" {
name = "terraform_state_lock"
name = aws_s3_bucket.this.bucket
hash_key = "LockID"
billing_mode = "PAY_PER_REQUEST"

Expand Down
2 changes: 1 addition & 1 deletion log.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_s3_bucket" "this-logs" {
bucket_prefix = "${var.bucket_prefix}-logs"
bucket_prefix = "${var.name_prefix}-tf-state-logs"
tags = var.tags
}

Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_s3_bucket" "this" {
bucket_prefix = var.bucket_prefix
bucket_prefix = "${var.name_prefix}-tf-state"
tags = var.tags
}

Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ output "s3_bucket_id" {
value = aws_s3_bucket.this.id
description = "The name of the s3 terraform backend bucket"
}

output "dynamo_table_name" {
value = aws_dynamodb_table.this.name
description = "The name of the dynamoDB table"
}
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
variable "bucket_prefix" {
variable "name_prefix" {
type = string
description = "The name to give the bucket where the statefile will be stored (Must be 32 characters or less)"
description = "The name to give the bucket and Dynamo table where the statefile and locks will be stored (Must be 23 characters or less)"
}

variable "use_kms" {
Expand Down

0 comments on commit 6640637

Please sign in to comment.