Skip to content

Commit

Permalink
[v3] Remove __inputs in state (#3772)
Browse files Browse the repository at this point in the history
This PR implements the next stage of removing the `__inputs` from state.
In this stage, the provider has "v2" and "v3" behavior. In "v2" mode,
the behavior is unchanged. In "v3" mode, `Configure` asserts that the
engine is passing the old inputs, and doesn't write `__inputs` to state.
The fallback code that reads the `__inputs` from state is effectively
inoperative in the "v3" mode.

Added a line item to this ticket for the final phase which is to remove
the "v2" code:
#3754

Closes #2686
  • Loading branch information
EronWright authored Dec 10, 2024
1 parent a8d8df8 commit b2e76de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 6 additions & 2 deletions provider/pkg/provider/crud/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/azure"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/convert"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/resources"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/version"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/logging"
Expand Down Expand Up @@ -258,10 +259,13 @@ func (r *resourceCrudClient) currentResourceStateCheckpoint(ctx context.Context,
)
}

// checkpointObject puts inputs in the `__inputs` field of the state.
// checkpointObject produces the checkpointed state for the given inputs and outputs.
// In v2, we stored the inputs in an `__inputs` field of the state; removed in v3.
func checkpointObject(inputs resource.PropertyMap, outputs map[string]interface{}) resource.PropertyMap {
object := resource.NewPropertyMapFromMap(outputs)
object["__inputs"] = resource.MakeSecret(resource.NewObjectProperty(inputs))
if version.GetVersion().Major < 3 {
object["__inputs"] = resource.MakeSecret(resource.NewObjectProperty(inputs))
}
return object
}

Expand Down
13 changes: 11 additions & 2 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/resources"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/resources/customresources"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/util"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/version"
"github.com/pulumi/pulumi/pkg/v3/resource/provider"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
Expand Down Expand Up @@ -166,6 +167,11 @@ func (p *azureNativeProvider) Attach(context context.Context, req *rpc.PluginAtt
func (k *azureNativeProvider) Configure(ctx context.Context,
req *rpc.ConfigureRequest) (*rpc.ConfigureResponse, error) {

if version.GetVersion().Major >= 3 && (!req.GetSendsOldInputs() || !req.GetSendsOldInputsToDelete()) {
// https://github.com/pulumi/pulumi-azure-native/issues/2686
return nil, errors.New("Azure Native provider requires Pulumi CLI v3.74.0 or later")
}

for key, val := range req.GetVariables() {
k.config[strings.TrimPrefix(key, "azure-native:config:")] = val
}
Expand Down Expand Up @@ -1578,10 +1584,13 @@ func azureContext(ctx context.Context, timeoutSeconds float64) (context.Context,
return context.WithTimeout(ctx, d)
}

// checkpointObject puts inputs in the `__inputs` field of the state.
// checkpointObject produces the checkpointed state for the given inputs and outputs.
// In v2, we stored the inputs in an `__inputs` field of the state; removed in v3.
func checkpointObject(inputs resource.PropertyMap, outputs map[string]interface{}) resource.PropertyMap {
object := resource.NewPropertyMapFromMap(outputs)
object["__inputs"] = resource.MakeSecret(resource.NewObjectProperty(inputs))
if version.GetVersion().Major < 3 {
object["__inputs"] = resource.MakeSecret(resource.NewObjectProperty(inputs))
}
return object
}

Expand Down
11 changes: 11 additions & 0 deletions provider/pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@

package version

import "github.com/blang/semver"

// Version is initialized by the Go linker to contain the semver of this build.
var Version string

func GetVersion() semver.Version {
v := Version
if v == "" {
// fallback to a default version e.g. for unit tests (see: PROVIDER_VERSION in Makefile)
v = "2.0.0-alpha.0+dev"
}
return semver.MustParse(v)
}

0 comments on commit b2e76de

Please sign in to comment.