Skip to content

Commit

Permalink
feat/improving outputs (#15)
Browse files Browse the repository at this point in the history
feat: saves credentials/configs to an s3 file for the particular cluster example: s3://bucket-name/test-refactor-2.example.com/configurations/credentials.json
* terraform-docs: automated action

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
venkatamutyala and github-actions[bot] authored Mar 23, 2023
1 parent 6cac262 commit d963e87
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 32 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ This Terraform module creates various resources for managing multi-cloud prerequ
| Name | Version |
|------|---------|
| <a name="provider_aws.clientaccount"></a> [aws.clientaccount](#provider\_aws.clientaccount) | 4.59.0 |
| <a name="provider_aws.primaryregion"></a> [aws.primaryregion](#provider\_aws.primaryregion) | 4.59.0 |
| <a name="provider_cloudflare"></a> [cloudflare](#provider\_cloudflare) | 4.2.0 |

## Modules
Expand Down Expand Up @@ -63,6 +64,7 @@ This Terraform module creates various resources for managing multi-cloud prerequ
| [aws_route53_record.wildcard_for_apps](https://registry.terraform.io/providers/hashicorp/aws/4.59.0/docs/resources/route53_record) | resource |
| [aws_route53_zone.clusters](https://registry.terraform.io/providers/hashicorp/aws/4.59.0/docs/resources/route53_zone) | resource |
| [aws_route53_zone.main](https://registry.terraform.io/providers/hashicorp/aws/4.59.0/docs/resources/route53_zone) | resource |
| [aws_s3_bucket_object.combined_outputs](https://registry.terraform.io/providers/hashicorp/aws/4.59.0/docs/resources/s3_bucket_object) | resource |
| [cloudflare_record.delegation_ns_record_first](https://registry.terraform.io/providers/cloudflare/cloudflare/4.2.0/docs/resources/record) | resource |
| [cloudflare_record.delegation_ns_record_fourth](https://registry.terraform.io/providers/cloudflare/cloudflare/4.2.0/docs/resources/record) | resource |
| [cloudflare_record.delegation_ns_record_second](https://registry.terraform.io/providers/cloudflare/cloudflare/4.2.0/docs/resources/record) | resource |
Expand All @@ -84,11 +86,5 @@ This Terraform module creates various resources for managing multi-cloud prerequ

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_certmanager_iam_credentials"></a> [certmanager\_iam\_credentials](#output\_certmanager\_iam\_credentials) | A map of IAM Access Keys to Route53 for Cert Manager. One per Cluster Environment |
| <a name="output_externaldns_iam_credentials"></a> [externaldns\_iam\_credentials](#output\_externaldns\_iam\_credentials) | A map of IAM Access Keys to Route53 for External DNS. One per Cluster Environment |
| <a name="output_loki_s3_iam_credentials"></a> [loki\_s3\_iam\_credentials](#output\_loki\_s3\_iam\_credentials) | A map of IAM Access Keys to S3 for Loki. One per Cluster Environment |
| <a name="output_opsgenie_prometheus_api_keys"></a> [opsgenie\_prometheus\_api\_keys](#output\_opsgenie\_prometheus\_api\_keys) | A map of OpsGenie API Keys. One per Cluster Environment |
| <a name="output_vault_s3_iam_credentials"></a> [vault\_s3\_iam\_credentials](#output\_vault\_s3\_iam\_credentials) | A map of IAM Access Keys to S3 for vault backups. One per Cluster Environment |
No outputs.
<!-- END_TF_DOCS -->
5 changes: 0 additions & 5 deletions iam-user-cert-manager.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ resource "aws_iam_access_key" "certmanager" {
provider = aws.clientaccount
user = each.value.name
}

output "certmanager_iam_credentials" {
value = { for user, keys in aws_iam_access_key.certmanager : user => keys }
description = "A map of IAM Access Keys to Route53 for Cert Manager. One per Cluster Environment"
}
5 changes: 0 additions & 5 deletions iam-user-external-dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ resource "aws_iam_access_key" "externaldns" {
provider = aws.clientaccount
user = each.value.name
}

output "externaldns_iam_credentials" {
value = { for user, keys in aws_iam_access_key.externaldns : user => keys }
description = "A map of IAM Access Keys to Route53 for External DNS. One per Cluster Environment"
}
4 changes: 0 additions & 4 deletions iam-user-loki-s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@ resource "aws_iam_access_key" "loki_s3" {
user = each.value.name
}

output "loki_s3_iam_credentials" {
value = { for user, keys in aws_iam_access_key.loki_s3 : user => keys }
description = "A map of IAM Access Keys to S3 for Loki. One per Cluster Environment"
}
5 changes: 0 additions & 5 deletions iam-user-vault-backup-s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,3 @@ resource "aws_iam_access_key" "vault_s3" {
provider = aws.clientaccount
user = each.value.name
}

output "vault_s3_iam_credentials" {
value = { for user, keys in aws_iam_access_key.vault_s3 : user => keys }
description = "A map of IAM Access Keys to S3 for vault backups. One per Cluster Environment"
}
4 changes: 4 additions & 0 deletions modules/multy-s3-bucket/0.1.0/s3-primary-bucket.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ output "primary_s3_bucket_arn" {
value = aws_s3_bucket.primary.arn
}

output "primary_s3_bucket_id" {
value = aws_s3_bucket.primary.id
}

resource "aws_s3_bucket_acl" "primary" {
provider = aws.primaryregion
bucket = aws_s3_bucket.primary.id
Expand Down
2 changes: 1 addition & 1 deletion modules/opsgenie/0.1.0/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ resource "opsgenie_team" "teams" {

resource "opsgenie_team_routing_rule" "routing_rules" {
for_each = local.cluster_environments_set

name = "${var.company_key}-${each.value}-routing-rule"
team_id = opsgenie_team.teams[each.key].id
order = 0
Expand Down
5 changes: 0 additions & 5 deletions opsgenie.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ module "opsgenie_teams" {
company_key = var.company_key
cluster_environments = var.cluster_environments
}

output "opsgenie_prometheus_api_keys" {
value = module.opsgenie_teams.opsgenie_prometheus_api_keys
description = "A map of OpsGenie API Keys. One per Cluster Environment"
}
32 changes: 32 additions & 0 deletions save-credentials-to-s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
locals {
combined_outputs = {
opsgenie_credentials = module.opsgenie_teams.opsgenie_prometheus_api_keys
certmanager_credentials = { for user, keys in aws_iam_access_key.certmanager : aws_route53_zone.clusters[user].name => keys }
externaldns_credentials = { for user, keys in aws_iam_access_key.externaldns : aws_route53_zone.clusters[user].name => keys }
loki_credentials = { for user, keys in aws_iam_access_key.loki_s3 : aws_route53_zone.clusters[user].name => keys }
vault_credentials = { for user, keys in aws_iam_access_key.vault_s3 : aws_route53_zone.clusters[user].name => keys }
}


cluster_names = toset([for k in keys(local.combined_outputs.certmanager_credentials) : k])

updated_combined_outputs = {
for name in local.cluster_names :
name => {
certmanager_credentials = local.combined_outputs.certmanager_credentials[name]
externaldns_credentials = local.combined_outputs.externaldns_credentials[name]
loki_credentials = local.combined_outputs.loki_credentials[name]
opsgenie_credentials = lookup(local.combined_outputs.opsgenie_credentials, split(".", name)[0], null)
vault_credentials = local.combined_outputs.vault_credentials[name]
}
}
}

resource "aws_s3_bucket_object" "combined_outputs" {
for_each = local.updated_combined_outputs
provider = aws.primaryregion
bucket = module.common_s3.primary_s3_bucket_id
key = "${each.key}/configurations/credentials.json"
content = jsonencode(each.value)
content_type = "application/json"
}

0 comments on commit d963e87

Please sign in to comment.