aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/moduledeps/provider.go
blob: 89ceefb2cf016831f406bce89f56656d2e89475b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package moduledeps

import (
	"strings"
)

// ProviderInstance describes a particular provider instance by its full name,
// like "null" or "aws.foo".
type ProviderInstance string

// Type returns the provider type of this instance. For example, for an instance
// named "aws.foo" the type is "aws".
func (p ProviderInstance) Type() string {
	t := string(p)
	if dotPos := strings.Index(t, "."); dotPos != -1 {
		t = t[:dotPos]
	}
	return t
}

// Alias returns the alias of this provider, if any. An instance named "aws.foo"
// has the alias "foo", while an instance named just "docker" has no alias,
// so the empty string would be returned.
func (p ProviderInstance) Alias() string {
	t := string(p)
	if dotPos := strings.Index(t, "."); dotPos != -1 {
		return t[dotPos+1:]
	}
	return ""
}