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

fix dashboard, causing missing required displayName error #609

Merged
merged 2 commits into from
Oct 24, 2024
Merged
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
3 changes: 1 addition & 2 deletions modules/bucket-events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ No requirements.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_authorize-delivery"></a> [authorize-delivery](#module\_authorize-delivery) | ../authorize-private-service | n/a |
| <a name="module_dashboard-json"></a> [dashboard-json](#module\_dashboard-json) | ../dashboard/json | n/a |
| <a name="module_dashboard"></a> [dashboard](#module\_dashboard) | ../dashboard | n/a |
| <a name="module_http"></a> [http](#module\_http) | ../dashboard/sections/http | n/a |
| <a name="module_layout"></a> [layout](#module\_layout) | ../dashboard/sections/layout | n/a |
| <a name="module_logs"></a> [logs](#module\_logs) | ../dashboard/sections/logs | n/a |
Expand All @@ -96,7 +96,6 @@ No requirements.
| Name | Type |
|------|------|
| [google-beta_google_project_service_identity.pubsub](https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/google_project_service_identity) | resource |
| [google_monitoring_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) | resource |
| [google_pubsub_subscription.dead-letter-pull-sub](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_subscription) | resource |
| [google_pubsub_subscription.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_subscription) | resource |
| [google_pubsub_subscription_iam_binding.allow-pubsub-to-ack](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_subscription_iam_binding) | resource |
Expand Down
9 changes: 5 additions & 4 deletions modules/bucket-events/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../dashboard/json"
module "dashboard" {
source = "../dashboard"

object = {
displayName = "GCS Bucket Events: ${var.bucket} in ${local.region}"
Expand All @@ -61,6 +61,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
3 changes: 1 addition & 2 deletions modules/cloudevent-broker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ No requirements.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_dashboard-json"></a> [dashboard-json](#module\_dashboard-json) | ../dashboard/json | n/a |
| <a name="module_dashboard"></a> [dashboard](#module\_dashboard) | ../dashboard | n/a |
| <a name="module_http"></a> [http](#module\_http) | ../dashboard/sections/http | n/a |
| <a name="module_layout"></a> [layout](#module\_layout) | ../dashboard/sections/layout | n/a |
| <a name="module_logs"></a> [logs](#module\_logs) | ../dashboard/sections/logs | n/a |
Expand All @@ -98,7 +98,6 @@ No requirements.

| Name | Type |
|------|------|
| [google_monitoring_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) | resource |
| [google_pubsub_topic.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_topic) | resource |
| [google_pubsub_topic_iam_binding.ingress-publishes-events](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/pubsub_topic_iam_binding) | resource |
| [google_service_account.this](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
Expand Down
9 changes: 5 additions & 4 deletions modules/cloudevent-broker/ingress.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../dashboard/json"
module "dashboard" {
source = "../dashboard"

object = {
displayName = "Cloud Events Broker Ingress: ${var.name}"
Expand All @@ -118,6 +118,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
54 changes: 54 additions & 0 deletions modules/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,60 @@

The modules in this directory define [`google_monitoring_dashboard`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) resources in a repeatable structured way.

This module itself creates a dashboard that cleans up defaulted no-op changes.

- The [Service](service/README.md) and [Job](job/README.md) modules define pre-configured dashboards for Cloud Run services and Cloud Run jobs, respectively.
- The [`cloudevent-receiver`](cloudevent-receiver/README.md) module defines a pre-configured dashboard for a Cloud Run-based event handler receiving events from a `cloudevent-trigger`.
- The modules in [`./widgets`](widgets/) define the widgets used by the dashboards, in a way that can be reused to create custom dashboards.

```hcl
// Call module to generate cleaned up json
module "dashboard" {
source = "chainguard-dev/common/infra//modules/dashboard"

object = {
displayName = "Elastic Build"
labels = { "elastic-builds" : "" }
dashboardFilters = []

mosaicLayout = {
columns = module.width.size
tiles = module.layout.tiles,
}
}
}
```

The dashboard resource should now diff properly.

<!-- BEGIN_TF_DOCS -->
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | n/a |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [google_monitoring_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_object"></a> [object](#input\_object) | Object to encode into JSON | `object({})` | n/a | yes |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
15 changes: 8 additions & 7 deletions modules/dashboard/alerts/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ SPDX-License-Identifier: Apache-2.0
module "alerts" {
for_each = var.alerts

source = "../widgets/alert"
title = each.key
source = "../widgets/alert"
title = each.key
alert_name = each.value
}

Expand All @@ -20,16 +20,16 @@ locals {
widgets = [for x in keys(var.alerts) : module.alerts[x].widget]

tiles = [for x in range(length(local.widgets)) : {
yPos = floor(x/2) * local.unit,
yPos = floor(x / 2) * local.unit,
xPos = (x % local.columns) * local.unit,
height = local.unit,
width = local.unit,
widget = local.widgets[x],
}]
}

module "dashboard-json" {
source = "../json"
module "dashboard" {
source = "../"

object = {
displayName = var.title
Expand All @@ -43,6 +43,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
17 changes: 7 additions & 10 deletions modules/dashboard/cloudevent-receiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | n/a |
No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_dashboard-json"></a> [dashboard-json](#module\_dashboard-json) | ../json | n/a |
| <a name="module_dashboard"></a> [dashboard](#module\_dashboard) | ../ | n/a |
| <a name="module_errgrp"></a> [errgrp](#module\_errgrp) | ../sections/errgrp | n/a |
| <a name="module_github"></a> [github](#module\_github) | ../sections/github | n/a |
| <a name="module_grpc"></a> [grpc](#module\_grpc) | ../sections/grpc | n/a |
Expand All @@ -92,16 +90,13 @@ No requirements.
| <a name="module_logs"></a> [logs](#module\_logs) | ../sections/logs | n/a |
| <a name="module_resources"></a> [resources](#module\_resources) | ../sections/resources | n/a |
| <a name="module_subscription"></a> [subscription](#module\_subscription) | ../sections/subscription | n/a |
| <a name="module_trigger-dashboard-jsons"></a> [trigger-dashboard-jsons](#module\_trigger-dashboard-jsons) | ../json | n/a |
| <a name="module_trigger-dashboards"></a> [trigger-dashboards](#module\_trigger-dashboards) | ../ | n/a |
| <a name="module_trigger_layout"></a> [trigger\_layout](#module\_trigger\_layout) | ../sections/layout | n/a |
| <a name="module_width"></a> [width](#module\_width) | ../sections/width | n/a |

## Resources

| Name | Type |
|------|------|
| [google_monitoring_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) | resource |
| [google_monitoring_dashboard.trigger_dashboards](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) | resource |
No resources.

## Inputs

Expand All @@ -119,5 +114,7 @@ No requirements.

## Outputs

No outputs.
| Name | Description |
|------|-------------|
| <a name="output_json"></a> [json](#output\_json) | n/a |
<!-- END_TF_DOCS -->
34 changes: 20 additions & 14 deletions modules/dashboard/cloudevent-receiver/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module "width" { source = "../sections/width" }

module "layout" {
// This funky for_each just creates one instance when split_triggers is false
for_each = var.split_triggers ? {} : {(var.service_name): ""}
for_each = toset(var.split_triggers ? [] : [var.service_name])

source = "../sections/layout"
sections = concat(
[for key in sort(keys(var.triggers)) : module.subscription[key].section],
Expand All @@ -70,10 +71,10 @@ module "layout" {
)
}

module "dashboard-json" {
for_each = var.split_triggers ? {} : {(var.service_name): ""}
module "dashboard" {
for_each = toset(var.split_triggers ? [] : [var.service_name])

source = "../json"
source = "../"

// This funky for_each just creates one instance when split_triggers is false
object = {
Expand All @@ -96,10 +97,15 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
for_each = var.split_triggers ? {} : {(var.service_name): ""}
moved {
from = google_monitoring_dashboard.dashboard
to = module.trigger_dashboard.google_monitoring_dashboard.dashboard
}

dashboard_json = module.dashboard-json[each.key].json
output "json" {
value = {
for k, v in module.dashboard : k => v.json
}
}

// Google cloud has a limit of 50 widgets per dashboard so we create a dashboard
Expand All @@ -109,7 +115,8 @@ resource "google_monitoring_dashboard" "dashboard" {
// This module is opt-in and will replace the layout module above
module "trigger_layout" {
for_each = var.split_triggers ? var.triggers : {}
source = "../sections/layout"

source = "../sections/layout"
sections = concat([module.subscription[each.key].section],
[
module.errgrp.section,
Expand All @@ -127,10 +134,10 @@ module "trigger_layout" {
// do not hit the widget limit.
//
// This resource is opt-in and will replace the dashboard resource above
module "trigger-dashboard-jsons" {
module "trigger-dashboards" {
for_each = var.split_triggers ? var.triggers : {}

source = "../json"
source = "../"

object = {
displayName = "Cloud Event Receiver: ${var.service_name} (${each.key})"
Expand All @@ -152,8 +159,7 @@ module "trigger-dashboard-jsons" {
}
}

resource "google_monitoring_dashboard" "trigger_dashboards" {
for_each = var.split_triggers ? var.triggers : {}

dashboard_json = module.trigger-dashboard-jsons[each.key].json
moved {
from = google_monitoring_dashboard.trigger_dashboards
to = module.trigger_dashboards.google_monitoring_dashboard.dashboard
}
10 changes: 3 additions & 7 deletions modules/dashboard/job/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ No requirements.

## Providers

| Name | Version |
|------|---------|
| <a name="provider_google"></a> [google](#provider\_google) | n/a |
No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_dashboard-json"></a> [dashboard-json](#module\_dashboard-json) | ../json | n/a |
| <a name="module_dashboard"></a> [dashboard](#module\_dashboard) | ../ | n/a |
| <a name="module_errgrp"></a> [errgrp](#module\_errgrp) | ../sections/errgrp | n/a |
| <a name="module_layout"></a> [layout](#module\_layout) | ../sections/layout | n/a |
| <a name="module_logs"></a> [logs](#module\_logs) | ../sections/logs | n/a |
Expand All @@ -52,9 +50,7 @@ No requirements.

## Resources

| Name | Type |
|------|------|
| [google_monitoring_dashboard.dashboard](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_dashboard) | resource |
No resources.

## Inputs

Expand Down
9 changes: 5 additions & 4 deletions modules/dashboard/job/dashboard.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module "layout" {
]
}

module "dashboard-json" {
source = "../json"
module "dashboard" {
source = "../"

object = {
displayName = "Cloud Run Job: ${var.job_name}"
Expand All @@ -57,6 +57,7 @@ module "dashboard-json" {
}
}

resource "google_monitoring_dashboard" "dashboard" {
dashboard_json = module.dashboard-json.json
moved {
from = google_monitoring_dashboard.dashboard
to = module.dashboard.google_monitoring_dashboard.dashboard
}
Loading
Loading