config: add LiteralInterpolation
This commit is contained in:
parent
51b2a8e7f2
commit
db160a0249
|
@ -43,6 +43,14 @@ type FunctionInterpolation struct {
|
||||||
key string
|
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
|
// VariableInterpolation implements Interpolation for simple variable
|
||||||
// interpolation. Ex: "${var.foo}" or "${aws_instance.foo.bar}"
|
// interpolation. Ex: "${var.foo}" or "${aws_instance.foo.bar}"
|
||||||
type VariableInterpolation struct {
|
type VariableInterpolation struct {
|
||||||
|
@ -174,6 +182,19 @@ func (i *FunctionInterpolation) Variables() map[string]InterpolatedVariable {
|
||||||
return result
|
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 {
|
func (i *VariableInterpolation) FullString() string {
|
||||||
return i.key
|
return i.key
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
func TestResourceVariable_impl(t *testing.T) {
|
||||||
var _ InterpolatedVariable = new(ResourceVariable)
|
var _ InterpolatedVariable = new(ResourceVariable)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue