Skip to content

Commit 6644b8e

Browse files
feat(tools): add terraform resource issue template generator (#2231)
* feat(tools): add terraform resource issue template generator * fix: remove deprecated import * fix: source dropdown options from catalog files * fix: update template to use generated resources * feat: retrieve resources from schema * fix: remove stale files * fix: permissions from linter * test: run script for PR * fix: remove run on PR * fix: address comments Co-authored-by: Jeroen Op 't Eynde <[email protected]> --------- Co-authored-by: Jeroen Op 't Eynde <[email protected]>
1 parent 168214e commit 6644b8e

File tree

5 files changed

+381
-0
lines changed

5 files changed

+381
-0
lines changed
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: Bug Report (Enhanced)
2+
description: File a bug report with resource dropdown
3+
type: "bug"
4+
projects: ["grafana/513"]
5+
body:
6+
- type: input
7+
id: terraform_version
8+
attributes:
9+
label: Terraform Version
10+
- type: input
11+
id: terraform_grafana_provider_version
12+
attributes:
13+
label: Terraform Grafana Provider Version
14+
- type: input
15+
id: grafana_version
16+
attributes:
17+
label: Grafana Version
18+
- type: dropdown
19+
id: affected_resources
20+
attributes:
21+
label: Affected Resource(s)
22+
description: |
23+
Select the terraform resources or data sources this issue relates to.
24+
💡 Tip: Click the dropdown and start typing to quickly find items
25+
multiple: true
26+
options:
27+
- Other (please describe in the issue)
28+
- grafana_annotation (resource)
29+
- grafana_apps_dashboard_dashboard_v1beta1 (resource)
30+
- grafana_apps_playlist_playlist_v0alpha1 (resource)
31+
- grafana_cloud_access_policies (data source)
32+
- grafana_cloud_access_policy (resource)
33+
- grafana_cloud_access_policy_token (resource)
34+
- grafana_cloud_ips (data source)
35+
- grafana_cloud_org_member (resource)
36+
- grafana_cloud_organization (data source)
37+
- grafana_cloud_plugin_installation (resource)
38+
- grafana_cloud_private_data_source_connect_network (resource)
39+
- grafana_cloud_private_data_source_connect_network_token (resource)
40+
- grafana_cloud_private_data_source_connect_networks (data source)
41+
- grafana_cloud_provider_aws_account (data source)
42+
- grafana_cloud_provider_aws_account (resource)
43+
- grafana_cloud_provider_aws_cloudwatch_scrape_job (data source)
44+
- grafana_cloud_provider_aws_cloudwatch_scrape_job (resource)
45+
- grafana_cloud_provider_aws_cloudwatch_scrape_jobs (data source)
46+
- grafana_cloud_provider_aws_resource_metadata_scrape_job (resource)
47+
- grafana_cloud_provider_azure_credential (data source)
48+
- grafana_cloud_provider_azure_credential (resource)
49+
- grafana_cloud_stack (data source)
50+
- grafana_cloud_stack (resource)
51+
- grafana_cloud_stack_service_account (resource)
52+
- grafana_cloud_stack_service_account_token (resource)
53+
- grafana_connections_metrics_endpoint_scrape_job (data source)
54+
- grafana_connections_metrics_endpoint_scrape_job (resource)
55+
- grafana_contact_point (resource)
56+
- grafana_dashboard (data source)
57+
- grafana_dashboard (resource)
58+
- grafana_dashboard_permission (resource)
59+
- grafana_dashboard_permission_item (resource)
60+
- grafana_dashboard_public (resource)
61+
- grafana_dashboards (data source)
62+
- grafana_data_source (data source)
63+
- grafana_data_source (resource)
64+
- grafana_data_source_config (resource)
65+
- grafana_data_source_config_lbac_rules (resource)
66+
- grafana_data_source_permission (resource)
67+
- grafana_data_source_permission_item (resource)
68+
- grafana_fleet_management_collector (data source)
69+
- grafana_fleet_management_collector (resource)
70+
- grafana_fleet_management_collectors (data source)
71+
- grafana_fleet_management_pipeline (resource)
72+
- grafana_folder (data source)
73+
- grafana_folder (resource)
74+
- grafana_folder_permission (resource)
75+
- grafana_folder_permission_item (resource)
76+
- grafana_folders (data source)
77+
- grafana_frontend_o11y_app (data source)
78+
- grafana_frontend_o11y_app (resource)
79+
- grafana_k6_installation (resource)
80+
- grafana_k6_load_test (data source)
81+
- grafana_k6_load_test (resource)
82+
- grafana_k6_load_tests (data source)
83+
- grafana_k6_project (data source)
84+
- grafana_k6_project (resource)
85+
- grafana_k6_project_limits (data source)
86+
- grafana_k6_project_limits (resource)
87+
- grafana_k6_projects (data source)
88+
- grafana_library_panel (data source)
89+
- grafana_library_panel (resource)
90+
- grafana_library_panels (data source)
91+
- grafana_machine_learning_alert (resource)
92+
- grafana_machine_learning_holiday (resource)
93+
- grafana_machine_learning_job (resource)
94+
- grafana_machine_learning_outlier_detector (resource)
95+
- grafana_message_template (resource)
96+
- grafana_mute_timing (resource)
97+
- grafana_notification_policy (resource)
98+
- grafana_oncall_escalation (resource)
99+
- grafana_oncall_escalation_chain (data source)
100+
- grafana_oncall_escalation_chain (resource)
101+
- grafana_oncall_integration (data source)
102+
- grafana_oncall_integration (resource)
103+
- grafana_oncall_label (data source)
104+
- grafana_oncall_on_call_shift (resource)
105+
- grafana_oncall_outgoing_webhook (data source)
106+
- grafana_oncall_outgoing_webhook (resource)
107+
- grafana_oncall_route (resource)
108+
- grafana_oncall_schedule (data source)
109+
- grafana_oncall_schedule (resource)
110+
- grafana_oncall_slack_channel (data source)
111+
- grafana_oncall_team (data source)
112+
- grafana_oncall_user (data source)
113+
- grafana_oncall_user_group (data source)
114+
- grafana_oncall_user_notification_rule (resource)
115+
- grafana_oncall_users (data source)
116+
- grafana_organization (data source)
117+
- grafana_organization (resource)
118+
- grafana_organization_preferences (data source)
119+
- grafana_organization_preferences (resource)
120+
- grafana_organization_user (data source)
121+
- grafana_playlist (resource)
122+
- grafana_report (resource)
123+
- grafana_role (data source)
124+
- grafana_role (resource)
125+
- grafana_role_assignment (resource)
126+
- grafana_role_assignment_item (resource)
127+
- grafana_rule_group (resource)
128+
- grafana_service_account (data source)
129+
- grafana_service_account (resource)
130+
- grafana_service_account_permission (resource)
131+
- grafana_service_account_permission_item (resource)
132+
- grafana_service_account_token (resource)
133+
- grafana_slo (resource)
134+
- grafana_slos (data source)
135+
- grafana_sso_settings (resource)
136+
- grafana_synthetic_monitoring_check (resource)
137+
- grafana_synthetic_monitoring_check_alerts (resource)
138+
- grafana_synthetic_monitoring_installation (resource)
139+
- grafana_synthetic_monitoring_probe (data source)
140+
- grafana_synthetic_monitoring_probe (resource)
141+
- grafana_synthetic_monitoring_probes (data source)
142+
- grafana_team (data source)
143+
- grafana_team (resource)
144+
- grafana_team_external_group (resource)
145+
- grafana_user (data source)
146+
- grafana_user (resource)
147+
- grafana_users (data source)
148+
- type: textarea
149+
id: terraform_configuration_files
150+
attributes:
151+
label: Terraform Configuration Files
152+
placeholder: |
153+
```hcl
154+
# Copy-paste your Terraform configurations here
155+
```
156+
- type: textarea
157+
id: expected_behavior
158+
attributes:
159+
label: Expected Behavior
160+
placeholder: What should have happened?
161+
- type: textarea
162+
id: actual_behavior
163+
attributes:
164+
label: Actual Behavior
165+
placeholder: What actually happened?
166+
- type: textarea
167+
id: steps_to_reproduce
168+
attributes:
169+
label: Steps to Reproduce
170+
placeholder: |
171+
Please list the steps required to reproduce the issue, for example:
172+
1. `terraform apply`
173+
- type: textarea
174+
id: important_factoids
175+
attributes:
176+
label: Important Factoids
177+
placeholder: |
178+
Are there anything atypical about your accounts that we should know?
179+
- type: textarea
180+
id: references
181+
attributes:
182+
label: References
183+
placeholder: |
184+
- GH-1234

.github/workflows/update-schema.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: update provider schema
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'internal/**'
9+
- 'pkg/**'
10+
- 'go.mod'
11+
- 'go.sum'
12+
workflow_dispatch: {}
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
update-schema:
19+
name: update provider schema
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
24+
with:
25+
go-version-file: go.mod
26+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
27+
28+
- name: build provider
29+
run: go build .
30+
31+
- name: update schema and generate template
32+
run: go run scripts/generate_issue_template.go --update-schema
33+
34+
- name: commit changes
35+
run: |
36+
git config user.name "github-actions[bot]"
37+
git config user.email "github-actions[bot]@users.noreply.github.com"
38+
git add provider_schema.json .github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml
39+
git diff --cached --quiet || git commit -m "chore: update provider schema and issue template"
40+
git push

GNUmakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,9 @@ docs:
7474

7575
linkcheck:
7676
docker run --rm --entrypoint sh -v "$$PWD:$$PWD" -w "$$PWD" python:3.11-alpine -c "pip3 install linkchecker && linkchecker --config .linkcheckerrc docs"
77+
78+
update-schema:
79+
go run scripts/generate_issue_template.go --update-schema
80+
81+
generate-issue-template:
82+
go run scripts/generate_issue_template.go

provider_schema.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

scripts/generate_issue_template.go

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
package main
2+
3+
// This file generates GitHub issue templates with terraform resource/data source dropdowns.
4+
// It sources component names from the provider schema (definitive source of truth).
5+
6+
import (
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
"os/exec"
11+
"sort"
12+
"strings"
13+
)
14+
15+
type ProviderSchema struct {
16+
ProviderSchemas map[string]struct {
17+
ResourceSchemas map[string]interface{} `json:"resource_schemas"`
18+
DataSourceSchemas map[string]interface{} `json:"data_source_schemas"`
19+
} `json:"provider_schemas"`
20+
}
21+
22+
func main() {
23+
updateSchema := len(os.Args) > 1 && (os.Args[1] == "--update-schema" || os.Args[1] == "-u")
24+
25+
// Load or generate schema
26+
schema := loadSchema(updateSchema)
27+
28+
// Extract resources
29+
var resources []string
30+
grafanaProvider := schema.ProviderSchemas["registry.terraform.io/grafana/grafana"]
31+
32+
for name := range grafanaProvider.ResourceSchemas {
33+
resources = append(resources, name+" (resource)")
34+
}
35+
for name := range grafanaProvider.DataSourceSchemas {
36+
resources = append(resources, name+" (data source)")
37+
}
38+
39+
// Add "Other" option for cases not covered
40+
resources = append(resources, "Other (please describe in the issue)")
41+
42+
sort.Strings(resources)
43+
44+
// Generate template
45+
generateTemplate(resources)
46+
fmt.Printf("Generated issue template with %d resources\n", len(resources))
47+
}
48+
49+
func loadSchema(update bool) ProviderSchema {
50+
schemaFile := "provider_schema.json"
51+
52+
// Use existing schema unless updating
53+
if !update {
54+
if data, err := os.ReadFile(schemaFile); err == nil {
55+
var schema ProviderSchema
56+
if json.Unmarshal(data, &schema) == nil {
57+
fmt.Println("Using existing schema")
58+
return schema
59+
}
60+
}
61+
}
62+
63+
// Generate new schema
64+
fmt.Println("Generating schema...")
65+
cmd := exec.Command("./scripts/generate_schema.sh")
66+
data, err := cmd.Output()
67+
if err != nil {
68+
panic(fmt.Sprintf("Failed to generate schema: %v", err))
69+
}
70+
71+
var schema ProviderSchema
72+
if err := json.Unmarshal(data, &schema); err != nil {
73+
panic(fmt.Sprintf("Invalid schema JSON: %v", err))
74+
}
75+
76+
// Save schema
77+
os.WriteFile(schemaFile, data, 0600)
78+
fmt.Println("Schema updated")
79+
return schema
80+
}
81+
82+
func generateTemplate(resources []string) {
83+
os.MkdirAll(".github/ISSUE_TEMPLATE", 0755)
84+
85+
template := `# NOTE: this template is automatically generated
86+
name: Bug Report (Enhanced)
87+
description: File a bug report with resource dropdown
88+
type: "bug"
89+
projects: ["grafana/513"]
90+
body:
91+
- type: input
92+
id: terraform_version
93+
attributes:
94+
label: Terraform Version
95+
- type: input
96+
id: terraform_grafana_provider_version
97+
attributes:
98+
label: Terraform Grafana Provider Version
99+
- type: input
100+
id: grafana_version
101+
attributes:
102+
label: Grafana Version
103+
- type: dropdown
104+
id: affected_resources
105+
attributes:
106+
label: Affected Resource(s)
107+
description: |
108+
Select the terraform resources or data sources this issue relates to.
109+
💡 Tip: Click the dropdown and start typing to quickly find items
110+
multiple: true
111+
options:
112+
` + " - " + strings.Join(resources, "\n - ") + `
113+
- type: textarea
114+
id: terraform_configuration_files
115+
attributes:
116+
label: Terraform Configuration Files
117+
placeholder: |
118+
` + "```hcl\n # Copy-paste your Terraform configurations here\n ```" + `
119+
- type: textarea
120+
id: expected_behavior
121+
attributes:
122+
label: Expected Behavior
123+
placeholder: What should have happened?
124+
- type: textarea
125+
id: actual_behavior
126+
attributes:
127+
label: Actual Behavior
128+
placeholder: What actually happened?
129+
- type: textarea
130+
id: steps_to_reproduce
131+
attributes:
132+
label: Steps to Reproduce
133+
placeholder: |
134+
Please list the steps required to reproduce the issue, for example:
135+
1. ` + "`terraform apply`" + `
136+
- type: textarea
137+
id: important_factoids
138+
attributes:
139+
label: Important Factoids
140+
placeholder: |
141+
Are there anything atypical about your accounts that we should know?
142+
- type: textarea
143+
id: references
144+
attributes:
145+
label: References
146+
placeholder: |
147+
- GH-1234`
148+
149+
os.WriteFile(".github/ISSUE_TEMPLATE/3-bug-report-enhanced.yml", []byte(template), 0600)
150+
}

0 commit comments

Comments
 (0)