Skip to content

Commit

Permalink
Add the Github workflow for the Terraform checks
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici committed Feb 9, 2024
1 parent becd9d3 commit a9ac578
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 150 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Check the Terraform Module

on:
pull_request:
paths:
- '**.tf'

jobs:
build:
name: Terraform Checks and Plans
runs-on: ubuntu-latest
steps:
- name: Checkout the repository to the runner
uses: actions/checkout@v3

- name: HashiCorp - Setup Terraform
uses: hashicorp/setup-terraform@v4

- name: Terraform Format
id: fmt
run: terraform fmt -recursive -check
continue-on-error: true

- name: Terraform Init
id: init
run: terraform init

- name: Terraform Validate
id: validate
run: terraform validate -no-color
86 changes: 0 additions & 86 deletions terraform/CONTRIBUTING.md

This file was deleted.

14 changes: 6 additions & 8 deletions terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This Grafana-agent-k8s Terraform module aims to deploy the [grafana-agent-k8s ch

### Prerequisites

The following software and tools needs to be installed and should be running in the local environment.
The following software and tools needs to be installed and should be running in the local environment. Please [set up your environment](https://discourse.charmhub.io/t/set-up-your-development-environment-with-microk8s-for-juju-terraform-provider/13109) before deployment.

- `microk8s`
- `juju 3.x`
Expand All @@ -23,7 +23,7 @@ sudo microk8s enable hostpath-storage
Add a Juju model:

```console
juju add model <model-name>
juju add-model <model-name>
```

Initialise the provider:
Expand All @@ -32,22 +32,20 @@ Initialise the provider:
terraform init
```

Customize the configuration inputs under `terraform.tfvars` file according to requirement.

Replace the values in the `terraform.tfvars` file:
Fill the mandatory config options in the `terraform.tfvars` file:

```yaml
# Mandatory Config Options
model_name = "put your model-name here"
```

Run Terraform Plan by providing var-file:
Create the Terraform Plan:

```console
terraform plan -var-file="terraform.tfvars"
```

Deploy the resources, skip the approval:
Deploy the resources:

```console
terraform apply -auto-approve
Expand All @@ -63,7 +61,7 @@ juju status --relations

### Clean Up

Remove the application:
Destroy the deployment:

```console
terraform destroy -auto-approve
Expand Down
34 changes: 4 additions & 30 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
resource "juju_application" "grafana-agent-k8s" {
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

resource "juju_application" "grafana" {
name = "grafana-agent-k8s"
model = var.model_name

charm {
name = "grafana-agent-k8s"
channel = var.channel
base = "[email protected]"
}
config = var.grafana-config
units = 1
trust = true
}

resource "juju_integration" "prometheus-remote-write" {
count = var.metrics_remote_write_offer_url != "" ? 1 : 0
model = var.model_name

application {
name = juju_application.grafana-agent-k8s.name
endpoint = "send-remote-write"
}

application {
offer_url = var.metrics_remote_write_offer_url
}
}

resource "juju_integration" "loki-logging" {
count = var.logging_offer_url != "" ? 1 : 0
model = var.model_name

application {
name = juju_application.grafana-agent-k8s.name
endpoint = "logging-consumer"
}

application {
offer_url = var.logging_offer_url
}
}

54 changes: 51 additions & 3 deletions terraform/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,52 @@
output "grafana_application_name" {
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

output "app-name" {
description = "Name of the deployed application."
value = juju_application.grafana-agent-k8s.name
}
value = juju_application.grafana.name
}

output "certificates-endpoint" {
description = "Name of the endpoint used by Grafana to get the X.509 certificate."
value = "certificates"
}

output "send-remote-write-endpoint" {
description = "Name of the endpoint used by Grafana to forward client charms metrics and associated alert rules to Prometheus using prometheus_remote_write interface."
value = "send-remote-write"
}

output "metrics-endpoint" {
description = "Exposes the Prometheus metrics endpoint providing telemetry about the Grafana instance using prometheus_scrape interface."
value = "metrics-endpoint"
}

output "logging-consumer-endpoint" {
description = "Name of the endpoint used by Grafana to send the logs to Loki using loki_push_api interface."
value = "logging-consumer"
}

output "grafana-dashboards-consumer-endpoint" {
description = "Name of the endpoint used by Grafana to provide meaningful dashboards about it's metrics using grafana_dashboard interface."
value = "grafana-dashboards-consumer"
}

output "grafana-cloud-config-endpoint" {
description = "Name of the endpoint used by Grafana to forward telemetry to any Prometheus(or Loki) compatible endpoint using grafana_cloud_config interface."
value = "grafana-cloud-config"
}

output "receive-ca-cert-endpoint" {
description = "Name of the endpoint used by Grafana to get the Self signed X.509 Certificates through the relation with Self Signed Certificates Charm using certificate_transfer interface."
value = "receive-ca-cert"
}

output "logging-provider-endpoint" {
description = "Name of the endpoint provided by Grafana to receive logs from any charm that supports the loki_push_api relation interface."
value = "logging-provider"
}

output "grafana-dashboards-provider-endpoint" {
description = "Name of the endpoint provided by Grafana to provide meaningful dashboards about its metrics to be shown in a Grafana Charm over the grafana-dashboard relation using the grafana-dashboard interface."
value = "grafana-dashboards-provider"
}
2 changes: 1 addition & 1 deletion terraform/terraform.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

terraform {
Expand Down
10 changes: 0 additions & 10 deletions terraform/terraform.tfvars

This file was deleted.

15 changes: 3 additions & 12 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

variable "model_name" {
description = "Name of Juju model to deploy application to"
type = string
Expand All @@ -14,15 +17,3 @@ variable "grafana-config" {
description = "Additional configuration for the Grafana"
default = {}
}

variable "metrics_remote_write_offer_url" {
description = "Prometheus offer URL for `send-remote-write` endpoint"
type = string
default = ""
}

variable "logging_offer_url" {
description = "Loki offer URL for `logging-consumer` endpoint"
type = string
default = ""
}

0 comments on commit a9ac578

Please sign in to comment.