mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-19 17:59:05 -05:00
Add lifecycle block schema to ModuleCall
Signed-off-by: Diogenes Fernandes <diofeher@gmail.com>
This commit is contained in:
committed by
Diógenes Fernandes
parent
7bcc6464ed
commit
ca53b2521d
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user