Skip to content

Commit

Permalink
Exporter: Skip emitting of clusters that come from more cluster sourc…
Browse files Browse the repository at this point in the history
…es (#3161)

Exporter always skipped clusters that came from the `JOB` cluster sources when it did the
listing of clusters.  But clusters may come from other sources us well, like, DLT pipeline
maintenance, and as result, they were emitted as normal clusters.

This PR adds checks for more cluster sources
  • Loading branch information
alexott committed Jan 26, 2024
1 parent 63f6464 commit ac22744
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/zclconf/go-cty/cty"
"golang.org/x/exp/slices"
)

var (
Expand All @@ -45,8 +46,8 @@ var (
globalWorkspaceConfName = "global_workspace_conf"
nameNormalizationRegex = regexp.MustCompile(`\W+`)
fileNameNormalizationRegex = regexp.MustCompile(`[^-_\w/.@]`)
jobClustersRegex = regexp.MustCompile(`^((job_cluster|task)\.[0-9]+\.new_cluster\.[0-9]+\.)`)
dltClusterRegex = regexp.MustCompile(`^(cluster\.[0-9]+\.)`)
jobClustersRegex = regexp.MustCompile(`^((job_cluster|task)\.\d+\.new_cluster\.\d+\.)`)
dltClusterRegex = regexp.MustCompile(`^(cluster\.\d+\.)`)
userDirRegex = regexp.MustCompile(`^(/Users/[^/]+)(/.*)?$`)
secretPathRegex = regexp.MustCompile(`^\{\{secrets\/([^\/]+)\/([^}]+)\}\}$`)
sqlParentRegexp = regexp.MustCompile(`^folders/(\d+)$`)
Expand Down Expand Up @@ -294,9 +295,14 @@ var resourcesMap map[string]importable = map[string]importable{
return err
}
lastActiveMs := ic.getLastActiveMs()
nonInteractiveClusters := []string{"JOB", "PIPELINE_MAINTENANCE", "PIPELINE", "SQL"}
for offset, c := range clusters {
if c.ClusterSource == "JOB" {
log.Printf("[INFO] Skipping job cluster %s", c.ClusterID)
log.Printf("[DEBUG] Cluster %s, source: %s", c.ClusterID, c.ClusterSource)
if slices.Contains(nonInteractiveClusters, string(c.ClusterSource)) {
// TODO: Should we check cluster name as well?
// jobRunClusterNameRegex = regexp.MustCompile(`^job-\d+-run-\d+$`)
// jobRunClusterNameRegex.MatchString(c.ClusterName)
log.Printf("[INFO] Skipping non-interactive cluster %s", c.ClusterID)
continue
}
if strings.HasPrefix(c.ClusterName, "terraform-") {
Expand Down

0 comments on commit ac22744

Please sign in to comment.