Skip to content

Commit

Permalink
Replacing Secrets Manager to SSM to store Grafana API Key (#178)
Browse files Browse the repository at this point in the history
* Fixing SSM

* Fixing SSM

* Replacing Secrets Manager with SSM

* Replacing Secrets Manager with SSM
  • Loading branch information
elamaran11 authored Jun 9, 2023
1 parent 354df99 commit e4f30fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
13 changes: 4 additions & 9 deletions docs/eks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,13 @@ export GO_AMG_API_KEY=$(aws grafana create-workspace-api-key \
--output text)
```

- Next, lets grab the Grafana API key secret name from AWS Secrets Manager. The keyname should start with `terraform-..`

```bash
aws secretsmanager list-secrets
```

- Finally, update the Grafana API key secret in AWS Secrets Manager using the above new Grafana API key:

```bash
aws secretsmanager update-secret \
--secret-id <Your Secret Name> \
--secret-string "{\"GF_SECURITY_ADMIN_APIKEY\": \"${GO_AMG_API_KEY}\"}" \
aws aws ssm put-parameter \
--name "/terraform-accelerator/grafana-api-key" \
--type "SecureString" \
--value "{\"GF_SECURITY_ADMIN_APIKEY\": \"${GO_AMG_API_KEY}\"}" \
--region <Your AWS Region>
```

Expand Down
3 changes: 1 addition & 2 deletions modules/eks-monitoring/add-ons/external-secrets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ This deploys an EKS Cluster with the External Secrets Operator. The cluster is p
|------|------|
| [aws_iam_policy.cluster_secretstore](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [aws_kms_key.secrets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource |
| [aws_secretsmanager_secret.secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
| [aws_secretsmanager_secret_version.secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
| [aws_ssm_parameter.secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
| [kubectl_manifest.cluster_secretstore](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource |
| [kubectl_manifest.secret](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
Expand Down
30 changes: 15 additions & 15 deletions modules/eks-monitoring/add-ons/external-secrets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ resource "aws_iam_policy" "cluster_secretstore" {
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
"ssm:DescribeParameters",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:GetParametersByPath",
"ssm:GetParameterHistory"
],
"Resource": "${aws_secretsmanager_secret.secret.arn}"
"Resource": "${aws_ssm_parameter.secret.arn}"
},
{
"Effect": "Allow",
Expand All @@ -64,7 +65,7 @@ metadata:
spec:
provider:
aws:
service: SecretsManager
service: ParameterStore
region: ${data.aws_region.current.name}
auth:
jwt:
Expand All @@ -75,16 +76,15 @@ YAML
depends_on = [module.external_secrets]
}

resource "aws_secretsmanager_secret" "secret" {
recovery_window_in_days = 0
kms_key_id = aws_kms_key.secrets.arn
}

resource "aws_secretsmanager_secret_version" "secret" {
secret_id = aws_secretsmanager_secret.secret.id
secret_string = jsonencode({
resource "aws_ssm_parameter" "secret" {
name = "/terraform-accelerator/grafana-api-key"
description = "SSM Secret to store grafana API Key"
type = "SecureString"
value = jsonencode({
GF_SECURITY_ADMIN_APIKEY = var.grafana_api_key
})
key_id = aws_kms_key.secrets.id
overwrite = true
}

resource "kubectl_manifest" "secret" {
Expand All @@ -103,7 +103,7 @@ spec:
name: ${var.target_secret_name}
dataFrom:
- extract:
key: ${aws_secretsmanager_secret.secret.name}
key: ${aws_ssm_parameter.secret.name}
YAML
depends_on = [module.external_secrets]
}

0 comments on commit e4f30fe

Please sign in to comment.