forked from patoarvizu/terraform-kms-encryption
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
13 changed files
with
103 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,51 @@ | ||
# terraform-kms-encryption | ||
# terraform-kms-encryption | ||
|
||
## Modules | ||
|
||
### KMS Key | ||
|
||
Path: `modules/kms_key` | ||
|
||
#### Inputs | ||
|
||
Variable name | Default value | ||
------------- | ------------- | ||
alias_name | | ||
additional_account_ids | [] | ||
|
||
#### Outputs | ||
|
||
* `key_id` | ||
* `key_arn` | ||
|
||
### Secret decryption | ||
|
||
Path: `modules/secret_decryption` | ||
|
||
#### Inputs | ||
|
||
Variable name | Default value | ||
------------- | ------------- | ||
encrypted_secret | | ||
secret_context | {} | ||
|
||
#### Outputs | ||
|
||
* `decrypted_secret` | ||
|
||
### Secret encryption | ||
|
||
Path: `modules/secret_encryption` | ||
|
||
#### Inputs | ||
|
||
Variable name | Default value | ||
------------- | ------------- | ||
alias_name | | ||
text_to_encrypt | | ||
secret_context | {} | ||
|
||
#### Outputs | ||
|
||
* `encrypted_secret` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
data "aws_caller_identity" "current" {} | ||
|
||
data "aws_iam_policy_document" "policy" { | ||
policy_id = "key-default-1" | ||
version = "2012-10-17" | ||
|
||
statement { | ||
sid = "Enable IAM User Permissions" | ||
effect = "Allow" | ||
actions = ["kms:*"] | ||
resources = ["*"] | ||
|
||
principals { | ||
type = "AWS" | ||
identifiers = ["${formatlist("arn:aws:iam::%s:root", local.accounts_with_permissions)}"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
locals { | ||
accounts_with_permissions = ["${concat(list(data.aws_caller_identity.current.account_id), var.additional_account_ids)}"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
resource "aws_kms_key" "key" {} | ||
resource "aws_kms_key" "key" { | ||
policy = "${data.aws_iam_policy_document.policy.json}" | ||
} | ||
|
||
resource "aws_kms_alias" "alias" { | ||
name = "alias/${var.alias_name}" | ||
name = "alias/${var.alias_name}" | ||
target_key_id = "${aws_kms_key.key.key_id}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ output "key_id" { | |
|
||
output "key_arn" { | ||
value = "${aws_kms_key.key.arn}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
variable "alias_name" { | ||
type = "string" | ||
type = "string" | ||
description = "The alias for the main key" | ||
} | ||
} | ||
|
||
variable "additional_account_ids" { | ||
type = "list" | ||
description = "List of additional account ids with permissions to use the key" | ||
default = [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
data "aws_kms_secrets" "secret" { | ||
secret { | ||
name = "decrypted_secret" | ||
name = "decrypted_secret" | ||
payload = "${var.encrypted_secret}" | ||
context = "${var.secret_context}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
output "decrypted_secret" { | ||
value = "${data.aws_kms_secrets.secret.plaintext.decrypted_secret}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
variable "encrypted_secret" { | ||
type = "string" | ||
type = "string" | ||
description = "KMS-encrypted secret to be decrypted" | ||
} | ||
|
||
variable "secret_context" { | ||
type = "map" | ||
type = "map" | ||
description = "Encryption context associated with the secret" | ||
default = {} | ||
} | ||
default = {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
data "aws_kms_alias" "alias" { | ||
name = "alias/${var.alias_name}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
data "aws_kms_ciphertext" "secret" { | ||
key_id = "${data.aws_kms_alias.alias.target_key_id}" | ||
key_id = "${data.aws_kms_alias.alias.target_key_id}" | ||
plaintext = "${var.text_to_encrypt}" | ||
context = "${var.secret_context}" | ||
} | ||
context = "${var.secret_context}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
output "encrypted_secret" { | ||
value = "${data.aws_kms_ciphertext.secret.ciphertext_blob}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
variable "alias_name" { | ||
type = "string" | ||
type = "string" | ||
description = "Alias of the KMS key to be used for encryption" | ||
} | ||
|
||
variable "text_to_encrypt" { | ||
type = "string" | ||
type = "string" | ||
description = "Plain text string to be encrypted" | ||
} | ||
|
||
variable "secret_context" { | ||
type = "map" | ||
type = "map" | ||
description = "Context to be associated with the encrypted secret" | ||
default = {} | ||
} | ||
default = {} | ||
} |