These changes take advantage of the newly-added support for returning inputs from Read to update a resource's inputs as part of a refresh. As a consequence, the Pulumi engine will now properly detect drift between the actual state of a resource and the desired state described by the program and generate appropriate update or replace steps. As part of these changes, a resource's old inputs are now passed to the provider when performing a refresh. The provider can take advantage of this to maintain the accuracy of any additional data or metadata in the resource's inputs that may need to be updated during the refresh. This is required for the complete implementation of https://github.com/pulumi/pulumi-terraform/pull/349. Without access to the old inputs for a resource, TF-based providers would lose all information about default population during a refresh.
153 lines
4.9 KiB
Go
153 lines
4.9 KiB
Go
// Copyright 2016-2018, Pulumi Corporation.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package deploytest
|
|
|
|
import (
|
|
"github.com/blang/semver"
|
|
uuid "github.com/satori/go.uuid"
|
|
|
|
"github.com/pulumi/pulumi/pkg/resource"
|
|
"github.com/pulumi/pulumi/pkg/resource/plugin"
|
|
"github.com/pulumi/pulumi/pkg/tokens"
|
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
|
"github.com/pulumi/pulumi/pkg/workspace"
|
|
)
|
|
|
|
type Provider struct {
|
|
Name string
|
|
Package tokens.Package
|
|
Version semver.Version
|
|
|
|
configured bool
|
|
|
|
CheckConfigF func(olds, news resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error)
|
|
DiffConfigF func(olds, news resource.PropertyMap) (plugin.DiffResult, error)
|
|
ConfigureF func(news resource.PropertyMap) error
|
|
|
|
CheckF func(urn resource.URN,
|
|
olds, news resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error)
|
|
DiffF func(urn resource.URN, id resource.ID, olds, news resource.PropertyMap) (plugin.DiffResult, error)
|
|
CreateF func(urn resource.URN,
|
|
inputs resource.PropertyMap) (resource.ID, resource.PropertyMap, resource.Status, error)
|
|
UpdateF func(urn resource.URN, id resource.ID,
|
|
olds, news resource.PropertyMap) (resource.PropertyMap, resource.Status, error)
|
|
DeleteF func(urn resource.URN, id resource.ID, olds resource.PropertyMap) (resource.Status, error)
|
|
|
|
ReadF func(urn resource.URN, id resource.ID,
|
|
inputs, state resource.PropertyMap) (plugin.ReadResult, resource.Status, error)
|
|
InvokeF func(tok tokens.ModuleMember,
|
|
inputs resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error)
|
|
|
|
CancelF func() error
|
|
}
|
|
|
|
func (prov *Provider) SignalCancellation() error {
|
|
if prov.CancelF == nil {
|
|
return nil
|
|
}
|
|
return prov.CancelF()
|
|
}
|
|
|
|
func (prov *Provider) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (prov *Provider) Pkg() tokens.Package {
|
|
return prov.Package
|
|
}
|
|
|
|
func (prov *Provider) GetPluginInfo() (workspace.PluginInfo, error) {
|
|
return workspace.PluginInfo{
|
|
Name: prov.Name,
|
|
Version: &prov.Version,
|
|
}, nil
|
|
}
|
|
|
|
func (prov *Provider) CheckConfig(olds,
|
|
news resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error) {
|
|
if prov.CheckConfigF == nil {
|
|
return news, nil, nil
|
|
}
|
|
return prov.CheckConfigF(olds, news)
|
|
}
|
|
func (prov *Provider) DiffConfig(olds, news resource.PropertyMap) (plugin.DiffResult, error) {
|
|
if prov.DiffConfigF == nil {
|
|
return plugin.DiffResult{}, nil
|
|
}
|
|
return prov.DiffConfigF(olds, news)
|
|
}
|
|
func (prov *Provider) Configure(inputs resource.PropertyMap) error {
|
|
contract.Assert(!prov.configured)
|
|
prov.configured = true
|
|
|
|
if prov.ConfigureF == nil {
|
|
return nil
|
|
}
|
|
return prov.ConfigureF(inputs)
|
|
}
|
|
|
|
func (prov *Provider) Check(urn resource.URN,
|
|
olds, news resource.PropertyMap, _ bool) (resource.PropertyMap, []plugin.CheckFailure, error) {
|
|
if prov.CheckF == nil {
|
|
return news, nil, nil
|
|
}
|
|
return prov.CheckF(urn, olds, news)
|
|
}
|
|
func (prov *Provider) Create(urn resource.URN, props resource.PropertyMap) (resource.ID,
|
|
resource.PropertyMap, resource.Status, error) {
|
|
if prov.CreateF == nil {
|
|
return resource.ID(uuid.NewV4().String()), resource.PropertyMap{}, resource.StatusOK, nil
|
|
}
|
|
return prov.CreateF(urn, props)
|
|
}
|
|
func (prov *Provider) Diff(urn resource.URN, id resource.ID,
|
|
olds resource.PropertyMap, news resource.PropertyMap, _ bool) (plugin.DiffResult, error) {
|
|
if prov.DiffF == nil {
|
|
return plugin.DiffResult{}, nil
|
|
}
|
|
return prov.DiffF(urn, id, olds, news)
|
|
}
|
|
func (prov *Provider) Update(urn resource.URN, id resource.ID,
|
|
olds resource.PropertyMap, news resource.PropertyMap) (resource.PropertyMap, resource.Status, error) {
|
|
if prov.UpdateF == nil {
|
|
return news, resource.StatusOK, nil
|
|
}
|
|
return prov.UpdateF(urn, id, olds, news)
|
|
}
|
|
func (prov *Provider) Delete(urn resource.URN,
|
|
id resource.ID, props resource.PropertyMap) (resource.Status, error) {
|
|
if prov.DeleteF == nil {
|
|
return resource.StatusOK, nil
|
|
}
|
|
return prov.DeleteF(urn, id, props)
|
|
}
|
|
|
|
func (prov *Provider) Read(urn resource.URN, id resource.ID,
|
|
inputs, state resource.PropertyMap) (plugin.ReadResult, resource.Status, error) {
|
|
if prov.ReadF == nil {
|
|
return plugin.ReadResult{
|
|
Outputs: resource.PropertyMap{},
|
|
Inputs: resource.PropertyMap{},
|
|
}, resource.StatusUnknown, nil
|
|
}
|
|
return prov.ReadF(urn, id, inputs, state)
|
|
}
|
|
func (prov *Provider) Invoke(tok tokens.ModuleMember,
|
|
args resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error) {
|
|
if prov.InvokeF == nil {
|
|
return resource.PropertyMap{}, nil, nil
|
|
}
|
|
return prov.InvokeF(tok, args)
|
|
}
|