]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/terraform/terraform/transform_orphan_output.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / transform_orphan_output.go
CommitLineData
bae9f6d2
JC
1package terraform
2
3import (
4 "log"
5
107c1cdb
ND
6 "github.com/hashicorp/terraform/addrs"
7 "github.com/hashicorp/terraform/configs"
8 "github.com/hashicorp/terraform/states"
bae9f6d2
JC
9)
10
11// OrphanOutputTransformer finds the outputs that aren't present
12// in the given config that are in the state and adds them to the graph
13// for deletion.
14type OrphanOutputTransformer struct {
107c1cdb
ND
15 Config *configs.Config // Root of config tree
16 State *states.State // State is the root state
bae9f6d2
JC
17}
18
19func (t *OrphanOutputTransformer) Transform(g *Graph) error {
20 if t.State == nil {
21 log.Printf("[DEBUG] No state, no orphan outputs")
22 return nil
23 }
24
15c0b25d
AP
25 for _, ms := range t.State.Modules {
26 if err := t.transform(g, ms); err != nil {
27 return err
bae9f6d2
JC
28 }
29 }
15c0b25d
AP
30 return nil
31}
bae9f6d2 32
107c1cdb 33func (t *OrphanOutputTransformer) transform(g *Graph, ms *states.Module) error {
15c0b25d 34 if ms == nil {
bae9f6d2
JC
35 return nil
36 }
37
107c1cdb 38 moduleAddr := ms.Addr
bae9f6d2 39
15c0b25d
AP
40 // Get the config for this path, which is nil if the entire module has been
41 // removed.
107c1cdb
ND
42 var outputs map[string]*configs.Output
43 if c := t.Config.DescendentForInstance(moduleAddr); c != nil {
44 outputs = c.Module.Outputs
15c0b25d 45 }
bae9f6d2 46
107c1cdb
ND
47 // An output is "orphaned" if it's present in the state but not declared
48 // in the configuration.
49 for name := range ms.OutputValues {
50 if _, exists := outputs[name]; exists {
51 continue
52 }
15c0b25d 53
107c1cdb
ND
54 g.Add(&NodeOutputOrphan{
55 Addr: addrs.OutputValue{Name: name}.Absolute(moduleAddr),
56 })
bae9f6d2
JC
57 }
58
59 return nil
60}