Create a new AMG workspace

This commit is contained in:
Rodrigue Koffi
2022-07-28 14:37:55 +02:00
parent d73dc30584
commit 2a55646074
6 changed files with 125 additions and 39 deletions
+36 -1
View File
@@ -8,6 +8,30 @@ data "aws_eks_cluster" "eks_cluster" {
name = var.eks_cluster_id
}
data "aws_grafana_workspace" "this" {
count = var.managed_grafana_workspace_id == "" ? 0 : 1
workspace_id = var.managed_grafana_workspace_id
}
# resource "null_resource" "amg_api_key" {
# # Bootstrap script can run on any instance of the cluster
# # So we just choose the first in this case
# connection {
# host = element(aws_instance.cluster.*.public_ip, 0)
# }
# provisioner "remote-exec" {
# # requires aws-cli
# inline = [
# #"bootstrap-cluster.sh ${join(" ", aws_instance.cluster.*.private_ip)}",
# "aws grafana create-key",
# ]
# }
# }
locals {
eks_oidc_issuer_url = replace(data.aws_eks_cluster.eks_cluster.identity[0].oidc[0].issuer, "https://", "")
eks_cluster_endpoint = data.aws_eks_cluster.eks_cluster.endpoint
@@ -15,9 +39,20 @@ locals {
# if region is not passed, we assume the current one
amp_ws_region = coalesce(var.managed_prometheus_region, data.aws_region.current.name)
amp_ws_id = var.create_managed_prometheus_workspace ? aws_prometheus_workspace.this[0].id : var.managed_prometheus_id
amp_ws_id = var.enable_managed_prometheus ? aws_prometheus_workspace.this[0].id : var.managed_prometheus_id
amp_ws_endpoint = "https://aps-workspaces.${local.amp_ws_region}.amazonaws.com/workspaces/${local.amp_ws_id}/"
# if region is not passed, we assume the current one
amg_ws_region = coalesce(var.managed_grafana_region, data.aws_region.current.name)
# if grafana_workspace_id is supplied, we infer the endpoint from
# computed region, else we create a new workspace
amg_ws_endpoint = var.enable_managed_grafana ? "https://${module.managed_grafana[0].workspace_endpoint}" : "https://${var.managed_grafana_workspace_id}.grafana-workspace.${local.amg_ws_region}.amazonaws.com"
# TODO when tf resource for AMG api keys are supported
# create a short-lived api key on the fly if api_key is not provided
amg_api_key = var.grafana_api_key
context = {
aws_caller_identity_account_id = data.aws_caller_identity.current.account_id
aws_caller_identity_arn = data.aws_caller_identity.current.arn