Skip to content

Commit

Permalink
Add "enable" flag (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Sep 5, 2019
1 parent 24629c1 commit 0ce61ff
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Available targets:
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
| description | The description of the key as viewed in AWS console | string | `Parameter Store KMS master key` | no |
| enable_key_rotation | Specifies whether key rotation is enabled | string | `true` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| name | Application or solution name (e.g. `app`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| policy | A valid kms policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. | string | `` | no |
Expand Down Expand Up @@ -246,7 +247,7 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
|---|

[aknysh_homepage]: https://github.com/aknysh
[aknysh_avatar]: https://github.com/aknysh.png?size=150
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png



Expand Down
1 change: 1 addition & 0 deletions docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
| description | The description of the key as viewed in AWS console | string | `Parameter Store KMS master key` | no |
| enable_key_rotation | Specifies whether key rotation is enabled | string | `true` | no |
| enabled | Set to false to prevent the module from creating any resources | string | `true` | no |
| name | Application or solution name (e.g. `app`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| policy | A valid kms policy JSON document. Note that if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan. In this case, please make sure you use the verbose/specific version of the policy. | string | `` | no |
Expand Down
7 changes: 6 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3"
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.11.1"
enabled = "${var.enabled}"
namespace = "${var.namespace}"
stage = "${var.stage}"
name = "${var.name}"
Expand Down Expand Up @@ -33,6 +34,8 @@ module "policy" {
}

resource "aws_kms_key" "default" {
count = "${var.enabled == "true" ? 1 : 0}"

description = "${var.description}"
deletion_window_in_days = "${var.deletion_window_in_days}"
enable_key_rotation = "${var.enable_key_rotation}"
Expand All @@ -41,6 +44,8 @@ resource "aws_kms_key" "default" {
}

resource "aws_kms_alias" "default" {
count = "${var.enabled == "true" ? 1 : 0}"

name = "${coalesce(var.alias, format("alias/%v", module.label.id))}"
target_key_id = "${aws_kms_key.default.id}"
}
8 changes: 4 additions & 4 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
output "key_arn" {
value = "${aws_kms_key.default.arn}"
value = "${join("", aws_kms_key.default.*.arn)}"
description = "Key ARN"
}

output "key_id" {
value = "${aws_kms_key.default.key_id}"
value = "${join("", aws_kms_key.default.*.key_id)}"
description = "Key ID"
}

output "alias_arn" {
value = "${aws_kms_alias.default.arn}"
value = "${join("", aws_kms_alias.default.*.arn)}"
description = "Alias ARN"
}

output "alias_name" {
value = "${aws_kms_alias.default.name}"
value = "${join("", aws_kms_alias.default.*.name)}"
description = "Alias name"
}
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
variable "enabled" {
description = "Set to false to prevent the module from creating any resources"
default = "true"
}

variable "namespace" {
type = "string"
description = "Namespace (e.g. `cp` or `cloudposse`)"
Expand Down

0 comments on commit 0ce61ff

Please sign in to comment.