From 31f3cb8a778c1908df087b7cf372d356dd741e58 Mon Sep 17 00:00:00 2001 From: Pablo Balbi Date: Tue, 24 Sep 2024 14:06:39 +0200 Subject: [PATCH] generate docs with examples --- GNUmakefile | 3 + docs/index.md | 77 +++++++++++++ ...loud_provider_aws_cloudwatch_scrape_job.md | 101 ++++-------------- .../resources/cloud/resource_cloud_stack.go | 18 +--- templates/index.md.tmpl | 6 ++ 5 files changed, 109 insertions(+), 96 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 39b6d7117..9c19fcaaf 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -67,5 +67,8 @@ golangci-lint: --workdir "/src" \ golangci/golangci-lint:v1.54 golangci-lint run ./... -v +docs: + go generate ./... + linkcheck: docker run --rm --entrypoint sh -v "$$PWD:$$PWD" -w "$$PWD" python:3.11-alpine -c "pip3 install linkchecker && linkchecker --config .linkcheckerrc docs" diff --git a/docs/index.md b/docs/index.md index 98735c391..eb1cf9328 100644 --- a/docs/index.md +++ b/docs/index.md @@ -226,6 +226,83 @@ resource "grafana_oncall_escalation" "example_notify_step" { - `tls_key` (String) Client TLS key (file path or literal value) to use to authenticate to the Grafana server. May alternatively be set via the `GRAFANA_TLS_KEY` environment variable. - `url` (String) The root URL of a Grafana server. May alternatively be set via the `GRAFANA_URL` environment variable. +### Managing Cloud Provider + +```terraform +data "grafana_cloud_stack" "test" { + slug = "gcloudstacktest" +} + +data "aws_iam_role" "test" { + name = "my-role" +} + +resource "grafana_cloud_provider_aws_account" "test" { + stack_id = data.grafana_cloud_stack.test.id + role_arn = data.aws_iam_role.test.arn + regions = [ + "us-east-1", + "us-east-2", + "us-west-1" + ] +} +``` + +```terraform +data "grafana_cloud_stack" "test" { + slug = "gcloudstacktest" +} + +data "aws_iam_role" "test" { + name = "my-role" +} + +resource "grafana_cloud_provider_aws_account" "test" { + stack_id = data.grafana_cloud_stack.test.id + role_arn = data.aws_iam_role.test.arn + regions = [ + "us-east-1", + "us-east-2", + "us-west-1" + ] +} + +resource "grafana_cloud_provider_aws_cloudwatch_scrape_job" "test" { + stack_id = data.grafana_cloud_stack.test.id + name = "my-cloudwatch-scrape-job" + aws_account_resource_id = grafana_cloud_provider_aws_account.test.resource_id + regions = grafana_cloud_provider_aws_account.test.regions + export_tags = true + + service { + name = "AWS/EC2" + metric { + name = "CPUUtilization" + statistics = ["Average"] + } + metric { + name = "StatusCheckFailed" + statistics = ["Maximum"] + } + scrape_interval_seconds = 300 + resource_discovery_tag_filter { + key = "k8s.io/cluster-autoscaler/enabled" + value = "true" + } + tags_to_add_to_metrics = ["eks:cluster-name"] + } + + custom_namespace { + name = "CoolApp" + metric { + name = "CoolMetric" + statistics = ["Maximum", "Sum"] + } + scrape_interval_seconds = 300 + } +} +``` + ## Authentication One, or many, of the following authentication settings must be set. Each authentication setting allows a subset of resources to be used diff --git a/docs/resources/cloud_provider_aws_cloudwatch_scrape_job.md b/docs/resources/cloud_provider_aws_cloudwatch_scrape_job.md index f90c56f31..7fc71b2ba 100644 --- a/docs/resources/cloud_provider_aws_cloudwatch_scrape_job.md +++ b/docs/resources/cloud_provider_aws_cloudwatch_scrape_job.md @@ -31,53 +31,6 @@ resource "grafana_cloud_provider_aws_account" "test" { ] } -locals { - services = [ - { - name = "AWS/EC2", - metrics = [ - { - name = "CPUUtilization", - statistics = [ - "Average", - ], - }, - { - name = "StatusCheckFailed", - statistics = [ - "Maximum", - ], - }, - ], - scrape_interval_seconds = 300, - resource_discovery_tag_filters = [ - { - key = "k8s.io/cluster-autoscaler/enabled", - value = "true", - } - ], - tags_to_add_to_metrics = [ - "eks:cluster-name", - ] - }, - ] - custom_namespaces = [ - { - name = "CoolApp", - metrics = [ - { - name = "CoolMetric", - statistics = [ - "Maximum", - "Sum", - ] - }, - ], - scrape_interval_seconds = 300, - }, - ] -} - resource "grafana_cloud_provider_aws_cloudwatch_scrape_job" "test" { stack_id = data.grafana_cloud_stack.test.id name = "my-cloudwatch-scrape-job" @@ -85,43 +38,31 @@ resource "grafana_cloud_provider_aws_cloudwatch_scrape_job" "test" { regions = grafana_cloud_provider_aws_account.test.regions export_tags = true - dynamic "service" { - for_each = local.services - content { - name = service.value.name - dynamic "metric" { - for_each = service.value.metrics - content { - name = metric.value.name - statistics = metric.value.statistics - } - } - scrape_interval_seconds = service.value.scrape_interval_seconds - dynamic "resource_discovery_tag_filter" { - for_each = service.value.resource_discovery_tag_filters - content { - key = resource_discovery_tag_filter.value.key - value = resource_discovery_tag_filter.value.value - } - - } - tags_to_add_to_metrics = service.value.tags_to_add_to_metrics + service { + name = "AWS/EC2" + metric { + name = "CPUUtilization" + statistics = ["Average"] + } + metric { + name = "StatusCheckFailed" + statistics = ["Maximum"] + } + scrape_interval_seconds = 300 + resource_discovery_tag_filter { + key = "k8s.io/cluster-autoscaler/enabled" + value = "true" } + tags_to_add_to_metrics = ["eks:cluster-name"] } - dynamic "custom_namespace" { - for_each = local.custom_namespaces - content { - name = custom_namespace.value.name - dynamic "metric" { - for_each = custom_namespace.value.metrics - content { - name = metric.value.name - statistics = metric.value.statistics - } - } - scrape_interval_seconds = custom_namespace.value.scrape_interval_seconds + custom_namespace { + name = "CoolApp" + metric { + name = "CoolMetric" + statistics = ["Maximum", "Sum"] } + scrape_interval_seconds = 300 } } ``` diff --git a/internal/resources/cloud/resource_cloud_stack.go b/internal/resources/cloud/resource_cloud_stack.go index dfc4e9849..bb87bef83 100644 --- a/internal/resources/cloud/resource_cloud_stack.go +++ b/internal/resources/cloud/resource_cloud_stack.go @@ -342,13 +342,7 @@ func readStack(ctx context.Context, d *schema.ResourceData, client *gcom.APIClie return common.WarnMissing("stack", d) } - connectionsReq := client.InstancesAPI.GetConnections(ctx, id.(string)) - connections, _, err := connectionsReq.Execute() - if err != nil { - return apiError(err) - } - - if err := flattenStack(d, stack, connections); err != nil { + if err := flattenStack(d, stack); err != nil { return diag.FromErr(err) } // Always set the wait attribute to true after creation @@ -361,7 +355,7 @@ func readStack(ctx context.Context, d *schema.ResourceData, client *gcom.APIClie return nil } -func flattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance, connections *gcom.FormattedApiInstanceConnections) error { +func flattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance) error { id := strconv.FormatInt(int64(stack.Id), 10) d.SetId(id) d.Set("name", stack.Name) @@ -416,14 +410,6 @@ func flattenStack(d *schema.ResourceData, stack *gcom.FormattedApiInstance, conn d.Set("graphite_url", stack.HmInstanceGraphiteUrl) d.Set("graphite_status", stack.HmInstanceGraphiteStatus) - if otlpURL := connections.OtlpHttpUrl; otlpURL.IsSet() { - d.Set("otlp_url", otlpURL.Get()) - } - - if influxURL := connections.InfluxUrl; influxURL.IsSet() { - d.Set("influx_url", influxURL.Get()) - } - return nil } diff --git a/templates/index.md.tmpl b/templates/index.md.tmpl index 3ff35711d..96a8a0e64 100644 --- a/templates/index.md.tmpl +++ b/templates/index.md.tmpl @@ -32,6 +32,12 @@ The changelog for this provider can be found here: