Skip to content

Commit

Permalink
Datasoruce tfstate (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
HemanthDogiparthi12 authored Jul 19, 2024
1 parent 537b9d8 commit 36fd4e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
9 changes: 5 additions & 4 deletions genesyscloud/resource_exporter/resource_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ type RefAttrSettings struct {
}

type ResourceInfo struct {
State *terraform.InstanceState
Name string
Type string
CtyType cty.Type
State *terraform.InstanceState
Name string
Type string
CtyType cty.Type
ResourceType string
}

// RefAttrCustomResolver allows the definition of a custom resolver for an exporter.
Expand Down
14 changes: 10 additions & 4 deletions genesyscloud/tfexporter/genesyscloud_resource_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ func (g *GenesysCloudResourceExporter) generateZipForExporter() diag.Diagnostics
}

func (g *GenesysCloudResourceExporter) buildAndExportDependsOnResourcesForFlows() diag.Diagnostics {

if g.addDependsOn {
filterList, resources, err := g.processAndBuildDependencies()
if err != nil {
Expand All @@ -559,6 +560,7 @@ func (g *GenesysCloudResourceExporter) processAndBuildDependencies() (filters []
filterList := make([]string, 0)
totalResources := make(resourceExporter.ResourceIDMetaMap)
proxy := dependentconsumers.GetDependentConsumerProxy(nil)

retrieveDependentConsumers := func(resourceKeys resourceExporter.ResourceInfo) func(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, *resourceExporter.DependencyResource, diag.Diagnostics) {
return func(ctx context.Context, clientConfig *platformclientv2.Configuration) (resourceExporter.ResourceIDMetaMap, *resourceExporter.DependencyResource, diag.Diagnostics) {
proxy = dependentconsumers.GetDependentConsumerProxy(clientConfig)
Expand Down Expand Up @@ -1017,6 +1019,7 @@ func (g *GenesysCloudResourceExporter) getResourcesForType(resType string, provi
// will block until it can acquire a pooled client config object.
instanceState, err := getResourceState(ctx, res, id, resMeta, meta)

resourceType := ""
if g.isDataSource(resType, resMeta.Name) {
g.exMutex.Lock()
res = provider.DataSourcesMap[resType]
Expand All @@ -1036,6 +1039,7 @@ func (g *GenesysCloudResourceExporter) getResourcesForType(resType string, provi
}
}
instanceState.Attributes = attributes
resourceType = "data."
}

if err != nil {
Expand All @@ -1050,10 +1054,11 @@ func (g *GenesysCloudResourceExporter) getResourcesForType(resType string, provi
}

resourceChan <- resourceExporter.ResourceInfo{
State: instanceState,
Name: resMeta.Name,
Type: resType,
CtyType: ctyType,
State: instanceState,
Name: resMeta.Name,
Type: resType,
CtyType: ctyType,
ResourceType: resourceType,
}

return nil
Expand Down Expand Up @@ -1607,6 +1612,7 @@ func (g *GenesysCloudResourceExporter) isDataSource(resType string, name string)
}

func (g *GenesysCloudResourceExporter) containsElement(elements []string, resType, name string) bool {

for _, element := range elements {
if element == resType+"::"+name || fetchByRegex(element, resType, name) {
return true
Expand Down
2 changes: 1 addition & 1 deletion genesyscloud/tfexporter/tfstate_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (t *TFStateFileWriter) writeTfState() diag.Diagnostics {
Primary: resource.State,
Provider: "provider.genesyscloud",
}
tfstate.RootModule().Resources[resource.Type+"."+resource.Name] = resourceState
tfstate.RootModule().Resources[resource.ResourceType+resource.Type+"."+resource.Name] = resourceState
}

data, err := json.MarshalIndent(tfstate, "", " ")
Expand Down

0 comments on commit 36fd4e8

Please sign in to comment.