aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/config/config.go
diff options
context:
space:
mode:
authorRadek Simko <radek.simko@gmail.com>2017-08-10 14:38:14 +0200
committerRadek Simko <radek.simko@gmail.com>2017-08-10 14:38:14 +0200
commitc680a8e1622ed0f18751d9d167c836ee24f5e897 (patch)
tree864f925049d422033dd25a73bafce32b361c8827 /vendor/github.com/hashicorp/terraform/config/config.go
parent38f8880ac81bfabc6d7f82e4dc89661f20fc559e (diff)
downloadterraform-provider-statuscake-c680a8e1622ed0f18751d9d167c836ee24f5e897.tar.gz
terraform-provider-statuscake-c680a8e1622ed0f18751d9d167c836ee24f5e897.tar.zst
terraform-provider-statuscake-c680a8e1622ed0f18751d9d167c836ee24f5e897.zip
vendor: github.com/hashicorp/terraform/...@v0.10.0
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config/config.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/config/config.go42
1 files changed, 41 insertions, 1 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/config.go b/vendor/github.com/hashicorp/terraform/config/config.go
index a157824..3f756dc 100644
--- a/vendor/github.com/hashicorp/terraform/config/config.go
+++ b/vendor/github.com/hashicorp/terraform/config/config.go
@@ -12,6 +12,7 @@ import (
12 "github.com/hashicorp/hil" 12 "github.com/hashicorp/hil"
13 "github.com/hashicorp/hil/ast" 13 "github.com/hashicorp/hil/ast"
14 "github.com/hashicorp/terraform/helper/hilmapstructure" 14 "github.com/hashicorp/terraform/helper/hilmapstructure"
15 "github.com/hashicorp/terraform/plugin/discovery"
15 "github.com/mitchellh/reflectwalk" 16 "github.com/mitchellh/reflectwalk"
16) 17)
17 18
@@ -64,6 +65,7 @@ type Module struct {
64type ProviderConfig struct { 65type ProviderConfig struct {
65 Name string 66 Name string
66 Alias string 67 Alias string
68 Version string
67 RawConfig *RawConfig 69 RawConfig *RawConfig
68} 70}
69 71
@@ -238,6 +240,33 @@ func (r *Resource) Id() string {
238 } 240 }
239} 241}
240 242
243// ProviderFullName returns the full name of the provider for this resource,
244// which may either be specified explicitly using the "provider" meta-argument
245// or implied by the prefix on the resource type name.
246func (r *Resource) ProviderFullName() string {
247 return ResourceProviderFullName(r.Type, r.Provider)
248}
249
250// ResourceProviderFullName returns the full (dependable) name of the
251// provider for a hypothetical resource with the given resource type and
252// explicit provider string. If the explicit provider string is empty then
253// the provider name is inferred from the resource type name.
254func ResourceProviderFullName(resourceType, explicitProvider string) string {
255 if explicitProvider != "" {
256 return explicitProvider
257 }
258
259 idx := strings.IndexRune(resourceType, '_')
260 if idx == -1 {
261 // If no underscores, the resource name is assumed to be
262 // also the provider name, e.g. if the provider exposes
263 // only a single resource of each type.
264 return resourceType
265 }
266
267 return resourceType[:idx]
268}
269
241// Validate does some basic semantic checking of the configuration. 270// Validate does some basic semantic checking of the configuration.
242func (c *Config) Validate() error { 271func (c *Config) Validate() error {
243 if c == nil { 272 if c == nil {
@@ -349,7 +378,8 @@ func (c *Config) Validate() error {
349 } 378 }
350 } 379 }
351 380
352 // Check that providers aren't declared multiple times. 381 // Check that providers aren't declared multiple times and that their
382 // version constraints, where present, are syntactically valid.
353 providerSet := make(map[string]struct{}) 383 providerSet := make(map[string]struct{})
354 for _, p := range c.ProviderConfigs { 384 for _, p := range c.ProviderConfigs {
355 name := p.FullName() 385 name := p.FullName()
@@ -360,6 +390,16 @@ func (c *Config) Validate() error {
360 continue 390 continue
361 } 391 }
362 392
393 if p.Version != "" {
394 _, err := discovery.ConstraintStr(p.Version).Parse()
395 if err != nil {
396 errs = append(errs, fmt.Errorf(
397 "provider.%s: invalid version constraint %q: %s",
398 name, p.Version, err,
399 ))
400 }
401 }
402
363 providerSet[name] = struct{}{} 403 providerSet[name] = struct{}{}
364 } 404 }
365 405