diff options
author | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-09 15:59:15 +0200 |
---|---|---|
committer | Alexandre Garand <alexandre.garand@fretlink.com> | 2019-08-09 16:39:21 +0200 |
commit | 863486a6b71ed0e562a3965bed56465d007b1418 (patch) | |
tree | e93f6a687695af86d54237ec9f575d4ef104222d /vendor/github.com/hashicorp/terraform/command/format/state.go | |
parent | 49c1c7b4dc69ffb9ab52330e6dc52ccdd6351087 (diff) | |
download | terraform-provider-statuscake-add_contact_groups.tar.gz terraform-provider-statuscake-add_contact_groups.tar.zst terraform-provider-statuscake-add_contact_groups.zip |
update vendor and go.modadd_contact_groups
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/command/format/state.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/command/format/state.go | 160 |
1 files changed, 98 insertions, 62 deletions
diff --git a/vendor/github.com/hashicorp/terraform/command/format/state.go b/vendor/github.com/hashicorp/terraform/command/format/state.go index f411ef9..be1ea24 100644 --- a/vendor/github.com/hashicorp/terraform/command/format/state.go +++ b/vendor/github.com/hashicorp/terraform/command/format/state.go | |||
@@ -75,11 +75,14 @@ func State(opts *StateOpts) string { | |||
75 | v := m.OutputValues[k] | 75 | v := m.OutputValues[k] |
76 | p.buf.WriteString(fmt.Sprintf("%s = ", k)) | 76 | p.buf.WriteString(fmt.Sprintf("%s = ", k)) |
77 | p.writeValue(v.Value, plans.NoOp, 0) | 77 | p.writeValue(v.Value, plans.NoOp, 0) |
78 | p.buf.WriteString("\n\n") | 78 | p.buf.WriteString("\n") |
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | return opts.Color.Color(strings.TrimSpace(p.buf.String())) | 82 | trimmedOutput := strings.TrimSpace(p.buf.String()) |
83 | trimmedOutput += "[reset]" | ||
84 | |||
85 | return opts.Color.Color(trimmedOutput) | ||
83 | 86 | ||
84 | } | 87 | } |
85 | 88 | ||
@@ -95,81 +98,114 @@ func formatStateModule(p blockBodyDiffPrinter, m *states.Module, schemas *terraf | |||
95 | // Go through each resource and begin building up the output. | 98 | // Go through each resource and begin building up the output. |
96 | for _, key := range names { | 99 | for _, key := range names { |
97 | for k, v := range m.Resources[key].Instances { | 100 | for k, v := range m.Resources[key].Instances { |
101 | // keep these in order to keep the current object first, and | ||
102 | // provide deterministic output for the deposed objects | ||
103 | type obj struct { | ||
104 | header string | ||
105 | instance *states.ResourceInstanceObjectSrc | ||
106 | } | ||
107 | instances := []obj{} | ||
108 | |||
98 | addr := m.Resources[key].Addr | 109 | addr := m.Resources[key].Addr |
99 | 110 | ||
100 | taintStr := "" | 111 | taintStr := "" |
101 | if v.Current.Status == 'T' { | 112 | if v.Current != nil && v.Current.Status == 'T' { |
102 | taintStr = "(tainted)" | 113 | taintStr = " (tainted)" |
103 | } | 114 | } |
104 | p.buf.WriteString(fmt.Sprintf("# %s: %s\n", addr.Absolute(m.Addr).Instance(k), taintStr)) | 115 | |
105 | 116 | instances = append(instances, | |
106 | var schema *configschema.Block | 117 | obj{fmt.Sprintf("# %s:%s\n", addr.Absolute(m.Addr).Instance(k), taintStr), v.Current}) |
107 | provider := m.Resources[key].ProviderConfig.ProviderConfig.StringCompact() | 118 | |
108 | if _, exists := schemas.Providers[provider]; !exists { | 119 | for dk, v := range v.Deposed { |
109 | // This should never happen in normal use because we should've | 120 | instances = append(instances, |
110 | // loaded all of the schemas and checked things prior to this | 121 | obj{fmt.Sprintf("# %s: (deposed object %s)\n", addr.Absolute(m.Addr).Instance(k), dk), v}) |
111 | // point. We can't return errors here, but since this is UI code | ||
112 | // we will try to do _something_ reasonable. | ||
113 | p.buf.WriteString(fmt.Sprintf("# missing schema for provider %q\n\n", provider)) | ||
114 | continue | ||
115 | } | 122 | } |
116 | 123 | ||
117 | switch addr.Mode { | 124 | // Sort the instances for consistent output. |
118 | case addrs.ManagedResourceMode: | 125 | // Starting the sort from the second index, so the current instance |
119 | schema, _ = schemas.ResourceTypeConfig( | 126 | // is always first. |
120 | provider, | 127 | sort.Slice(instances[1:], func(i, j int) bool { |
121 | addr.Mode, | 128 | return instances[i+1].header < instances[j+1].header |
122 | addr.Type, | 129 | }) |
123 | ) | 130 | |
124 | if schema == nil { | 131 | for _, obj := range instances { |
125 | p.buf.WriteString(fmt.Sprintf( | 132 | header := obj.header |
126 | "# missing schema for provider %q resource type %s\n\n", provider, addr.Type)) | 133 | instance := obj.instance |
134 | p.buf.WriteString(header) | ||
135 | if instance == nil { | ||
136 | // this shouldn't happen, but there's nothing to do here so | ||
137 | // don't panic below. | ||
127 | continue | 138 | continue |
128 | } | 139 | } |
129 | 140 | ||
130 | p.buf.WriteString(fmt.Sprintf( | 141 | var schema *configschema.Block |
131 | "resource %q %q {", | 142 | provider := m.Resources[key].ProviderConfig.ProviderConfig.StringCompact() |
132 | addr.Type, | 143 | if _, exists := schemas.Providers[provider]; !exists { |
133 | addr.Name, | 144 | // This should never happen in normal use because we should've |
134 | )) | 145 | // loaded all of the schemas and checked things prior to this |
135 | case addrs.DataResourceMode: | 146 | // point. We can't return errors here, but since this is UI code |
136 | schema, _ = schemas.ResourceTypeConfig( | 147 | // we will try to do _something_ reasonable. |
137 | provider, | 148 | p.buf.WriteString(fmt.Sprintf("# missing schema for provider %q\n\n", provider)) |
138 | addr.Mode, | ||
139 | addr.Type, | ||
140 | ) | ||
141 | if schema == nil { | ||
142 | p.buf.WriteString(fmt.Sprintf( | ||
143 | "# missing schema for provider %q data source %s\n\n", provider, addr.Type)) | ||
144 | continue | 149 | continue |
145 | } | 150 | } |
146 | 151 | ||
147 | p.buf.WriteString(fmt.Sprintf( | 152 | switch addr.Mode { |
148 | "data %q %q {", | 153 | case addrs.ManagedResourceMode: |
149 | addr.Type, | 154 | schema, _ = schemas.ResourceTypeConfig( |
150 | addr.Name, | 155 | provider, |
151 | )) | 156 | addr.Mode, |
152 | default: | 157 | addr.Type, |
153 | // should never happen, since the above is exhaustive | 158 | ) |
154 | p.buf.WriteString(addr.String()) | 159 | if schema == nil { |
155 | } | 160 | p.buf.WriteString(fmt.Sprintf( |
161 | "# missing schema for provider %q resource type %s\n\n", provider, addr.Type)) | ||
162 | continue | ||
163 | } | ||
156 | 164 | ||
157 | val, err := v.Current.Decode(schema.ImpliedType()) | 165 | p.buf.WriteString(fmt.Sprintf( |
158 | if err != nil { | 166 | "resource %q %q {", |
159 | fmt.Println(err.Error()) | 167 | addr.Type, |
160 | break | 168 | addr.Name, |
161 | } | 169 | )) |
170 | case addrs.DataResourceMode: | ||
171 | schema, _ = schemas.ResourceTypeConfig( | ||
172 | provider, | ||
173 | addr.Mode, | ||
174 | addr.Type, | ||
175 | ) | ||
176 | if schema == nil { | ||
177 | p.buf.WriteString(fmt.Sprintf( | ||
178 | "# missing schema for provider %q data source %s\n\n", provider, addr.Type)) | ||
179 | continue | ||
180 | } | ||
162 | 181 | ||
163 | path := make(cty.Path, 0, 3) | 182 | p.buf.WriteString(fmt.Sprintf( |
164 | bodyWritten := p.writeBlockBodyDiff(schema, val.Value, val.Value, 2, path) | 183 | "data %q %q {", |
165 | if bodyWritten { | 184 | addr.Type, |
166 | p.buf.WriteString("\n") | 185 | addr.Name, |
167 | } | 186 | )) |
187 | default: | ||
188 | // should never happen, since the above is exhaustive | ||
189 | p.buf.WriteString(addr.String()) | ||
190 | } | ||
168 | 191 | ||
169 | p.buf.WriteString("}\n\n") | 192 | val, err := instance.Decode(schema.ImpliedType()) |
193 | if err != nil { | ||
194 | fmt.Println(err.Error()) | ||
195 | break | ||
196 | } | ||
197 | |||
198 | path := make(cty.Path, 0, 3) | ||
199 | bodyWritten := p.writeBlockBodyDiff(schema, val.Value, val.Value, 2, path) | ||
200 | if bodyWritten { | ||
201 | p.buf.WriteString("\n") | ||
202 | } | ||
203 | |||
204 | p.buf.WriteString("}\n\n") | ||
205 | } | ||
170 | } | 206 | } |
171 | } | 207 | } |
172 | p.buf.WriteString("[reset]\n") | 208 | p.buf.WriteString("\n") |
173 | } | 209 | } |
174 | 210 | ||
175 | func formatNestedList(indent string, outputList []interface{}) string { | 211 | func formatNestedList(indent string, outputList []interface{}) string { |
@@ -231,7 +267,7 @@ func formatListOutput(indent, outputName string, outputList []interface{}) strin | |||
231 | 267 | ||
232 | func formatNestedMap(indent string, outputMap map[string]interface{}) string { | 268 | func formatNestedMap(indent string, outputMap map[string]interface{}) string { |
233 | ks := make([]string, 0, len(outputMap)) | 269 | ks := make([]string, 0, len(outputMap)) |
234 | for k, _ := range outputMap { | 270 | for k := range outputMap { |
235 | ks = append(ks, k) | 271 | ks = append(ks, k) |
236 | } | 272 | } |
237 | sort.Strings(ks) | 273 | sort.Strings(ks) |
@@ -256,7 +292,7 @@ func formatNestedMap(indent string, outputMap map[string]interface{}) string { | |||
256 | 292 | ||
257 | func formatMapOutput(indent, outputName string, outputMap map[string]interface{}) string { | 293 | func formatMapOutput(indent, outputName string, outputMap map[string]interface{}) string { |
258 | ks := make([]string, 0, len(outputMap)) | 294 | ks := make([]string, 0, len(outputMap)) |
259 | for k, _ := range outputMap { | 295 | for k := range outputMap { |
260 | ks = append(ks, k) | 296 | ks = append(ks, k) |
261 | } | 297 | } |
262 | sort.Strings(ks) | 298 | sort.Strings(ks) |