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

schema: Fix schema merging for terraform_remote_state data source #272

Merged
merged 1 commit into from
Oct 6, 2023
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
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
Loading