mirror of https://github.com/hashicorp/terraform
parent
459ffe9d2a
commit
133a28e363
@ -0,0 +1,17 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// PrefixUIInput is an implementation of UIInput that prefixes the ID
|
||||
// with a string, allowing queries to be namespaced.
|
||||
type PrefixUIInput struct {
|
||||
IdPrefix string
|
||||
UIInput UIInput
|
||||
}
|
||||
|
||||
func (i *PrefixUIInput) Input(opts *InputOpts) (string, error) {
|
||||
opts.Id = fmt.Sprintf("%s.%s", i.IdPrefix, opts.Id)
|
||||
return i.UIInput.Input(opts)
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrefixUIInput_impl(t *testing.T) {
|
||||
var _ UIInput = new(PrefixUIInput)
|
||||
}
|
||||
|
||||
func testPrefixUIInput(t *testing.T) {
|
||||
input := new(MockUIInput)
|
||||
prefix := &PrefixUIInput{
|
||||
IdPrefix: "foo",
|
||||
UIInput: input,
|
||||
}
|
||||
|
||||
_, err := prefix.Input(&InputOpts{Id: "bar"})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if input.InputOpts.Id != "foo.bar" {
|
||||
t.Fatalf("bad: %#v", input.InputOpts)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue