mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-23 07:33:32 -06:00
e9fe0f1118
Signed-off-by: Ronny Orot <ronny.orot@gmail.com>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package configs
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl/v2"
|
|
"github.com/opentofu/opentofu/internal/addrs"
|
|
)
|
|
|
|
// Removed represents a removed block in the configuration.
|
|
type Removed struct {
|
|
From *addrs.RemoveEndpoint
|
|
|
|
DeclRange hcl.Range
|
|
}
|
|
|
|
func decodeRemovedBlock(block *hcl.Block) (*Removed, hcl.Diagnostics) {
|
|
var diags hcl.Diagnostics
|
|
removed := &Removed{
|
|
DeclRange: block.DefRange,
|
|
}
|
|
|
|
content, moreDiags := block.Body.Content(removedBlockSchema)
|
|
diags = append(diags, moreDiags...)
|
|
|
|
if attr, exists := content.Attributes["from"]; exists {
|
|
from, traversalDiags := hcl.AbsTraversalForExpr(attr.Expr)
|
|
diags = append(diags, traversalDiags...)
|
|
if !traversalDiags.HasErrors() {
|
|
from, fromDiags := addrs.ParseRemoveEndpoint(from)
|
|
diags = append(diags, fromDiags.ToHCL()...)
|
|
removed.From = from
|
|
}
|
|
}
|
|
|
|
return removed, diags
|
|
}
|
|
|
|
var removedBlockSchema = &hcl.BodySchema{
|
|
Attributes: []hcl.AttributeSchema{
|
|
{
|
|
Name: "from",
|
|
Required: true,
|
|
},
|
|
},
|
|
}
|