Add testProviderConfig to import tests
Provider import tests previously didn't have to supply a config, but terraform now requires the provider to be declared for discovery. testProviderConfig returns a stub config with provider blocks based on the TestCase Providers. This allows basic import tests in providers to remain unchanged.
This commit is contained in:
parent
8e2ee53ed3
commit
60ea42cd1c
|
@ -406,6 +406,10 @@ func Test(t TestT, c TestCase) {
|
||||||
step)
|
step)
|
||||||
} else {
|
} else {
|
||||||
if step.ImportState {
|
if step.ImportState {
|
||||||
|
if step.Config == "" {
|
||||||
|
step.Config = testProviderConfig(c)
|
||||||
|
}
|
||||||
|
|
||||||
// Can optionally set step.Config in addition to
|
// Can optionally set step.Config in addition to
|
||||||
// step.ImportState, to provide config for the import.
|
// step.ImportState, to provide config for the import.
|
||||||
state, err = testStepImportState(opts, state, step)
|
state, err = testStepImportState(opts, state, step)
|
||||||
|
@ -499,6 +503,18 @@ func Test(t TestT, c TestCase) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// testProviderConfig takes the list of Providers in a TestCase and returns a
|
||||||
|
// config with only empty provider blocks. This is useful for Import, where no
|
||||||
|
// config is provided, but the providers must be defined.
|
||||||
|
func testProviderConfig(c TestCase) string {
|
||||||
|
var lines []string
|
||||||
|
for p := range c.Providers {
|
||||||
|
lines = append(lines, fmt.Sprintf("provider %q {}\n", p))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(lines, "")
|
||||||
|
}
|
||||||
|
|
||||||
// testProviderResolver is a helper to build a ResourceProviderResolver
|
// testProviderResolver is a helper to build a ResourceProviderResolver
|
||||||
// with pre instantiated ResourceProviders, so that we can reset them for the
|
// with pre instantiated ResourceProviders, so that we can reset them for the
|
||||||
// test, while only calling the factory function once.
|
// test, while only calling the factory function once.
|
||||||
|
|
Loading…
Reference in New Issue