diff --git a/scripts/generate_data_sources.go b/scripts/generate_data_sources.go index 06505ca1..40f17c78 100644 --- a/scripts/generate_data_sources.go +++ b/scripts/generate_data_sources.go @@ -109,6 +109,11 @@ func Main() error { var rs []string if r == "" { for path := range swagger.Paths.Paths { + resourceName := strings.Split(path, "/")[2] + log.Printf("Resource: %s", resourceName) + if !resourceExist(resourceName) { + continue + } if strings.HasSuffix(path, "{id}") { rs = append(rs, strings.Split(path, "/")[2]) } @@ -687,3 +692,23 @@ func write(data string, filename string) error { f.Write([]byte(data)) return nil } + +// Check if terraform resource exists +func resourceExist(rs string) bool { + // Format resource properly to match the file name + name := strings.ReplaceAll(rs, "-", "_") + + if !strings.HasPrefix(name, "credentials") { + name = strings.TrimSuffix(name, "s") + } + + resourceFilePath := fmt.Sprintf("internal/provider/resource_%s*.go", name) + + // Assuming the resource files are in the internal/provider directory + // Utilize glob as some resources are not matched 1-1 such as credential_stores data sources vs credential_store_static resource + matches, err := filepath.Glob(resourceFilePath) + if err != nil || len(matches) == 0 { + return false + } + return true +}