Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tf state for DataSources #1170

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading