Skip to content

Commit

Permalink
generate docs with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thepalbi committed Sep 24, 2024
1 parent 49f6fa5 commit 31f3cb8
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 96 deletions.
3 changes: 3 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
77 changes: 77 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
101 changes: 21 additions & 80 deletions docs/resources/cloud_provider_aws_cloudwatch_scrape_job.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,97 +31,38 @@ 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"
aws_account_resource_id = grafana_cloud_provider_aws_account.test.resource_id
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
}
}
```
Expand Down
18 changes: 2 additions & 16 deletions internal/resources/cloud/resource_cloud_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ The changelog for this provider can be found here: <https://github.com/grafana/t

{{ .SchemaMarkdown | trimspace }}

### Managing Cloud Provider

{{ tffile "examples/resources/grafana_cloud_provider_aws_account/resource.tf" }}

{{ tffile "examples/resources/grafana_cloud_provider_aws_cloudwatch_scrape_job/resource.tf" }}

## Authentication

One, or many, of the following authentication settings must be set. Each authentication setting allows a subset of resources to be used
Expand Down

0 comments on commit 31f3cb8

Please sign in to comment.