Skip to content

Commit 1511a57

Browse files
authored
Use short-lived Grafana API keys (#33)
* Use short-lived Grafana API keys * Reduce API key TTL
1 parent 3451706 commit 1511a57

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

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

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ configuration options on the cluster infrastructure.
1616

1717
Ensure that you have the following tools installed locally:
1818

19-
1. [aws cli](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
19+
1. [aws cli v2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
2020
2. [kubectl](https://kubernetes.io/docs/tasks/tools/)
2121
3. [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli)
2222

@@ -60,29 +60,25 @@ If you don't specify anything a new workspace will be created for you.
6060

6161
6. Amazon Managed Grafana workspace
6262

63-
If you have an existing workspace, add `managed_grafana_workspace_id=g-xxx`
64-
or use an environment variable `export TF_VAR_managed_grafana_workspace_id=g-xxx`.
63+
If you have an existing workspace, create an environment variable `export TF_VAR_managed_grafana_workspace_id=g-xxx`.
6564

66-
7. Grafana API Key
65+
7. <a name="apikey"></a> Grafana API Key
6766

68-
- Give admin access to the SSO user you set up when creating the Amazon Managed Grafana Workspace:
69-
- In the AWS Console, navigate to Amazon Grafana. In the left navigation bar, click **All workspaces**, then click on the workspace name you are using for this example.
70-
- Under **Authentication** within **AWS Single Sign-On (SSO)**, click **Configure users and user groups**
71-
- Check the box next to the SSO user you created and click **Make admin**
72-
- From the workspace in the AWS console, click on the `Grafana workspace URL` to open the workspace
73-
- If you don't see the gear icon in the left navigation bar, log out and log back in.
74-
- Click on the gear icon, then click on the **API keys** tab.
75-
- Click **Add API key**, fill in the _Key name_ field and select _Admin_ as the Role.
76-
- Copy your API key into `terraform.tfvars` under the `grafana_api_key` variable (`grafana_api_key="xxx"`) or set as an environment variable on your CLI (`export TF_VAR_grafana_api_key="xxx"`)
67+
Amazon Managed Service for Grafana provides a control plane API for generating Grafana API keys. We will provide to Terraform
68+
a short lived API key to run the `apply` or `destroy` command.
69+
Ensure you have necessary IAM permissions (`CreateWorkspaceApiKey, DeleteWorkspaceApiKey`)
7770

71+
```sh
72+
export TF_VAR_grafana_api_key=`aws grafana create-workspace-api-key --key-name "observability-accelerator-$(date +%s)" --key-role ADMIN --seconds-to-live 1200 --workspace-id $TF_VAR_managed_grafana_workspace_id --query key --output text`
73+
```
7874

7975
## Deploy
8076

8177
```sh
8278
terraform apply -var-file=terraform.tfvars
8379
```
8480

85-
or if you had setup environment variables, run
81+
or if you had only setup environment variables, run
8682

8783
```sh
8884
terraform apply
@@ -125,6 +121,15 @@ add this `managed_prometheus_region=xxx` and `managed_prometheus_workspace_id=ws
125121
If your existing Amazon Managed Prometheus workspace is in another AWS Region,
126122
add this `managed_prometheus_region=xxx` and `managed_prometheus_workspace_id=ws-xxx`.
127123

124+
## Destroy resources
125+
126+
If you leave this stack running, you will incur charges. To remove all resources
127+
created by Terraform, [refresh your Grafana API key](#apikey) and run:
128+
129+
```sh
130+
terraform destroy -var-file=terraform.tfvars
131+
```
132+
128133

129134
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
130135
## Requirements

examples/existing-cluster-with-base-and-infra/terraform.tfvars

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,3 @@ eks_cluster_id = ""
66

77
# (optional) Leave it empty for a new workspace to be created
88
managed_prometheus_workspace_id = ""
9-
10-
# (mandatory) Amazon Managed Grafana Workspace ID: ex: g-abc123
11-
managed_grafana_workspace_id = ""
12-
13-
# (mandatory) Grafana API Key - https://docs.aws.amazon.com/grafana/latest/userguide/API_key_console.html
14-
grafana_api_key = ""

0 commit comments

Comments
 (0)