Skip to content

Commit 667a88c

Browse files
authored
Add support for replace_triggered_by in lifecycle (#1401)
Co-authored-by: zjhe <hezijie@microsoft.com>
1 parent dbbf2b7 commit 667a88c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

terraform/configs/resource.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type ManagedResource struct {
4242
PreventDestroy bool
4343
IgnoreChanges []hcl.Traversal
4444
IgnoreAllChanges bool
45+
ReplaceTriggeredBy []hcl.Traversal
4546

4647
CreateBeforeDestroySet bool
4748
PreventDestroySet bool
@@ -236,6 +237,32 @@ func decodeResourceBlock(block *hcl.Block) (*Resource, hcl.Diagnostics) {
236237
}
237238

238239
}
240+
if attr, exists := lcContent.Attributes["replace_triggered_by"]; exists {
241+
242+
// ignore_changes can either be a list of relative traversals
243+
// or it can be just the keyword "all" to ignore changes to this
244+
// resource entirely.
245+
// ignore_changes = [ami, instance_type]
246+
// ignore_changes = all
247+
// We also allow two legacy forms for compatibility with earlier
248+
// versions:
249+
// ignore_changes = ["ami", "instance_type"]
250+
// ignore_changes = ["*"]
251+
252+
exprs, listDiags := hcl.ExprList(attr.Expr)
253+
diags = append(diags, listDiags...)
254+
255+
for _, expr := range exprs {
256+
expr, shimDiags := shimTraversalInString(expr, false)
257+
diags = append(diags, shimDiags...)
258+
259+
traversal, travDiags := hcl.RelTraversalForExpr(expr)
260+
diags = append(diags, travDiags...)
261+
if len(traversal) != 0 {
262+
r.Managed.ReplaceTriggeredBy = append(r.Managed.ReplaceTriggeredBy, traversal)
263+
}
264+
}
265+
}
239266

240267
case "connection":
241268
if seenConnection != nil {
@@ -568,5 +595,8 @@ var resourceLifecycleBlockSchema = &hcl.BodySchema{
568595
{
569596
Name: "ignore_changes",
570597
},
598+
{
599+
Name: "replace_triggered_by",
600+
},
571601
},
572602
}

0 commit comments

Comments
 (0)