generated from SweetOps/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
379 additions
and
32 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
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
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
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,30 @@ | ||
formatter: markdown | ||
|
||
output: | ||
file: README.md | ||
mode: replace | ||
template: |- | ||
<!-- BEGIN_TF_DOCS --> | ||
{{ .Content }} | ||
<!-- END_TF_DOCS --> | ||
## License | ||
The Apache-2.0 license | ||
sort: | ||
enabled: true | ||
by: required | ||
|
||
settings: | ||
anchor: true | ||
color: true | ||
default: true | ||
description: false | ||
escape: true | ||
hide-empty: false | ||
html: true | ||
indent: 2 | ||
lockfile: true | ||
required: true | ||
sensitive: true | ||
type: true |
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
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,33 @@ | ||
module "aweasome_module" { | ||
source = "../../" | ||
name = "aweasome" | ||
stage = "production" | ||
namespace = "sweetops" | ||
module "label" { | ||
source = "cloudposse/label/null" | ||
version = "0.24.1" | ||
|
||
name = "alpha" | ||
namespace = "so" | ||
stage = "staging" | ||
} | ||
|
||
module "ssh_key_pair" { | ||
source = "cloudposse/key-pair/aws" | ||
version = "0.18.1" | ||
|
||
ssh_public_key_path = "keys/" | ||
generate_ssh_key = "true" | ||
|
||
context = module.label.context | ||
} | ||
|
||
module "secrets" { | ||
source = "SweetOps/secretsmanager/aws" | ||
version = "0.1.0" | ||
|
||
secret_version = { | ||
secret_string = jsonencode( | ||
{ | ||
ssh_public_key = base64encode(module.ssh_key_pair.public_key) | ||
ssh_private_key = base64encode(module.ssh_key_pair.private_key) | ||
} | ||
) | ||
} | ||
context = module.label.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
experiments = [module_variable_optional_attrs] | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 3.0" | ||
} | ||
} | ||
} |
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,67 @@ | ||
locals { | ||
enabled = module.this.enabled | ||
enabled = module.this.enabled | ||
secret_id = one(aws_secretsmanager_secret.default[*].id) | ||
secret_arn = one(aws_secretsmanager_secret.default[*].arn) | ||
version_id = one(aws_secretsmanager_secret_version.default[*].version_id) | ||
secret_version = defaults(var.secret_version, local.secret_version_default) | ||
secret_version_enabled = local.enabled && (length(local.secret_version["secret_string"]) > 0 || length(local.secret_version["secret_binary"]) > 0) | ||
secret_string = local.enabled && length(local.secret_version["secret_string"]) > 0 ? local.secret_version["secret_string"] : null | ||
secret_binary = local.enabled && length(local.secret_version["secret_binary"]) > 0 ? local.secret_version["secret_binary"] : null | ||
kms_key = defaults(var.kms_key, local.kms_key_default) | ||
kms_key_enabled = local.enabled && local.kms_key["enabled"] | ||
kms_key_id = local.kms_key["enabled"] ? module.kms_key.key_id : var.kms_key_id | ||
|
||
kms_key_default = { | ||
deletion_window_in_days = 30 | ||
description = "Managed by Terraform" | ||
enable_key_rotation = true | ||
enabled = true | ||
} | ||
secret_version_default = { | ||
secret_string = "" | ||
secret_binary = "" | ||
} | ||
} | ||
|
||
module "kms_key" { | ||
source = "cloudposse/kms-key/aws" | ||
version = "0.11.0" | ||
|
||
description = local.kms_key["description"] | ||
deletion_window_in_days = local.kms_key["deletion_window_in_days"] | ||
enable_key_rotation = local.kms_key["enable_key_rotation"] | ||
alias = lookup(local.kms_key, "alias", format("secretsmanager/%s", module.this.id)) | ||
|
||
enabled = local.kms_key_enabled | ||
context = module.this.context | ||
} | ||
|
||
resource "aws_secretsmanager_secret" "default" { | ||
count = local.enabled ? 1 : 0 | ||
|
||
name = module.this.id | ||
description = var.description | ||
policy = var.policy | ||
tags = module.this.tags | ||
recovery_window_in_days = var.recovery_window_in_days | ||
kms_key_id = local.kms_key_id | ||
} | ||
|
||
resource "aws_secretsmanager_secret_version" "default" { | ||
count = local.secret_version_enabled ? 1 : 0 | ||
|
||
secret_id = local.secret_id | ||
secret_string = local.secret_string | ||
secret_binary = local.secret_binary | ||
} | ||
|
||
resource "aws_secretsmanager_secret_rotation" "default" { | ||
count = local.enabled && length(var.rotation["lambda_arn"]) > 0 ? 1 : 0 | ||
|
||
secret_id = local.secret_id | ||
rotation_lambda_arn = var.rotation["lambda_arn"] | ||
|
||
rotation_rules { | ||
automatically_after_days = var.rotation["automatically_after_days"] | ||
} | ||
} |
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,34 @@ | ||
output "id" { | ||
value = local.secret_id | ||
description = "ID of the secret" | ||
} | ||
|
||
output "arn" { | ||
value = local.secret_arn | ||
description = "ARN of the secret" | ||
} | ||
|
||
output "version_id" { | ||
value = local.version_id | ||
description = "The unique identifier of the version of the secret." | ||
} | ||
|
||
output "key_arn" { | ||
value = module.kms_key.key_arn | ||
description = "KMS key ARN" | ||
} | ||
|
||
output "kms_key_id" { | ||
value = local.kms_key_id | ||
description = "KMS key ID" | ||
} | ||
|
||
output "alias_arn" { | ||
value = module.kms_key.alias_arn | ||
description = "KMS key alias ARN" | ||
} | ||
|
||
output "alias_name" { | ||
value = module.kms_key.alias_name | ||
description = "KMS key alias name" | ||
} |
Oops, something went wrong.