Create a builtin provider during import. (#5730)
`pulumi import` may otherwise fail if there are providers in the statefile.
This commit is contained in:
parent
a6f8b9b205
commit
0ec12d01f9
|
@ -3,6 +3,9 @@ CHANGELOG
|
|||
|
||||
## HEAD (Unreleased)
|
||||
|
||||
- Fix a bug that could prevent `pulumi import` from succeeding.
|
||||
[#5730](https://github.com/pulumi/pulumi/pull/5730)
|
||||
|
||||
- [Docs] Add support for the generation of Import documentation in the resource docs.
|
||||
This documentation will only be available if the resource is importable.
|
||||
[#5667](https://github.com/pulumi/pulumi/pull/5667)
|
||||
|
|
|
@ -3411,7 +3411,7 @@ func TestDetailedDiffReplace(t *testing.T) {
|
|||
assert.Nil(t, res)
|
||||
}
|
||||
|
||||
func TestImport(t *testing.T) {
|
||||
func TestImportOption(t *testing.T) {
|
||||
loaders := []*deploytest.ProviderLoader{
|
||||
deploytest.NewProviderLoader("pkgA", semver.MustParse("1.0.0"), func() (plugin.Provider, error) {
|
||||
return &deploytest.Provider{
|
||||
|
@ -5768,3 +5768,91 @@ func TestSingleComponentGetResourceDefaultProviderLifecycle(t *testing.T) {
|
|||
}
|
||||
p.Run(t, nil)
|
||||
}
|
||||
|
||||
const importSchema = `{
|
||||
"version": "0.0.1",
|
||||
"name": "pkgA",
|
||||
"resources": {
|
||||
"pkgA:m:typA": {
|
||||
"inputProperties": {
|
||||
"foo": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
func TestImport(t *testing.T) {
|
||||
loaders := []*deploytest.ProviderLoader{
|
||||
deploytest.NewProviderLoader("pkgA", semver.MustParse("1.0.0"), func() (plugin.Provider, error) {
|
||||
return &deploytest.Provider{
|
||||
GetSchemaF: func(version int) ([]byte, error) {
|
||||
return []byte(importSchema), nil
|
||||
},
|
||||
DiffF: func(urn resource.URN, id resource.ID,
|
||||
olds, news resource.PropertyMap, ignoreChanges []string) (plugin.DiffResult, error) {
|
||||
|
||||
if olds["foo"].DeepEquals(news["foo"]) {
|
||||
return plugin.DiffResult{Changes: plugin.DiffNone}, nil
|
||||
}
|
||||
|
||||
return plugin.DiffResult{
|
||||
Changes: plugin.DiffSome,
|
||||
DetailedDiff: map[string]plugin.PropertyDiff{
|
||||
"foo": {Kind: plugin.DiffUpdate},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
CreateF: func(urn resource.URN, news resource.PropertyMap, timeout float64,
|
||||
preview bool) (resource.ID, resource.PropertyMap, resource.Status, error) {
|
||||
|
||||
return "created-id", news, resource.StatusOK, nil
|
||||
},
|
||||
ReadF: func(urn resource.URN, id resource.ID,
|
||||
inputs, state resource.PropertyMap) (plugin.ReadResult, resource.Status, error) {
|
||||
|
||||
return plugin.ReadResult{
|
||||
Inputs: resource.PropertyMap{
|
||||
"foo": resource.NewStringProperty("bar"),
|
||||
},
|
||||
Outputs: resource.PropertyMap{
|
||||
"foo": resource.NewStringProperty("bar"),
|
||||
},
|
||||
}, resource.StatusOK, nil
|
||||
},
|
||||
}, nil
|
||||
}),
|
||||
}
|
||||
|
||||
program := deploytest.NewLanguageRuntime(func(_ plugin.RunInfo, monitor *deploytest.ResourceMonitor) error {
|
||||
_, _, _, err := monitor.RegisterResource("pkgA:m:typA", "resA", true, deploytest.ResourceOptions{})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
})
|
||||
host := deploytest.NewPluginHost(nil, nil, program, loaders...)
|
||||
|
||||
p := &TestPlan{
|
||||
Options: UpdateOptions{Host: host},
|
||||
}
|
||||
|
||||
// Run the initial update.
|
||||
project := p.GetProject()
|
||||
snap, res := TestOp(Update).Run(project, p.GetTarget(nil), p.Options, false, p.BackendClient, nil)
|
||||
assert.Nil(t, res)
|
||||
|
||||
// Run an import.
|
||||
snap, res = ImportOp([]deploy.Import{{
|
||||
Type: "pkgA:m:typA",
|
||||
Name: "resB",
|
||||
ID: "imported-id",
|
||||
}}).Run(project, p.GetTarget(snap), p.Options, false, p.BackendClient, nil)
|
||||
|
||||
assert.Nil(t, res)
|
||||
assert.Len(t, snap.Resources, 4)
|
||||
}
|
||||
|
|
|
@ -38,7 +38,14 @@ func (u *updateInfo) GetTarget() *deploy.Target {
|
|||
return &u.target
|
||||
}
|
||||
|
||||
func ImportOp(imports []deploy.Import) TestOp {
|
||||
return TestOp(func(info UpdateInfo, ctx *Context, opts UpdateOptions, dryRun bool) (ResourceChanges, result.Result) {
|
||||
return Import(info, ctx, opts, imports, dryRun)
|
||||
})
|
||||
}
|
||||
|
||||
type TestOp func(UpdateInfo, *Context, UpdateOptions, bool) (ResourceChanges, result.Result)
|
||||
|
||||
type ValidateFunc func(project workspace.Project, target deploy.Target, entries JournalEntries,
|
||||
events []Event, res result.Result) result.Result
|
||||
|
||||
|
|
|
@ -73,8 +73,10 @@ func NewImportPlan(ctx *plugin.Context, target *Target, projectName tokens.Packa
|
|||
return nil, err
|
||||
}
|
||||
|
||||
builtins := newBuiltinProvider(nil, nil)
|
||||
|
||||
// Create a new provider registry.
|
||||
reg, err := providers.NewRegistry(ctx.Host, oldResources, preview, nil)
|
||||
reg, err := providers.NewRegistry(ctx.Host, oldResources, preview, builtins)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue