-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlifecycle_test.go
46 lines (40 loc) · 961 Bytes
/
lifecycle_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2023 Volvo Car Corporation
// SPDX-License-Identifier: Apache-2.0
package terra
import (
"bytes"
"fmt"
"log/slog"
"github.com/golingon/lingon/pkg/internal/hcl"
)
func ExampleLifecycle() {
type lifecycleBlock struct {
Lifecycle *Lifecycle `hcl:"lifecycle,block"`
}
tagsRef := ReferenceAsString(
ReferenceResource(&dummyResource{}).Append(
"tags",
),
)
d := lifecycleBlock{
Lifecycle: &Lifecycle{
CreateBeforeDestroy: Bool(true),
PreventDestroy: Bool(true),
IgnoreChanges: IgnoreChanges(tagsRef),
ReplaceTriggeredBy: ReplaceTriggeredBy(tagsRef),
},
}
var b bytes.Buffer
if err := hcl.EncodeRaw(&b, d); err != nil {
slog.Error("encoding lifecycle", "err", err)
return
}
fmt.Println(b.String())
// Output:
// lifecycle {
// create_before_destroy = true
// prevent_destroy = true
// ignore_changes = [tags]
// replace_triggered_by = [dummy.dummy.tags]
// }
}