-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove global resources var The `provider` package now has a function that will expose all the resources from all subcategories of the provider This list is used to: - Used in the import docs generation command - Sent to both provider servers - Used in the tf code generation command * ML + SLO: Use common resource framework (#1433) Paving the way for TF code generation
- Loading branch information
1 parent
59ab857
commit 5177bb3
Showing
21 changed files
with
147 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import grafana_machine_learning_holiday.name "{{ id }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import grafana_machine_learning_job.name "{{ id }}" |
1 change: 1 addition & 0 deletions
1
examples/resources/grafana_machine_learning_outlier_detector/import.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import grafana_machine_learning_outlier_detector.name "{{ id }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import grafana_slo.name "{{ uuid }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// This file contains | ||
|
||
package provider | ||
|
||
import ( | ||
"github.com/grafana/terraform-provider-grafana/internal/common" | ||
"github.com/grafana/terraform-provider-grafana/internal/resources/cloud" | ||
"github.com/grafana/terraform-provider-grafana/internal/resources/grafana" | ||
"github.com/grafana/terraform-provider-grafana/internal/resources/machinelearning" | ||
"github.com/grafana/terraform-provider-grafana/internal/resources/oncall" | ||
"github.com/grafana/terraform-provider-grafana/internal/resources/slo" | ||
"github.com/grafana/terraform-provider-grafana/internal/resources/syntheticmonitoring" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func Resources() []*common.Resource { | ||
var resources []*common.Resource | ||
resources = append(resources, cloud.Resources...) | ||
resources = append(resources, machinelearning.Resources...) | ||
resources = append(resources, slo.Resources...) | ||
return resources | ||
} | ||
|
||
func resourceMap() map[string]*schema.Resource { | ||
result := make(map[string]*schema.Resource) | ||
for _, r := range Resources() { | ||
result[r.Name] = r.Schema | ||
} | ||
|
||
// TODO: Migrate to common.Resource instances (in Resources function) | ||
return mergeResourceMaps( | ||
result, | ||
grafana.ResourcesMap, | ||
syntheticmonitoring.ResourcesMap, | ||
oncall.ResourcesMap, | ||
) | ||
} | ||
|
||
func mergeResourceMaps(maps ...map[string]*schema.Resource) map[string]*schema.Resource { | ||
result := make(map[string]*schema.Resource) | ||
for _, m := range maps { | ||
for k, v := range m { | ||
result[k] = v | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/grafana/terraform-provider-grafana/internal/common" | ||
"github.com/grafana/terraform-provider-grafana/pkg/provider" | ||
) | ||
|
||
// TODO: Move to cmd, and remove global var in common | ||
|
||
func main() { | ||
p := provider.Provider("genimports") // Instantiate the provider so that all resources are registered | ||
_ = p | ||
|
||
if err := common.GenerateImportFiles(os.Args[1]); err != nil { | ||
if err := generateImportFiles(os.Args[1]); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// GenerateImportFiles generates import files for all resources that use a helper defined in this package | ||
func generateImportFiles(path string) error { | ||
for _, r := range provider.Resources() { | ||
resourcePath := filepath.Join(path, "resources", r.Name, "import.sh") | ||
if err := os.RemoveAll(resourcePath); err != nil { // Remove the file if it exists | ||
return err | ||
} | ||
|
||
if r.IDType == nil { | ||
log.Printf("Skipping import file generation for %s because it does not have an ID type\n", r.Name) | ||
continue | ||
} | ||
|
||
log.Printf("Generating import file for %s (writing to %s)\n", r.Name, resourcePath) | ||
if err := os.WriteFile(resourcePath, []byte(r.ImportExample()), 0600); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |