From d6c6f8852ceb0ebd830cdd291249b64e10b9c08b Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 16 Mar 2018 10:43:35 -0700 Subject: [PATCH] configschema: include description in schema We will need access to this information in order to render interactive input prompts, and it will also be useful in returning schema information to external tools such as text editors that have autocomplete-like functionality. --- config/configschema/schema.go | 6 ++++++ helper/schema/core_schema.go | 11 ++++++----- helper/schema/core_schema_test.go | 10 ++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/config/configschema/schema.go b/config/configschema/schema.go index 9a8ee550aa..0c23741fea 100644 --- a/config/configschema/schema.go +++ b/config/configschema/schema.go @@ -28,6 +28,12 @@ type Attribute struct { // Type is a type specification that the attribute's value must conform to. Type cty.Type + // Description is an English-language description of the purpose and + // usage of the attribute. A description should be concise and use only + // one or two sentences, leaving full definition to longer-form + // documentation defined elsewhere. + Description string + // Required, if set to true, specifies that an omitted or null value is // not permitted. Required bool diff --git a/helper/schema/core_schema.go b/helper/schema/core_schema.go index bf952f6631..95398578be 100644 --- a/helper/schema/core_schema.go +++ b/helper/schema/core_schema.go @@ -59,11 +59,12 @@ func (m schemaMap) CoreConfigSchema() *configschema.Block { // whose elem is a whole resource. func (s *Schema) coreConfigSchemaAttribute() *configschema.Attribute { return &configschema.Attribute{ - Type: s.coreConfigSchemaType(), - Optional: s.Optional, - Required: s.Required, - Computed: s.Computed, - Sensitive: s.Sensitive, + Type: s.coreConfigSchemaType(), + Optional: s.Optional, + Required: s.Required, + Computed: s.Computed, + Sensitive: s.Sensitive, + Description: s.Description, } } diff --git a/helper/schema/core_schema_test.go b/helper/schema/core_schema_test.go index 08f8dbd9a5..8fefc47fc2 100644 --- a/helper/schema/core_schema_test.go +++ b/helper/schema/core_schema_test.go @@ -23,8 +23,9 @@ func TestSchemaMapCoreConfigSchema(t *testing.T) { "primitives": { map[string]*Schema{ "int": { - Type: TypeInt, - Required: true, + Type: TypeInt, + Required: true, + Description: "foo bar baz", }, "float": { Type: TypeFloat, @@ -43,8 +44,9 @@ func TestSchemaMapCoreConfigSchema(t *testing.T) { &configschema.Block{ Attributes: map[string]*configschema.Attribute{ "int": { - Type: cty.Number, - Required: true, + Type: cty.Number, + Required: true, + Description: "foo bar baz", }, "float": { Type: cty.Number,