Skip to content

Commit 038f396

Browse files
committed
Adding Unit Tests as per my discussing with bonclay7@. Additional information can be found in the comments of the Pull Request.
2 parents 102e3f3 + 57bfc0a commit 038f396

File tree

18 files changed

+179
-152
lines changed

18 files changed

+179
-152
lines changed

examples/existing-cluster-with-base-and-infra/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ View the full documentation for this example [here](https://aws-observability.gi
3636
| Name | Source | Version |
3737
|------|--------|---------|
3838
| <a name="module_eks_monitoring"></a> [eks\_monitoring](#module\_eks\_monitoring) | ../../modules/eks-monitoring | n/a |
39+
| <a name="module_grafana_key_rotation"></a> [grafana\_key\_rotation](#module\_grafana\_key\_rotation) | ../../modules/grafana-key-rotation | n/a |
3940

4041
## Resources
4142

@@ -52,7 +53,12 @@ View the full documentation for this example [here](https://aws-observability.gi
5253
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS Region | `string` | n/a | yes |
5354
| <a name="input_eks_cluster_id"></a> [eks\_cluster\_id](#input\_eks\_cluster\_id) | Name of the EKS cluster | `string` | `"eks-cluster-with-vpc"` | no |
5455
| <a name="input_enable_dashboards"></a> [enable\_dashboards](#input\_enable\_dashboards) | Enables or disables curated dashboards. Dashboards are managed by the Grafana Operator | `bool` | `true` | no |
56+
| <a name="input_enable_grafana_key_rotation"></a> [enable\_grafana\_key\_rotation](#input\_enable\_grafana\_key\_rotation) | Enables or disables Grafana API key rotation | `bool` | `true` | no |
57+
| <a name="input_eventbridge_scheduler_schedule_expression"></a> [eventbridge\_scheduler\_schedule\_expression](#input\_eventbridge\_scheduler\_schedule\_expression) | Schedule Expression for EventBridge Scheduler in Grafana API Key Rotation | `string` | `"rate(60 minutes)"` | no |
5558
| <a name="input_grafana_api_key"></a> [grafana\_api\_key](#input\_grafana\_api\_key) | API key for authorizing the Grafana provider to make changes to Amazon Managed Grafana | `string` | n/a | yes |
59+
| <a name="input_grafana_api_key_interval"></a> [grafana\_api\_key\_interval](#input\_grafana\_api\_key\_interval) | Number of seconds for secondsToLive value while creating API Key | `number` | `5400` | no |
60+
| <a name="input_grafana_api_key_refresh_interval"></a> [grafana\_api\_key\_refresh\_interval](#input\_grafana\_api\_key\_refresh\_interval) | Refresh Internal to be used by External Secrets for Grafana API Key rotation | `string` | `"5m"` | no |
61+
| <a name="input_lambda_runtime_grafana_key_rotation"></a> [lambda\_runtime\_grafana\_key\_rotation](#input\_lambda\_runtime\_grafana\_key\_rotation) | Python Runtime Identifier for the Lambda Function | `string` | `"python3.12"` | no |
5662
| <a name="input_managed_grafana_workspace_id"></a> [managed\_grafana\_workspace\_id](#input\_managed\_grafana\_workspace\_id) | Amazon Managed Grafana Workspace ID | `string` | n/a | yes |
5763
| <a name="input_managed_prometheus_workspace_id"></a> [managed\_prometheus\_workspace\_id](#input\_managed\_prometheus\_workspace\_id) | Amazon Managed Service for Prometheus Workspace ID | `string` | `""` | no |
5864

@@ -62,6 +68,10 @@ View the full documentation for this example [here](https://aws-observability.gi
6268
|------|-------------|
6369
| <a name="output_eks_cluster_id"></a> [eks\_cluster\_id](#output\_eks\_cluster\_id) | EKS Cluster Id |
6470
| <a name="output_eks_cluster_version"></a> [eks\_cluster\_version](#output\_eks\_cluster\_version) | EKS Cluster version |
71+
| <a name="output_grafana_key_rotation_eventbridge_scheduler_arn"></a> [grafana\_key\_rotation\_eventbridge\_scheduler\_arn](#output\_grafana\_key\_rotation\_eventbridge\_scheduler\_arn) | ARN of the EventBridge Scheduler invoking Lambda Function for Key rotation |
72+
| <a name="output_grafana_key_rotation_eventbridge_scheduler_role_arn"></a> [grafana\_key\_rotation\_eventbridge\_scheduler\_role\_arn](#output\_grafana\_key\_rotation\_eventbridge\_scheduler\_role\_arn) | ARN of the IAM Role of EventBridge Scheduler invoking Lambda Function for Key rotation |
73+
| <a name="output_grafana_key_rotation_lambda_function_arn"></a> [grafana\_key\_rotation\_lambda\_function\_arn](#output\_grafana\_key\_rotation\_lambda\_function\_arn) | ARN of the Lambda function performing Key rotation |
74+
| <a name="output_grafana_key_rotation_lambda_function_role_arn"></a> [grafana\_key\_rotation\_lambda\_function\_role\_arn](#output\_grafana\_key\_rotation\_lambda\_function\_role\_arn) | ARN of the Lambda function execution role |
6575
| <a name="output_managed_prometheus_workspace_endpoint"></a> [managed\_prometheus\_workspace\_endpoint](#output\_managed\_prometheus\_workspace\_endpoint) | Amazon Managed Prometheus workspace endpoint |
6676
| <a name="output_managed_prometheus_workspace_id"></a> [managed\_prometheus\_workspace\_id](#output\_managed\_prometheus\_workspace\_id) | Amazon Managed Prometheus workspace ID |
6777
| <a name="output_managed_prometheus_workspace_region"></a> [managed\_prometheus\_workspace\_region](#output\_managed\_prometheus\_workspace\_region) | AWS Region |

examples/existing-cluster-with-base-and-infra/main.tf

+11-14
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ module "eks_monitoring" {
5353
enable_apiserver_monitoring = true
5454

5555
# deploys external-secrets in to the cluster
56-
enable_external_secrets = true
57-
grafana_api_key = var.grafana_api_key
58-
target_secret_name = "grafana-admin-credentials"
59-
target_secret_namespace = "grafana-operator"
60-
grafana_url = "https://${data.aws_grafana_workspace.this.endpoint}"
61-
grafana_api_key_refresh_interval = var.grafana_api_key_refresh_interval
56+
enable_external_secrets = true
57+
grafana_api_key = var.grafana_api_key
58+
target_secret_name = "grafana-admin-credentials"
59+
target_secret_namespace = "grafana-operator"
60+
grafana_url = "https://${data.aws_grafana_workspace.this.endpoint}"
61+
grafana_api_key_refresh_interval = var.grafana_api_key_refresh_interval
6262

6363
# control the publishing of dashboards by specifying the boolean value for the variable 'enable_dashboards', default is 'true'
6464
enable_dashboards = var.enable_dashboards
@@ -81,20 +81,17 @@ module "eks_monitoring" {
8181
tags = local.tags
8282
}
8383

84-
# Enabling Key Rotation for API Keys of Grafana Workspace
84+
# Enabling Grafana API Key Rotation
8585
module "grafana_key_rotation" {
8686
source = "../../modules/grafana-key-rotation"
87-
# source = "github.com/aws-observability/terraform-aws-observability-accelerator//modules/eks-key-rotation"
88-
8987
count = var.enable_grafana_key_rotation ? 1 : 0
9088

9189
managed_grafana_workspace_id = var.managed_grafana_workspace_id
9290
grafana_api_key_interval = var.grafana_api_key_interval
9391
eventbridge_scheduler_schedule_expression = var.eventbridge_scheduler_schedule_expression
9492
lambda_runtime_grafana_key_rotation = var.lambda_runtime_grafana_key_rotation
95-
96-
ssmparameter_name = module.eks_monitoring.ssmparameter_name_eks_monitoring
97-
ssmparameter_arn = module.eks_monitoring.ssmparameter_arn_eks_monitoring
98-
kms_key_arn_ssm = module.eks_monitoring.kms_key_arn_eks_monitoring
9993

100-
}
94+
ssmparameter_name = module.eks_monitoring.ssmparameter_name
95+
ssmparameter_arn = module.eks_monitoring.ssmparameter_arn
96+
kms_key_arn_ssm = module.eks_monitoring.kms_key_arn
97+
}

examples/existing-cluster-with-base-and-infra/outputs.tf

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,29 @@ output "eks_cluster_id" {
2323
value = module.eks_monitoring.eks_cluster_id
2424
}
2525

26-
output "eks_key_rotation_lambda_function_arn" {
26+
output "grafana_key_rotation_lambda_function_arn" {
2727
description = "ARN of the Lambda function performing Key rotation"
2828
# value = module.grafana_key_rotation.lambda_function_arn
29-
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].lambda_function_arn : null
29+
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].lambda_function_arn : null
3030
}
3131

3232

33-
output "eks_key_rotation_lambda_function_role_arn" {
33+
output "grafana_key_rotation_lambda_function_role_arn" {
3434
description = "ARN of the Lambda function execution role"
3535
# value = module.grafana_key_rotation.lambda_function_role_arn
36-
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].lambda_function_role_arn : null
36+
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].lambda_function_role_arn : null
3737
}
3838

3939

40-
output "eks_key_rotation_eventbridge_scheduler_arn" {
40+
output "grafana_key_rotation_eventbridge_scheduler_arn" {
4141
description = "ARN of the EventBridge Scheduler invoking Lambda Function for Key rotation"
4242
# value = module.grafana_key_rotation.eventbridge_scheduler_arn
43-
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].eventbridge_scheduler_arn : null
43+
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].eventbridge_scheduler_arn : null
4444
}
4545

4646

47-
output "eks_key_rotation_eventbridge_scheduler_role_arn" {
47+
output "grafana_key_rotation_eventbridge_scheduler_role_arn" {
4848
description = "ARN of the IAM Role of EventBridge Scheduler invoking Lambda Function for Key rotation"
4949
# value = module.grafana_key_rotation.eventbridge_scheduler_role_arn
50-
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].eventbridge_scheduler_role_arn : null
50+
value = var.enable_grafana_key_rotation ? module.grafana_key_rotation[0].eventbridge_scheduler_role_arn : null
5151
}
52-

examples/existing-cluster-with-base-and-infra/variables.tf

+30
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,33 @@ variable "enable_dashboards" {
3131
type = bool
3232
default = true
3333
}
34+
35+
variable "enable_grafana_key_rotation" {
36+
description = "Enables or disables Grafana API key rotation"
37+
type = bool
38+
default = true
39+
}
40+
41+
variable "grafana_api_key_interval" {
42+
description = "Number of seconds for secondsToLive value while creating API Key"
43+
type = number
44+
default = 5400
45+
}
46+
47+
variable "eventbridge_scheduler_schedule_expression" {
48+
description = "Schedule Expression for EventBridge Scheduler in Grafana API Key Rotation"
49+
type = string
50+
default = "rate(60 minutes)"
51+
}
52+
53+
variable "grafana_api_key_refresh_interval" {
54+
description = "Refresh Internal to be used by External Secrets for Grafana API Key rotation"
55+
type = string
56+
default = "5m"
57+
}
58+
59+
variable "lambda_runtime_grafana_key_rotation" {
60+
description = "Python Runtime Identifier for the Lambda Function"
61+
type = string
62+
default = "python3.12"
63+
}

modules/eks-monitoring/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ See examples using this Terraform modules in the **Amazon EKS** section of [this
106106
| <a name="input_flux_kustomization_path"></a> [flux\_kustomization\_path](#input\_flux\_kustomization\_path) | Flux Kustomization Path | `string` | `"./artifacts/grafana-operator-manifests/eks/infrastructure"` | no |
107107
| <a name="input_go_config"></a> [go\_config](#input\_go\_config) | Grafana Operator configuration | <pre>object({<br> create_namespace = optional(bool, true)<br> helm_chart = optional(string, "oci://ghcr.io/grafana-operator/helm-charts/grafana-operator")<br> helm_name = optional(string, "grafana-operator")<br> k8s_namespace = optional(string, "grafana-operator")<br> helm_release_name = optional(string, "grafana-operator")<br> helm_chart_version = optional(string, "v5.5.2")<br> })</pre> | `{}` | no |
108108
| <a name="input_grafana_api_key"></a> [grafana\_api\_key](#input\_grafana\_api\_key) | Grafana API key for the Amazon Managed Grafana workspace. Required if `enable_external_secrets = true` | `string` | `""` | no |
109+
| <a name="input_grafana_api_key_refresh_interval"></a> [grafana\_api\_key\_refresh\_interval](#input\_grafana\_api\_key\_refresh\_interval) | Refresh Internal to be used by External Secrets for Grafana API Key rotation | `string` | `"5m"` | no |
109110
| <a name="input_grafana_cluster_dashboard_url"></a> [grafana\_cluster\_dashboard\_url](#input\_grafana\_cluster\_dashboard\_url) | Dashboard URL for Cluster Grafana Dashboard JSON | `string` | `"https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/v0.2.0/artifacts/grafana-dashboards/eks/infrastructure/cluster.json"` | no |
110111
| <a name="input_grafana_kubelet_dashboard_url"></a> [grafana\_kubelet\_dashboard\_url](#input\_grafana\_kubelet\_dashboard\_url) | Dashboard URL for Kubelet Grafana Dashboard JSON | `string` | `"https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/v0.2.0/artifacts/grafana-dashboards/eks/infrastructure/kubelet.json"` | no |
111112
| <a name="input_grafana_kubeproxy_dashboard_url"></a> [grafana\_kubeproxy\_dashboard\_url](#input\_grafana\_kubeproxy\_dashboard\_url) | Dashboard URL for kube-proxy Grafana Dashboard JSON | `string` | `"https://raw.githubusercontent.com/aws-observability/aws-observability-accelerator/v0.2.0/artifacts/grafana-dashboards/eks/kube-proxy/kube-proxy.json"` | no |
@@ -144,7 +145,10 @@ See examples using this Terraform modules in the **Amazon EKS** section of [this
144145
| <a name="output_adot_irsa_arn"></a> [adot\_irsa\_arn](#output\_adot\_irsa\_arn) | IRSA Arn for ADOT |
145146
| <a name="output_eks_cluster_id"></a> [eks\_cluster\_id](#output\_eks\_cluster\_id) | EKS Cluster Id |
146147
| <a name="output_eks_cluster_version"></a> [eks\_cluster\_version](#output\_eks\_cluster\_version) | EKS Cluster version |
148+
| <a name="output_kms_key_arn"></a> [kms\_key\_arn](#output\_kms\_key\_arn) | Name of the SSM Parameter |
147149
| <a name="output_managed_prometheus_workspace_endpoint"></a> [managed\_prometheus\_workspace\_endpoint](#output\_managed\_prometheus\_workspace\_endpoint) | Amazon Managed Prometheus workspace endpoint |
148150
| <a name="output_managed_prometheus_workspace_id"></a> [managed\_prometheus\_workspace\_id](#output\_managed\_prometheus\_workspace\_id) | Amazon Managed Prometheus workspace ID |
149151
| <a name="output_managed_prometheus_workspace_region"></a> [managed\_prometheus\_workspace\_region](#output\_managed\_prometheus\_workspace\_region) | Amazon Managed Prometheus workspace region |
152+
| <a name="output_ssmparameter_arn"></a> [ssmparameter\_arn](#output\_ssmparameter\_arn) | Name of the SSM Parameter |
153+
| <a name="output_ssmparameter_name"></a> [ssmparameter\_name](#output\_ssmparameter\_name) | Name of the SSM Parameter |
150154
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/eks-monitoring/add-ons/external-secrets/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,16 @@ This deploys an EKS Cluster with the External Secrets Operator. The cluster is p
4747
| <a name="input_addon_context"></a> [addon\_context](#input\_addon\_context) | Input configuration for the addon | <pre>object({<br> aws_caller_identity_account_id = string<br> aws_caller_identity_arn = string<br> aws_eks_cluster_endpoint = string<br> aws_partition_id = string<br> aws_region_name = string<br> eks_cluster_id = string<br> eks_oidc_issuer_url = string<br> eks_oidc_provider_arn = string<br> irsa_iam_role_path = string<br> irsa_iam_permissions_boundary = string<br> tags = map(string)<br> })</pre> | n/a | yes |
4848
| <a name="input_enable_external_secrets"></a> [enable\_external\_secrets](#input\_enable\_external\_secrets) | Enable external-secrets | `bool` | `true` | no |
4949
| <a name="input_grafana_api_key"></a> [grafana\_api\_key](#input\_grafana\_api\_key) | Grafana API key for the Amazon Managed Grafana workspace | `string` | n/a | yes |
50+
| <a name="input_grafana_api_key_refresh_interval"></a> [grafana\_api\_key\_refresh\_interval](#input\_grafana\_api\_key\_refresh\_interval) | Refresh Internal to be used by External Secrets for Grafana API Key rotation | `string` | n/a | yes |
5051
| <a name="input_helm_config"></a> [helm\_config](#input\_helm\_config) | Helm provider config for external secrets | `any` | `{}` | no |
5152
| <a name="input_target_secret_name"></a> [target\_secret\_name](#input\_target\_secret\_name) | Name to store the secret for Grafana API Key | `string` | n/a | yes |
5253
| <a name="input_target_secret_namespace"></a> [target\_secret\_namespace](#input\_target\_secret\_namespace) | Namespace to store the secret for Grafana API Key | `string` | n/a | yes |
5354

5455
## Outputs
5556

56-
No outputs.
57+
| Name | Description |
58+
|------|-------------|
59+
| <a name="output_kms_key_arn_ssm"></a> [kms\_key\_arn\_ssm](#output\_kms\_key\_arn\_ssm) | Name of the SSM Parameter |
60+
| <a name="output_ssmparameter_arn"></a> [ssmparameter\_arn](#output\_ssmparameter\_arn) | Name of the SSM Parameter |
61+
| <a name="output_ssmparameter_name"></a> [ssmparameter\_name](#output\_ssmparameter\_name) | Name of the SSM Parameter |
5762
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

modules/eks-monitoring/add-ons/external-secrets/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ metadata:
9797
name: ${local.name}-sm
9898
namespace: ${var.target_secret_namespace}
9999
spec:
100-
refreshInterval: ${var.grafana_api_key_refresh_interval}
100+
refreshInterval: ${var.grafana_api_key_refresh_interval}
101101
secretStoreRef:
102102
name: ${local.cluster_secretstore_name}
103103
kind: ClusterSecretStore

modules/eks-monitoring/add-ons/external-secrets/outputs.tf

-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,3 @@ output "kms_key_arn_ssm" {
1212
description = "Name of the SSM Parameter"
1313
value = aws_kms_key.secrets.arn
1414
}
15-
16-

modules/eks-monitoring/add-ons/external-secrets/variables.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ variable "target_secret_name" {
4545
variable "grafana_api_key_refresh_interval" {
4646
description = "Refresh Internal to be used by External Secrets for Grafana API Key rotation"
4747
type = string
48-
}
48+
}

modules/eks-monitoring/main.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,12 @@ module "external_secrets" {
265265
source = "./add-ons/external-secrets"
266266
count = var.enable_external_secrets ? 1 : 0
267267

268-
enable_external_secrets = var.enable_external_secrets
269-
grafana_api_key = var.grafana_api_key
270-
addon_context = local.context
271-
target_secret_namespace = var.target_secret_namespace
272-
target_secret_name = var.target_secret_name
273-
grafana_api_key_refresh_interval = var.grafana_api_key_refresh_interval
268+
enable_external_secrets = var.enable_external_secrets
269+
grafana_api_key = var.grafana_api_key
270+
addon_context = local.context
271+
target_secret_namespace = var.target_secret_namespace
272+
target_secret_name = var.target_secret_name
273+
grafana_api_key_refresh_interval = var.grafana_api_key_refresh_interval
274274

275275
depends_on = [resource.helm_release.grafana_operator]
276276
}

modules/eks-monitoring/outputs.tf

+15-15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ output "adot_irsa_arn" {
1313
value = module.helm_addon.irsa_arn
1414
}
1515

16+
output "ssmparameter_name" {
17+
description = "Name of the SSM Parameter"
18+
value = module.external_secrets[0].ssmparameter_name
19+
}
20+
21+
output "ssmparameter_arn" {
22+
description = "Name of the SSM Parameter"
23+
value = module.external_secrets[0].ssmparameter_arn
24+
}
25+
26+
output "kms_key_arn" {
27+
description = "Name of the SSM Parameter"
28+
value = module.external_secrets[0].kms_key_arn_ssm
29+
}
30+
1631
output "managed_prometheus_workspace_endpoint" {
1732
description = "Amazon Managed Prometheus workspace endpoint"
1833
value = local.managed_prometheus_workspace_endpoint
@@ -27,18 +42,3 @@ output "managed_prometheus_workspace_region" {
2742
description = "Amazon Managed Prometheus workspace region"
2843
value = local.managed_prometheus_workspace_region
2944
}
30-
31-
output "ssmparameter_name_eks_monitoring" {
32-
description = "Name of the SSM Parameter"
33-
value = module.external_secrets[0].ssmparameter_name
34-
}
35-
36-
output "ssmparameter_arn_eks_monitoring" {
37-
description = "Name of the SSM Parameter"
38-
value = module.external_secrets[0].ssmparameter_arn
39-
}
40-
41-
output "kms_key_arn_eks_monitoring" {
42-
description = "Name of the SSM Parameter"
43-
value = module.external_secrets[0].kms_key_arn_ssm
44-
}

modules/eks-monitoring/variables.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -569,4 +569,5 @@ variable "kubeproxy_monitoring_config" {
569569
variable "grafana_api_key_refresh_interval" {
570570
description = "Refresh Internal to be used by External Secrets for Grafana API Key rotation"
571571
type = string
572-
}
572+
default = "5m"
573+
}

0 commit comments

Comments
 (0)