Skip to content

Commit

Permalink
Enable dynamodb switch (#65)
Browse files Browse the repository at this point in the history
* Update variables.tf

* Update main.tf

* Updated README.md

Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com>
  • Loading branch information
nitrocode and actions-bot authored Sep 16, 2020
1 parent 6126606 commit 41a9aa5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ Available targets:
```
<!-- markdownlint-restore -->
<!-- markdownlint-disable -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -222,6 +223,7 @@ Available targets:
| block\_public\_policy | Whether Amazon S3 should block public bucket policies for this bucket | `bool` | `true` | no |
| context | Default context to use for passing state between label invocations | <pre>object({<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> enabled = bool<br> delimiter = string<br> attributes = list(string)<br> label_order = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": "",<br> "enabled": true,<br> "environment": "",<br> "label_order": [],<br> "name": "",<br> "namespace": "",<br> "regex_replace_chars": "",<br> "stage": "",<br> "tags": {}<br>}</pre> | no |
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | `string` | `"-"` | no |
| enable\_dynamodb | Enable DynamoDB Locking | `bool` | `true` | no |
| enable\_point\_in\_time\_recovery | Enable DynamoDB point-in-time recovery | `bool` | `false` | no |
| enable\_public\_access\_block | Enable Bucket Public Access Block | `bool` | `true` | no |
| enable\_server\_side\_encryption | Enable DynamoDB server-side encryption | `bool` | `true` | no |
Expand Down Expand Up @@ -261,6 +263,7 @@ Available targets:
| s3\_bucket\_id | S3 bucket ID |
| terraform\_backend\_config | Rendered Terraform backend config file |

<!-- markdownlint-restore -->



Expand Down
3 changes: 3 additions & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- markdownlint-disable -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -29,6 +30,7 @@
| block\_public\_policy | Whether Amazon S3 should block public bucket policies for this bucket | `bool` | `true` | no |
| context | Default context to use for passing state between label invocations | <pre>object({<br> namespace = string<br> environment = string<br> stage = string<br> name = string<br> enabled = bool<br> delimiter = string<br> attributes = list(string)<br> label_order = list(string)<br> tags = map(string)<br> additional_tag_map = map(string)<br> regex_replace_chars = string<br> })</pre> | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": "",<br> "enabled": true,<br> "environment": "",<br> "label_order": [],<br> "name": "",<br> "namespace": "",<br> "regex_replace_chars": "",<br> "stage": "",<br> "tags": {}<br>}</pre> | no |
| delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes` | `string` | `"-"` | no |
| enable\_dynamodb | Enable DynamoDB Locking | `bool` | `true` | no |
| enable\_point\_in\_time\_recovery | Enable DynamoDB point-in-time recovery | `bool` | `false` | no |
| enable\_public\_access\_block | Enable Bucket Public Access Block | `bool` | `true` | no |
| enable\_server\_side\_encryption | Enable DynamoDB server-side encryption | `bool` | `true` | no |
Expand Down Expand Up @@ -68,3 +70,4 @@
| s3\_bucket\_id | S3 bucket ID |
| terraform\_backend\_config | Rendered Terraform backend config file |

<!-- markdownlint-restore -->
5 changes: 3 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,13 @@ resource "aws_s3_bucket_public_access_block" "default" {

module "dynamodb_table_label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.17.0"
enabled = var.enable_dynamodb
context = module.base_label.context
attributes = compact(concat(var.attributes, ["lock"]))
}

resource "aws_dynamodb_table" "with_server_side_encryption" {
count = var.enable_server_side_encryption ? 1 : 0
count = var.enable_dynamodb && var.enable_server_side_encryption ? 1 : 0
name = module.dynamodb_table_label.id
billing_mode = var.billing_mode
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
Expand Down Expand Up @@ -195,7 +196,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
}

resource "aws_dynamodb_table" "without_server_side_encryption" {
count = var.enable_server_side_encryption ? 0 : 1
count = var.enable_dynamodb && var.enable_server_side_encryption ? 0 : 1
name = module.dynamodb_table_label.id
billing_mode = var.billing_mode
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ variable "enable_public_access_block" {
default = true
}

variable "enable_dynamodb" {
type = bool
description = "Enable DynamoDB Locking"
default = true
}

variable "block_public_acls" {
type = bool
description = "Whether Amazon S3 should block public ACLs for this bucket"
Expand Down

0 comments on commit 41a9aa5

Please sign in to comment.