config: add LiteralInterpolation

This commit is contained in:
Mitchell Hashimoto 2014-07-22 14:21:47 -07:00
parent 51b2a8e7f2
commit db160a0249
2 changed files with 48 additions and 0 deletions

View File

@ -43,6 +43,14 @@ type FunctionInterpolation struct {
key string
}
// LiteralInterpolation implements Interpolation for literals. Ex:
// ${"foo"} will equal "foo".
type LiteralInterpolation struct {
Literal string
key string
}
// VariableInterpolation implements Interpolation for simple variable
// interpolation. Ex: "${var.foo}" or "${aws_instance.foo.bar}"
type VariableInterpolation struct {
@ -174,6 +182,19 @@ func (i *FunctionInterpolation) Variables() map[string]InterpolatedVariable {
return result
}
func (i *LiteralInterpolation) FullString() string {
return i.key
}
func (i *LiteralInterpolation) Interpolate(
map[string]string) (string, error) {
return i.Literal, nil
}
func (i *LiteralInterpolation) Variables() map[string]InterpolatedVariable {
return nil
}
func (i *VariableInterpolation) FullString() string {
return i.key
}

View File

@ -199,6 +199,33 @@ func TestFunctionInterpolation(t *testing.T) {
}
}
func TestLiteralInterpolation_impl(t *testing.T) {
var _ Interpolation = new(LiteralInterpolation)
}
func TestLiteralInterpolation(t *testing.T) {
i := &LiteralInterpolation{
Literal: "bar",
key: "foo",
}
if i.FullString() != "foo" {
t.Fatalf("err: %#v", i)
}
if i.Variables() != nil {
t.Fatalf("bad: %#v", i.Variables())
}
actual, err := i.Interpolate(nil)
if err != nil {
t.Fatalf("err: %s", err)
}
if actual != "bar" {
t.Fatalf("bad: %#v", actual)
}
}
func TestResourceVariable_impl(t *testing.T) {
var _ InterpolatedVariable = new(ResourceVariable)
}