Add lifecycle block schema to ModuleCall

Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
Diogenes Fernandes
2025-07-21 17:06:12 -03:00
committed by Diógenes Fernandes
parent 7bcc6464ed
commit ca53b2521d

View File

@@ -110,9 +110,28 @@ func decodeModuleBlock(block *hcl.Block, override bool) (*ModuleCall, hcl.Diagno
mc.Providers = append(mc.Providers, providers...)
}
var seenLifecycle *hcl.Block
var seenEscapeBlock *hcl.Block
for _, block := range content.Blocks {
switch block.Type {
case "lifecycle":
if seenLifecycle != nil {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Duplicate lifecycle block",
Detail: fmt.Sprintf("This resource already has a lifecycle block at %s.", seenLifecycle.DefRange),
Subject: &block.DefRange,
})
continue
}
seenLifecycle = block
lcContent, lcDiags := block.Body.Content(moduleLifecycleBlockSchema)
diags = append(diags, lcDiags...)
if attr, exists := lcContent.Attributes["enabled"]; exists {
mc.Enabled = attr.Expr
}
case "_":
if seenEscapeBlock != nil {
diags = append(diags, &hcl.Diagnostic{
@@ -368,6 +387,14 @@ var moduleBlockSchema = &hcl.BodySchema{
},
}
var moduleLifecycleBlockSchema = &hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{
Name: "enabled",
},
},
}
func moduleSourceAddrEntersNewPackage(addr addrs.ModuleSource) bool {
switch addr.(type) {
case nil: