Skip to content

Instantly share code, notes, and snippets.

@neomantra
Last active July 12, 2024 19:44
Show Gist options
  • Save neomantra/e689afac7b04c2fec4db2a61b0ee2e69 to your computer and use it in GitHub Desktop.
Save neomantra/e689afac7b04c2fec4db2a61b0ee2e69 to your computer and use it in GitHub Desktop.
pdc-agent with HashiCorp Nomad
# Grafana PDC -- private network tunnel
# This is templated by Terraform templatefile()
# https://grafana.com/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/configure-pdc/
job "grafana-pdc" {
region = "global"
datacenters = ["${NOMAD_DATACENTER}"]
namespace = "${NOMAD_NAMESPACE}"
type = "service"
group "grafana-pdc" {
task "grafana-pdc" {
driver = "docker"
config {
image = "${IMAGE}"
args = []
}
template {
destination = "secrets/.envs"
env = true
change_mode = "restart"
data = <<EOH
{{ with nomadVar "grafana/pdc" }}
{{ .env }}
{{ end }}
EOH
}
template {
destination = "/alloc/.envs"
change_mode = "restart"
data = <<EOH
{{ with nomadVar "grafana/pdc" }}
{{ .env }}
{{ end }}
EOH
}
resources {
cpu = 1024
memory = 1024
}
}
}
}
locals {
# grafana_pdc.env file can have:
#. GCLOUD_PDC_SIGNING_TOKEN=
# GCLOUD_HOSTED_GRAFANA_ID=
# GCLOUD_PDC_DOMAIN=
# GCLOUD_PDC_CLUSTER=
#
grafana_pdc_env = sensitive(file("grafana_pdc.env"))
}
resource "nomad_variable" "grafana-pdc" {
namespace = "default"
path = "grafana/pdc"
items = {
# this gets injected by Nomad
env = local.grafana_pdc_env
}
}
resource "nomad_job" "grafana-pdc" {
jobspec = templatefile("grafana-pdc.nomad.tpl", {
NOMAD_DATACENTER = "default"
NOMAD_NAMESPACE = "default"
# TODO: change to "grafana/pdc-agent:latest" once it handles #102
IMAGE = "neomantra/pdc-agent"
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment