Skip to content

Commit 968a567

Browse files
committed
helper/schema: ability to force set Meta
1 parent 43d0850 commit 968a567

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

helper/schema/provider.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ func (p *Provider) Meta() interface{} {
5858
return p.meta
5959
}
6060

61+
// SetMeta can be used to forcefully set the Meta object of the provider.
62+
// Note that if Configure is called the return value will override anything
63+
// set here.
64+
func (p *Provider) SetMeta(v interface{}) {
65+
p.meta = v
66+
}
67+
6168
// Validate validates the provider configuration against the schema.
6269
func (p *Provider) Validate(c *terraform.ResourceConfig) ([]string, []error) {
6370
return schemaMap(p.Schema).Validate(c)

helper/schema/provider_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,16 @@ func TestProviderValidateResource(t *testing.T) {
155155
}
156156
}
157157
}
158+
159+
func TestProviderMeta(t *testing.T) {
160+
p := new(Provider)
161+
if v := p.Meta(); v != nil {
162+
t.Fatalf("bad: %#v", v)
163+
}
164+
165+
expected := 42
166+
p.SetMeta(42)
167+
if v := p.Meta(); !reflect.DeepEqual(v, expected) {
168+
t.Fatalf("bad: %#v")
169+
}
170+
}

0 commit comments

Comments
 (0)