Skip to content

Commit

Permalink
Use sanitizeName instead of strings.replaceAll
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMoyles committed Jul 2, 2024
1 parent 8086205 commit 8936cc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
14 changes: 10 additions & 4 deletions genesyscloud/resource_exporter/resource_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,19 @@ func SetRegisterExporter(resources map[string]*ResourceExporter) {
}

var (
ExportAsData []string
dsMutex sync.Mutex
ExportAsData []string
dsMutex sync.Mutex
resourceNameSanitizer = NewSanitizerProvider()
)

// The GetDataSourceItems function adds resources to the ExportAsData []string
// The GetDataSourceItems function adds resources to the ExportAsData []string and are formatted correctly
// The ExportAsData will be checked in the genesyscloud_resource_exporter to determine resources to be exported as data source
func GetDataSourceItems(name string) {
func GetDataSourceItems(resourceName, itemName string) {
exportName := resourceName + "::" + resourceNameSanitizer.S.SanitizeResourceName(itemName)
addDataSourceItemstoExport(exportName)
}

func addDataSourceItemstoExport(name string) {
dsMutex.Lock()
defer dsMutex.Unlock()
ExportAsData = append(ExportAsData, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"log"
"strings"
//"strings"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/tfexporter_state"
"terraform-provider-genesyscloud/genesyscloud/util"
Expand Down Expand Up @@ -46,10 +46,9 @@ func getAllSites(ctx context.Context, sdkConfig *platformclientv2.Configuration)
for _, managedSite := range *managedSites {
resources[*managedSite.Id] = &resourceExporter.ResourceMeta{Name: *managedSite.Name}
// When exporting managed sites, they must automatically be exported as data source
// Managed sites are added to the ExportAsData []string in resource_exporter and formatted correctly for export as data source
// Managed sites are added to the ExportAsData []string in resource_exporter
if tfexporter_state.IsExporterActive() {
managedSiteDataSource := resourceName + "::" + strings.ReplaceAll(*managedSite.Name, " ", "_")
resourceExporter.GetDataSourceItems(managedSiteDataSource)
resourceExporter.GetDataSourceItems(resourceName, *managedSite.Name)
}
}
return resources, nil
Expand Down

0 comments on commit 8936cc4

Please sign in to comment.