Skip to content

Commit

Permalink
schema: Fix schema merging for terraform_remote_state data source
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Oct 6, 2023
1 parent 478ebd8 commit e7795ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion schema/schema_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (m *SchemaMerger) SchemaForModule(meta *tfmod.Meta) (*schema.BodySchema, er
remoteStateDs.Attributes["backend"].Constraint = backends.BackendTypesAsOneOfConstraint(m.terraformVersion)
delete(remoteStateDs.Attributes, "config")

depBodies := m.dependentBodyForRemoteStateDataSource(providerAddr, localRef)
depBodies := m.dependentBodyForRemoteStateDataSource(remoteStateDs, providerAddr, localRef)
for key, depBody := range depBodies {
mergedSchema.Blocks["data"].DependentBody[key] = depBody
if _, ok := mergedSchema.Blocks["check"]; ok {
Expand Down
23 changes: 10 additions & 13 deletions schema/schema_merge_remote_state_ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func isRemoteStateDataSource(pAddr tfaddr.Provider, dsName string) bool {
dsName == remoteStateDsName
}

func (sm *SchemaMerger) dependentBodyForRemoteStateDataSource(providerAddr lang.Address, localRef module.ProviderRef) map[schema.SchemaKey]*schema.BodySchema {
func (sm *SchemaMerger) dependentBodyForRemoteStateDataSource(originalBodySchema *schema.BodySchema, providerAddr lang.Address, localRef module.ProviderRef) map[schema.SchemaKey]*schema.BodySchema {
m := make(map[schema.SchemaKey]*schema.BodySchema, 0)
backendsAsCons := backends.ConfigsAsObjectConstraint(sm.terraformVersion)

Expand All @@ -49,18 +49,15 @@ func (sm *SchemaMerger) dependentBodyForRemoteStateDataSource(providerAddr lang.
},
}

dsSchema := &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"backend": {
Constraint: backends.BackendTypesAsOneOfConstraint(sm.terraformVersion),
IsRequired: true,
SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent},
},
"config": {
Constraint: objConstraint,
IsOptional: true,
},
},
dsSchema := originalBodySchema.Copy()
dsSchema.Attributes["backend"] = &schema.AttributeSchema{
Constraint: backends.BackendTypesAsOneOfConstraint(sm.terraformVersion),
IsRequired: true,
SemanticTokenModifiers: lang.SemanticTokenModifiers{lang.TokenModifierDependent},
}
dsSchema.Attributes["config"] = &schema.AttributeSchema{
Constraint: objConstraint,
IsOptional: true,
}

m[schema.NewSchemaKey(depKeys)] = dsSchema
Expand Down

0 comments on commit e7795ae

Please sign in to comment.