Skip to content

Commit

Permalink
Fix ephemeral resource merger for Terraform version < 1.10 (#431)
Browse files Browse the repository at this point in the history
* Fix ephemeral resource merger for Terraform version < 1.10

* add tf version to schema tests

* Add tests for ephemeral resource merging

---------

Co-authored-by: James Pogran <[email protected]>
  • Loading branch information
dbanck and jpogran authored Dec 12, 2024
1 parent c0ab11d commit 081547f
Show file tree
Hide file tree
Showing 2 changed files with 392 additions and 19 deletions.
42 changes: 23 additions & 19 deletions schema/schema_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,35 @@ func (m *SchemaMerger) SchemaForModule(meta *tfmod.Meta) (*schema.BodySchema, er
}
}

for erName, erSchema := range pSchema.EphemeralResources {
depKeys := schema.DependencyKeys{
Labels: []schema.LabelDependent{
{Index: 0, Value: erName},
},
Attributes: []schema.AttributeDependent{
{
Name: "provider",
Expr: schema.ExpressionValue{
Address: providerAddr,
},
},
},
}
mergedSchema.Blocks["ephemeral"].DependentBody[schema.NewSchemaKey(depKeys)] = erSchema

// No explicit association is required
// if the ephemeral resource prefix matches provider name
if typeBelongsToProvider(erName, localRef) {
// Ephemeral resources were introduced in Terraform 1.10, so we don't need to
// merge them for older versions
if m.terraformVersion.GreaterThanOrEqual(v1_10) {
for erName, erSchema := range pSchema.EphemeralResources {
depKeys := schema.DependencyKeys{
Labels: []schema.LabelDependent{
{Index: 0, Value: erName},
},
Attributes: []schema.AttributeDependent{
{
Name: "provider",
Expr: schema.ExpressionValue{
Address: providerAddr,
},
},
},
}
mergedSchema.Blocks["ephemeral"].DependentBody[schema.NewSchemaKey(depKeys)] = erSchema

// No explicit association is required
// if the ephemeral resource prefix matches provider name
if typeBelongsToProvider(erName, localRef) {
depKeys := schema.DependencyKeys{
Labels: []schema.LabelDependent{
{Index: 0, Value: erName},
},
}
mergedSchema.Blocks["ephemeral"].DependentBody[schema.NewSchemaKey(depKeys)] = erSchema
}
}
}

Expand Down
Loading

0 comments on commit 081547f

Please sign in to comment.