command/jsonconfig: add missing fields from configuration output (#20387)

Display depends_on for resources and outputs, and description for
outputs.
This commit is contained in:
Kristin Laemmert 2019-02-19 16:31:10 -08:00 committed by GitHub
parent 1bef862e3a
commit b14472f22c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 11 deletions

View File

@ -32,7 +32,7 @@ type providerConfig struct {
} }
type module struct { type module struct {
Outputs map[string]configOutput `json:"outputs,omitempty"` Outputs map[string]output `json:"outputs,omitempty"`
// Resources are sorted in a user-friendly order that is undefined at this // Resources are sorted in a user-friendly order that is undefined at this
// time, but consistent. // time, but consistent.
Resources []resource `json:"resources,omitempty"` Resources []resource `json:"resources,omitempty"`
@ -90,11 +90,15 @@ type resource struct {
// These are omitted if the corresponding argument isn't set. // These are omitted if the corresponding argument isn't set.
CountExpression *expression `json:"count_expression,omitempty"` CountExpression *expression `json:"count_expression,omitempty"`
ForEachExpression *expression `json:"for_each_expression,omitempty"` ForEachExpression *expression `json:"for_each_expression,omitempty"`
DependsOn []string `json:"depends_on,omitempty"`
} }
type configOutput struct { type output struct {
Sensitive bool `json:"sensitive,omitempty"` Sensitive bool `json:"sensitive,omitempty"`
Expression expression `json:"expression,omitempty"` Expression expression `json:"expression,omitempty"`
DependsOn []string `json:"depends_on,omitempty"`
Description string `json:"description,omitempty"`
} }
type provisioner struct { type provisioner struct {
@ -161,12 +165,30 @@ func marshalModule(c *configs.Config, schemas *terraform.Schemas) (module, error
rs = append(managedResources, dataResources...) rs = append(managedResources, dataResources...)
module.Resources = rs module.Resources = rs
outputs := make(map[string]configOutput) outputs := make(map[string]output)
for _, v := range c.Module.Outputs { for _, v := range c.Module.Outputs {
outputs[v.Name] = configOutput{ o := output{
Sensitive: v.Sensitive, Sensitive: v.Sensitive,
Expression: marshalExpression(v.Expr), Expression: marshalExpression(v.Expr),
} }
if v.Description != "" {
o.Description = v.Description
}
if len(v.DependsOn) > 0 {
dependencies := make([]string, len(v.DependsOn))
for i, d := range v.DependsOn {
ref, diags := addrs.ParseRef(d)
// we should not get an error here, because `terraform validate`
// would have complained well before this point, but if we do we'll
// silenty skip it.
if !diags.HasErrors() {
dependencies[i] = ref.Subject.String()
}
}
o.DependsOn = dependencies
}
outputs[v.Name] = o
} }
module.Outputs = outputs module.Outputs = outputs
module.ModuleCalls = marshalModuleCalls(c, schemas) module.ModuleCalls = marshalModuleCalls(c, schemas)
@ -289,6 +311,20 @@ func marshalResources(resources map[string]*configs.Resource, schemas *terraform
r.Provisioners = provisioners r.Provisioners = provisioners
} }
if len(v.DependsOn) > 0 {
dependencies := make([]string, len(v.DependsOn))
for i, d := range v.DependsOn {
ref, diags := addrs.ParseRef(d)
// we should not get an error here, because `terraform validate`
// would have complained well before this point, but if we do we'll
// silenty skip it.
if !diags.HasErrors() {
dependencies[i] = ref.Subject.String()
}
}
r.DependsOn = dependencies
}
rs = append(rs, r) rs = append(rs, r)
} }
sort.Slice(rs, func(i, j int) bool { sort.Slice(rs, func(i, j int) bool {

View File

@ -4,5 +4,6 @@ module "test" {
} }
output "test" { output "test" {
value = module.test.test value = module.test.test
depends_on = [module.test]
} }

View File

@ -61,7 +61,6 @@
"type": "test_instance", "type": "test_instance",
"name": "test", "name": "test",
"index": 0, "index": 0,
"deposed": true,
"change": { "change": {
"actions": [ "actions": [
"create" "create"
@ -83,7 +82,6 @@
"type": "test_instance", "type": "test_instance",
"name": "test", "name": "test",
"index": 1, "index": 1,
"deposed": true,
"change": { "change": {
"actions": [ "actions": [
"create" "create"
@ -105,7 +103,6 @@
"type": "test_instance", "type": "test_instance",
"name": "test", "name": "test",
"index": 2, "index": 2,
"deposed": true,
"change": { "change": {
"actions": [ "actions": [
"create" "create"
@ -139,7 +136,10 @@
"references": [ "references": [
"module.test.test" "module.test.test"
] ]
} },
"depends_on": [
"module.test"
]
} }
}, },
"module_calls": { "module_calls": {