diff --git a/config/interpolate.go b/config/interpolate.go index 59f14a83b..935ff2e8f 100644 --- a/config/interpolate.go +++ b/config/interpolate.go @@ -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 } diff --git a/config/interpolate_test.go b/config/interpolate_test.go index 3b01c6cd7..20d72f18a 100644 --- a/config/interpolate_test.go +++ b/config/interpolate_test.go @@ -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) }