aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/helper/schema
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/schema')
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/schema/provider.go17
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/schema/provisioner.go52
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/schema/resource.go23
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/schema/schema.go14
4 files changed, 78 insertions, 28 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/provider.go b/vendor/github.com/hashicorp/terraform/helper/schema/provider.go
index d52d2f5..fb28b41 100644
--- a/vendor/github.com/hashicorp/terraform/helper/schema/provider.go
+++ b/vendor/github.com/hashicorp/terraform/helper/schema/provider.go
@@ -8,6 +8,7 @@ import (
8 "sync" 8 "sync"
9 9
10 "github.com/hashicorp/go-multierror" 10 "github.com/hashicorp/go-multierror"
11 "github.com/hashicorp/terraform/config"
11 "github.com/hashicorp/terraform/terraform" 12 "github.com/hashicorp/terraform/terraform"
12) 13)
13 14
@@ -89,6 +90,13 @@ func (p *Provider) InternalValidate() error {
89 validationErrors = multierror.Append(validationErrors, err) 90 validationErrors = multierror.Append(validationErrors, err)
90 } 91 }
91 92
93 // Provider-specific checks
94 for k, _ := range sm {
95 if isReservedProviderFieldName(k) {
96 return fmt.Errorf("%s is a reserved field name for a provider", k)
97 }
98 }
99
92 for k, r := range p.ResourcesMap { 100 for k, r := range p.ResourcesMap {
93 if err := r.InternalValidate(nil, true); err != nil { 101 if err := r.InternalValidate(nil, true); err != nil {
94 validationErrors = multierror.Append(validationErrors, fmt.Errorf("resource %s: %s", k, err)) 102 validationErrors = multierror.Append(validationErrors, fmt.Errorf("resource %s: %s", k, err))
@@ -104,6 +112,15 @@ func (p *Provider) InternalValidate() error {
104 return validationErrors 112 return validationErrors
105} 113}
106 114
115func isReservedProviderFieldName(name string) bool {
116 for _, reservedName := range config.ReservedProviderFields {
117 if name == reservedName {
118 return true
119 }
120 }
121 return false
122}
123
107// Meta returns the metadata associated with this provider that was 124// Meta returns the metadata associated with this provider that was
108// returned by the Configure call. It will be nil until Configure is called. 125// returned by the Configure call. It will be nil until Configure is called.
109func (p *Provider) Meta() interface{} { 126func (p *Provider) Meta() interface{} {
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/provisioner.go b/vendor/github.com/hashicorp/terraform/helper/schema/provisioner.go
index 856c675..476192e 100644
--- a/vendor/github.com/hashicorp/terraform/helper/schema/provisioner.go
+++ b/vendor/github.com/hashicorp/terraform/helper/schema/provisioner.go
@@ -43,7 +43,7 @@ type Provisioner struct {
43 43
44 // ValidateFunc is a function for extended validation. This is optional 44 // ValidateFunc is a function for extended validation. This is optional
45 // and should be used when individual field validation is not enough. 45 // and should be used when individual field validation is not enough.
46 ValidateFunc func(*ResourceData) ([]string, []error) 46 ValidateFunc func(*terraform.ResourceConfig) ([]string, []error)
47 47
48 stopCtx context.Context 48 stopCtx context.Context
49 stopCtxCancel context.CancelFunc 49 stopCtxCancel context.CancelFunc
@@ -121,32 +121,6 @@ func (p *Provisioner) Stop() error {
121 return nil 121 return nil
122} 122}
123 123
124func (p *Provisioner) Validate(config *terraform.ResourceConfig) ([]string, []error) {
125 if err := p.InternalValidate(); err != nil {
126 return nil, []error{fmt.Errorf(
127 "Internal validation of the provisioner failed! This is always a bug\n"+
128 "with the provisioner itself, and not a user issue. Please report\n"+
129 "this bug:\n\n%s", err)}
130 }
131 w := []string{}
132 e := []error{}
133 if p.Schema != nil {
134 w2, e2 := schemaMap(p.Schema).Validate(config)
135 w = append(w, w2...)
136 e = append(e, e2...)
137 }
138 if p.ValidateFunc != nil {
139 data := &ResourceData{
140 schema: p.Schema,
141 config: config,
142 }
143 w2, e2 := p.ValidateFunc(data)
144 w = append(w, w2...)
145 e = append(e, e2...)
146 }
147 return w, e
148}
149
150// Apply implementation of terraform.ResourceProvisioner interface. 124// Apply implementation of terraform.ResourceProvisioner interface.
151func (p *Provisioner) Apply( 125func (p *Provisioner) Apply(
152 o terraform.UIOutput, 126 o terraform.UIOutput,
@@ -204,3 +178,27 @@ func (p *Provisioner) Apply(
204 ctx = context.WithValue(ctx, ProvRawStateKey, s) 178 ctx = context.WithValue(ctx, ProvRawStateKey, s)
205 return p.ApplyFunc(ctx) 179 return p.ApplyFunc(ctx)
206} 180}
181
182// Validate implements the terraform.ResourceProvisioner interface.
183func (p *Provisioner) Validate(c *terraform.ResourceConfig) (ws []string, es []error) {
184 if err := p.InternalValidate(); err != nil {
185 return nil, []error{fmt.Errorf(
186 "Internal validation of the provisioner failed! This is always a bug\n"+
187 "with the provisioner itself, and not a user issue. Please report\n"+
188 "this bug:\n\n%s", err)}
189 }
190
191 if p.Schema != nil {
192 w, e := schemaMap(p.Schema).Validate(c)
193 ws = append(ws, w...)
194 es = append(es, e...)
195 }
196
197 if p.ValidateFunc != nil {
198 w, e := p.ValidateFunc(c)
199 ws = append(ws, w...)
200 es = append(es, e...)
201 }
202
203 return ws, es
204}
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/resource.go b/vendor/github.com/hashicorp/terraform/helper/schema/resource.go
index c810558..ddba109 100644
--- a/vendor/github.com/hashicorp/terraform/helper/schema/resource.go
+++ b/vendor/github.com/hashicorp/terraform/helper/schema/resource.go
@@ -6,6 +6,7 @@ import (
6 "log" 6 "log"
7 "strconv" 7 "strconv"
8 8
9 "github.com/hashicorp/terraform/config"
9 "github.com/hashicorp/terraform/terraform" 10 "github.com/hashicorp/terraform/terraform"
10) 11)
11 12
@@ -142,6 +143,12 @@ func (r *Resource) Apply(
142 if err := rt.DiffDecode(d); err != nil { 143 if err := rt.DiffDecode(d); err != nil {
143 log.Printf("[ERR] Error decoding ResourceTimeout: %s", err) 144 log.Printf("[ERR] Error decoding ResourceTimeout: %s", err)
144 } 145 }
146 } else if s != nil {
147 if _, ok := s.Meta[TimeoutKey]; ok {
148 if err := rt.StateDecode(s); err != nil {
149 log.Printf("[ERR] Error decoding ResourceTimeout: %s", err)
150 }
151 }
145 } else { 152 } else {
146 log.Printf("[DEBUG] No meta timeoutkey found in Apply()") 153 log.Printf("[DEBUG] No meta timeoutkey found in Apply()")
147 } 154 }
@@ -388,9 +395,25 @@ func (r *Resource) InternalValidate(topSchemaMap schemaMap, writable bool) error
388 } 395 }
389 } 396 }
390 397
398 // Resource-specific checks
399 for k, _ := range tsm {
400 if isReservedResourceFieldName(k) {
401 return fmt.Errorf("%s is a reserved field name for a resource", k)
402 }
403 }
404
391 return schemaMap(r.Schema).InternalValidate(tsm) 405 return schemaMap(r.Schema).InternalValidate(tsm)
392} 406}
393 407
408func isReservedResourceFieldName(name string) bool {
409 for _, reservedName := range config.ReservedResourceFields {
410 if name == reservedName {
411 return true
412 }
413 }
414 return false
415}
416
394// Data returns a ResourceData struct for this Resource. Each return value 417// Data returns a ResourceData struct for this Resource. Each return value
395// is a separate copy and can be safely modified differently. 418// is a separate copy and can be safely modified differently.
396// 419//
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/schema.go b/vendor/github.com/hashicorp/terraform/helper/schema/schema.go
index 632672a..acb5618 100644
--- a/vendor/github.com/hashicorp/terraform/helper/schema/schema.go
+++ b/vendor/github.com/hashicorp/terraform/helper/schema/schema.go
@@ -15,6 +15,7 @@ import (
15 "fmt" 15 "fmt"
16 "os" 16 "os"
17 "reflect" 17 "reflect"
18 "regexp"
18 "sort" 19 "sort"
19 "strconv" 20 "strconv"
20 "strings" 21 "strings"
@@ -661,7 +662,13 @@ func (m schemaMap) InternalValidate(topSchemaMap schemaMap) error {
661 if v.ValidateFunc != nil { 662 if v.ValidateFunc != nil {
662 switch v.Type { 663 switch v.Type {
663 case TypeList, TypeSet: 664 case TypeList, TypeSet:
664 return fmt.Errorf("ValidateFunc is not yet supported on lists or sets.") 665 return fmt.Errorf("%s: ValidateFunc is not yet supported on lists or sets.", k)
666 }
667 }
668
669 if v.Deprecated == "" && v.Removed == "" {
670 if !isValidFieldName(k) {
671 return fmt.Errorf("%s: Field name may only contain lowercase alphanumeric characters & underscores.", k)
665 } 672 }
666 } 673 }
667 } 674 }
@@ -669,6 +676,11 @@ func (m schemaMap) InternalValidate(topSchemaMap schemaMap) error {
669 return nil 676 return nil
670} 677}
671 678
679func isValidFieldName(name string) bool {
680 re := regexp.MustCompile("^[a-z0-9_]+$")
681 return re.MatchString(name)
682}
683
672func (m schemaMap) diff( 684func (m schemaMap) diff(
673 k string, 685 k string,
674 schema *Schema, 686 schema *Schema,