Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(terraform): add s3 fix as a local exec #219

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions terraform/modules/cos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,74 @@ To deploy this module with its needed dependency, you can run `terraform apply -

By default, this Terraform module will deploy each worker with `1` unit. To configure the module to run `x` units of any worker role, you can run `terraform apply -var="model_name=<MODEL_NAME>" -var="<ROLE>_units=<x>" -auto-approve`.
See each ... for the recommended scale for each role.

### Sample deployment

```hcl
terraform {
required_version = ">= 1.5"
required_providers {
juju = {
source = "juju/juju"
}
}
}

module "cos" {
source = "git::https://github.com/canonical/observability//terraform/modules/cos"
model_name = var.model_name
}

# Assumes that model already exists
variable "model_name" {
type = string
}


resource "juju_application" "minio" {
name = "minio"
# Coordinator requires s3
model = var.model_name
trust = true

charm {
name = "minio"
channel = "latest/edge"
}
units = 1

config = {
access-key = "user"
secret-key = "password"
}
}


resource "null_resource" "s3fix" {

provisioner "local-exec" {
# There's currently no way to wait for the charm to be idle, hence the sleep
# https://github.com/juju/terraform-provider-juju/issues/202
command = <<-EOT
sleep 600;

juju ssh -m cos minio/leader curl https://dl.min.io/client/mc/release/linux-amd64/mc --create-dirs -o '/root/minio/mc';
juju ssh -m cos minio/leader chmod +x '/root/minio/mc';
juju ssh -m cos minio/leader /root/minio/mc alias set local http://minio-0.minio-endpoints.cos.svc.cluster.local:9000 user password;
juju ssh -m cos minio/leader /root/minio/mc mb local/mimir;
juju ssh -m cos minio/leader /root/minio/mc mb local/loki;
juju ssh -m cos minio/leader /root/minio/mc mb local/tempo;

juju config loki-s3-bucket endpoint="http://minio-0.minio-endpoints.cos.svc.cluster.local:9000" bucket="loki";
juju config mimir-s3-bucket endpoint="http://minio-0.minio-endpoints.cos.svc.cluster.local:9000" bucket="mimir";
juju config tempo-s3-bucket endpoint="http://minio-0.minio-endpoints.cos.svc.cluster.local:9000" bucket="tempo";

juju run -m cos loki-s3-bucket/leader sync-s3-credentials access-key=user secret-key=password;
juju run -m cos mimir-s3-bucket/leader sync-s3-credentials access-key=user secret-key=password;
juju run -m cos tempo-s3-bucket/leader sync-s3-credentials access-key=user secret-key=password;

sleep 30;
EOT
}
}
```
55 changes: 54 additions & 1 deletion terraform/modules/cos/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module "ssc" {
}

module "tempo" {
source = "git::https://github.com/canonical/observability//terraform/modules/tempo"
source = "git::https://github.com/canonical/observability//terraform/modules/tempo?ref=feature/local_exec"
model_name = var.model_name
channel = var.channel
}
Expand All @@ -44,6 +44,13 @@ module "traefik" {
channel = var.channel
}

module "grafana_agent" {
source = "git::https://github.com/canonical/grafana-agent-k8s-operator//terraform?ref=feature/terraform"
app_name = "grafana-agent"
model_name = var.model_name
channel = var.channel
}

# -------------- # Integrations --------------

# Provided by Mimir
Expand Down Expand Up @@ -106,6 +113,22 @@ resource "juju_integration" "loki-grafana-source" {
}
}

# Provided by Tempo
resource "juju_integration" "tempo-grafana-source" {
model = var.model_name

application {
name = module.tempo.app_names.tempo_coordinator
endpoint = module.tempo.provides.grafana_source
}

application {
name = module.grafana.app_name
endpoint = module.grafana.requires.grafana_source
}
}


# Provided by Catalogue

resource "juju_integration" "grafana-catalogue" {
Expand Down Expand Up @@ -165,3 +188,33 @@ resource "juju_integration" "loki-ingress" {
endpoint = module.loki.requires.ingress
}
}

# Grafana agent

resource "juju_integration" "agent-loki-metrics" {
model = var.model_name

application {
name = module.loki.app_names.loki_coordinator
endpoint = module.loki.provides.self_metrics_endpoint
}

application {
name = module.grafana_agent.app_name
endpoint = module.grafana_agent.requires.metrics_endpoint
}
}

resource "juju_integration" "agent-mimir-metrics" {
model = var.model_name

application {
name = module.mimir.app_names.mimir_coordinator
endpoint = module.mimir.provides.receive_remote_write
}

application {
name = module.grafana_agent.app_name
endpoint = module.grafana_agent.requires.send_remote_write
}
}
16 changes: 16 additions & 0 deletions terraform/modules/tempo/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ output "app_names" {
tempo_s3_integrator = juju_application.s3_integrator.name,
}
)
}

output "requires" {
value = {
logging = "logging",
ingress = "ingress",
certificates = "certificates",
send-remote-write = "send-remote-write",
}
}

output "provides" {
value = {
grafana_dashboard = "grafana-dashboard",
grafana_source = "grafana-source",
metrics_endpoint = "metrics-endpoint",
tracing = "tracing",
}
}