mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
config: remove a lot of unused stuff
This commit is contained in:
parent
1ccad4d729
commit
49fe0d5c7f
@ -8,16 +8,6 @@ import (
|
||||
"github.com/hashicorp/terraform/config/lang/ast"
|
||||
)
|
||||
|
||||
// Interpolation is something that can be contained in a "${}" in a
|
||||
// configuration value.
|
||||
//
|
||||
// Interpolations might be simple variable references, or it might be
|
||||
// function calls, or even nested function calls.
|
||||
type Interpolation interface {
|
||||
Interpolate(map[string]string) (string, error)
|
||||
Variables() map[string]InterpolatedVariable
|
||||
}
|
||||
|
||||
// An InterpolatedVariable is a variable reference within an interpolation.
|
||||
//
|
||||
// Implementations of this interface represents various sources where
|
||||
@ -26,18 +16,6 @@ type InterpolatedVariable interface {
|
||||
FullKey() string
|
||||
}
|
||||
|
||||
// LiteralInterpolation implements Interpolation for literals. Ex:
|
||||
// ${"foo"} will equal "foo".
|
||||
type LiteralInterpolation struct {
|
||||
Literal string
|
||||
}
|
||||
|
||||
// VariableInterpolation implements Interpolation for simple variable
|
||||
// interpolation. Ex: "${var.foo}" or "${aws_instance.foo.bar}"
|
||||
type VariableInterpolation struct {
|
||||
Variable InterpolatedVariable
|
||||
}
|
||||
|
||||
// CountVariable is a variable for referencing information about
|
||||
// the count.
|
||||
type CountVariable struct {
|
||||
@ -114,35 +92,6 @@ func NewInterpolatedVariable(v string) (InterpolatedVariable, error) {
|
||||
}
|
||||
}
|
||||
|
||||
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) Interpolate(
|
||||
vs map[string]string) (string, error) {
|
||||
v, ok := vs[i.Variable.FullKey()]
|
||||
if !ok {
|
||||
return "", fmt.Errorf(
|
||||
"%s: value for variable not found",
|
||||
i.Variable.FullKey())
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
func (i *VariableInterpolation) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *i)
|
||||
}
|
||||
|
||||
func (i *VariableInterpolation) Variables() map[string]InterpolatedVariable {
|
||||
return map[string]InterpolatedVariable{i.Variable.FullKey(): i.Variable}
|
||||
}
|
||||
|
||||
func NewCountVariable(key string) (*CountVariable, error) {
|
||||
var fieldType CountValueType
|
||||
parts := strings.SplitN(key, ".", 2)
|
||||
|
@ -122,29 +122,6 @@ func TestNewUserVariable_map(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLiteralInterpolation_impl(t *testing.T) {
|
||||
var _ Interpolation = new(LiteralInterpolation)
|
||||
}
|
||||
|
||||
func TestLiteralInterpolation(t *testing.T) {
|
||||
i := &LiteralInterpolation{
|
||||
Literal: "bar",
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
@ -201,50 +178,6 @@ func TestUserVariable_impl(t *testing.T) {
|
||||
var _ InterpolatedVariable = new(UserVariable)
|
||||
}
|
||||
|
||||
func TestVariableInterpolation_impl(t *testing.T) {
|
||||
var _ Interpolation = new(VariableInterpolation)
|
||||
}
|
||||
|
||||
func TestVariableInterpolation(t *testing.T) {
|
||||
uv, err := NewUserVariable("var.foo")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
i := &VariableInterpolation{Variable: uv}
|
||||
|
||||
expected := map[string]InterpolatedVariable{"var.foo": uv}
|
||||
if !reflect.DeepEqual(i.Variables(), expected) {
|
||||
t.Fatalf("bad: %#v", i.Variables())
|
||||
}
|
||||
|
||||
actual, err := i.Interpolate(map[string]string{
|
||||
"var.foo": "bar",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if actual != "bar" {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVariableInterpolation_missing(t *testing.T) {
|
||||
uv, err := NewUserVariable("var.foo")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
i := &VariableInterpolation{Variable: uv}
|
||||
_, err = i.Interpolate(map[string]string{
|
||||
"var.bar": "bar",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("should error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetectVariables(t *testing.T) {
|
||||
cases := []struct {
|
||||
Input string
|
||||
|
Loading…
Reference in New Issue
Block a user