forked from hashicorp/terraform-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
194 lines (148 loc) · 6.35 KB
/
config.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package tfjson
import (
"encoding/json"
"errors"
)
// Config represents the complete configuration source.
type Config struct {
// A map of all provider instances across all modules in the
// configuration.
//
// The index for this field is opaque and should not be parsed. Use
// the individual fields in ProviderConfig to discern actual data
// about the provider such as name, alias, or defined module.
ProviderConfigs map[string]*ProviderConfig `json:"provider_config,omitempty"`
// The root module in the configuration. Any child modules descend
// off of here.
RootModule *ConfigModule `json:"root_module,omitempty"`
}
// Validate checks to ensure that the config is present.
func (c *Config) Validate() error {
if c == nil {
return errors.New("config is nil")
}
return nil
}
func (c *Config) UnmarshalJSON(b []byte) error {
type rawConfig Config
var config rawConfig
err := json.Unmarshal(b, &config)
if err != nil {
return err
}
*c = *(*Config)(&config)
return c.Validate()
}
// ProviderConfig describes a provider configuration instance.
type ProviderConfig struct {
// The name of the provider, ie: "aws".
Name string `json:"name,omitempty"`
// The fully-specified name of the provider, ie: "registry.terraform.io/hashicorp/aws".
FullName string `json:"full_name,omitempty"`
// The alias of the provider, ie: "us-east-1".
Alias string `json:"alias,omitempty"`
// The address of the module the provider is declared in.
ModuleAddress string `json:"module_address,omitempty"`
// Any non-special configuration values in the provider, indexed by
// key.
Expressions map[string]*Expression `json:"expressions,omitempty"`
// The defined version constraint for this provider.
VersionConstraint string `json:"version_constraint,omitempty"`
}
// ConfigModule describes a module in Terraform configuration.
type ConfigModule struct {
// The outputs defined in the module.
Outputs map[string]*ConfigOutput `json:"outputs,omitempty"`
// The resources defined in the module.
Resources []*ConfigResource `json:"resources,omitempty"`
// Any "module" stanzas within the specific module.
ModuleCalls map[string]*ModuleCall `json:"module_calls,omitempty"`
// The variables defined in the module.
Variables map[string]*ConfigVariable `json:"variables,omitempty"`
}
// ConfigOutput defines an output as defined in configuration.
type ConfigOutput struct {
// Indicates whether or not the output was marked as sensitive.
Sensitive bool `json:"sensitive,omitempty"`
// The defined value of the output.
Expression *Expression `json:"expression,omitempty"`
// The defined description of this output.
Description string `json:"description,omitempty"`
// The defined dependencies tied to this output.
DependsOn []string `json:"depends_on,omitempty"`
}
// ConfigResource is the configuration representation of a resource.
type ConfigResource struct {
// The address of the resource relative to the module that it is
// in.
Address string `json:"address,omitempty"`
// The resource mode.
Mode ResourceMode `json:"mode,omitempty"`
// The type of resource, ie: "null_resource" in
// "null_resource.foo".
Type string `json:"type,omitempty"`
// The name of the resource, ie: "foo" in "null_resource.foo".
Name string `json:"name,omitempty"`
// An opaque key representing the provider configuration this
// module uses. Note that there are more than one circumstance that
// this key will not match what is found in the ProviderConfigs
// field in the root Config structure, and as such should not be
// relied on for that purpose.
ProviderConfigKey string `json:"provider_config_key,omitempty"`
// The list of provisioner defined for this configuration. This
// will be nil if no providers are defined.
Provisioners []*ConfigProvisioner `json:"provisioners,omitempty"`
// Any non-special configuration values in the resource, indexed by
// key.
Expressions map[string]*Expression `json:"expressions,omitempty"`
// The resource's configuration schema version. With access to the
// specific Terraform provider for this resource, this can be used
// to determine the correct schema for the configuration data
// supplied in Expressions.
SchemaVersion uint64 `json:"schema_version"`
// The expression data for the "count" value in the resource.
CountExpression *Expression `json:"count_expression,omitempty"`
// The expression data for the "for_each" value in the resource.
ForEachExpression *Expression `json:"for_each_expression,omitempty"`
// The contents of the "depends_on" config directive, which
// declares explicit dependencies for this resource.
DependsOn []string `json:"depends_on,omitempty"`
}
// ConfigVariable defines a variable as defined in configuration.
type ConfigVariable struct {
// The defined default value of the variable.
Default interface{} `json:"default,omitempty"`
// The defined text description of the variable.
Description string `json:"description,omitempty"`
// Whether the variable is marked as sensitive
Sensitive bool `json:"sensitive,omitempty"`
}
// ConfigProvisioner describes a provisioner declared in a resource
// configuration.
type ConfigProvisioner struct {
// The type of the provisioner, ie: "local-exec".
Type string `json:"type,omitempty"`
// Any non-special configuration values in the provisioner, indexed by
// key.
Expressions map[string]*Expression `json:"expressions,omitempty"`
}
// ModuleCall describes a declared "module" within a configuration.
// It also contains the data for the module itself.
type ModuleCall struct {
// The contents of the "source" field.
Source string `json:"source,omitempty"`
// Any non-special configuration values in the module, indexed by
// key.
Expressions map[string]*Expression `json:"expressions,omitempty"`
// The expression data for the "count" value in the module.
CountExpression *Expression `json:"count_expression,omitempty"`
// The expression data for the "for_each" value in the module.
ForEachExpression *Expression `json:"for_each_expression,omitempty"`
// The configuration data for the module itself.
Module *ConfigModule `json:"module,omitempty"`
// The version constraint for modules that come from the registry.
VersionConstraint string `json:"version_constraint,omitempty"`
// The explicit resource dependencies for the "depends_on" value.
// As it must be a slice of references, Expression is not used.
DependsOn []string `json:"depends_on,omitempty"`
}