forked from hashicorp/terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.go
More file actions
114 lines (99 loc) · 2.9 KB
/
objects.go
File metadata and controls
114 lines (99 loc) · 2.9 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package jsonchecks
import (
"fmt"
"github.com/hashicorp/terraform/internal/addrs"
)
type staticObjectAddr map[string]interface{}
func makeStaticObjectAddr(addr addrs.ConfigCheckable) staticObjectAddr {
ret := map[string]interface{}{
"to_display": addr.String(),
}
switch addr := addr.(type) {
case addrs.ConfigResource:
if kind := addr.CheckableKind(); kind != addrs.CheckableResource {
// Something has gone very wrong
panic(fmt.Sprintf("%T has CheckableKind %s", addr, kind))
}
ret["kind"] = "resource"
switch addr.Resource.Mode {
case addrs.ManagedResourceMode:
ret["mode"] = "managed"
case addrs.DataResourceMode:
ret["mode"] = "data"
case addrs.EphemeralResourceMode:
ret["mode"] = "ephemeral"
default:
panic(fmt.Sprintf("unsupported resource mode %#v", addr.Resource.Mode))
}
ret["type"] = addr.Resource.Type
ret["name"] = addr.Resource.Name
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
case addrs.ConfigOutputValue:
if kind := addr.CheckableKind(); kind != addrs.CheckableOutputValue {
// Something has gone very wrong
panic(fmt.Sprintf("%T has CheckableKind %s", addr, kind))
}
ret["kind"] = "output_value"
ret["name"] = addr.OutputValue.Name
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
case addrs.ConfigCheck:
if kind := addr.CheckableKind(); kind != addrs.CheckableCheck {
// Something has gone very wrong
panic(fmt.Sprintf("%T has CheckableKind %s", addr, kind))
}
ret["kind"] = "check"
ret["name"] = addr.Check.Name
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
case addrs.ConfigInputVariable:
if kind := addr.CheckableKind(); kind != addrs.CheckableInputVariable {
// Something has gone very wrong
panic(fmt.Sprintf("%T has CheckableKind %s", addr, kind))
}
ret["kind"] = "var"
ret["name"] = addr.Variable.Name
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
default:
panic(fmt.Sprintf("unsupported ConfigCheckable implementation %T", addr))
}
return ret
}
type dynamicObjectAddr map[string]interface{}
func makeDynamicObjectAddr(addr addrs.Checkable) dynamicObjectAddr {
ret := map[string]interface{}{
"to_display": addr.String(),
}
switch addr := addr.(type) {
case addrs.AbsResourceInstance:
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
if addr.Resource.Key != addrs.NoKey {
ret["instance_key"] = addr.Resource.Key
}
case addrs.AbsOutputValue:
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
case addrs.AbsCheck:
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
case addrs.AbsInputVariableInstance:
if !addr.Module.IsRoot() {
ret["module"] = addr.Module.String()
}
default:
panic(fmt.Sprintf("unsupported Checkable implementation %T", addr))
}
return ret
}