跳到正文

Upgrading to Pulumi 3.0 ​

Pulumi 3.0 is generally available. It’s simple to upgrade:

  1. Install or upgrade to the 3.0 CLI.
  2. Review the updated CLI behaviors listed below.
  3. Update each of your Pulumi programs to utilize the new version of the SDK.

Updated CLI behavior in Pulumi 3.0 ​

Previously, when using the --stack option on CLI commands, Pulumi would inconsistently set that stack as the current stack. In Pulumi 3.0, this behavior has now standardized and will NOT set the stack as the current stack. This affects the following commands:

  • pulumi cancel
  • pulumi config refresh
  • pulumi destroy
  • pulumi import
  • pulumi logs
  • pulumi preview
  • pulumi refresh
  • pulumi stack *
  • pulumi state
  • pulumi up
  • pulumi watch

Required updates to Pulumi programs ​

Update to the new SDK version ​

bash
npm install @pulumi/pulumi@^3.0.0

Changes to pulumi.runtime.Mocks ​

The signature of the setMocks function has changed with the introduction of the pulumi.runtime.MockResourceArgs and pulumi.runtime.MockCallArgs types. If you use setMocks in your code, you'll need to update to these new types.

javascript
// before
pulumi.runtime.setMocks({
    newResource: function(type: string, name: string, inputs: any): {id: string, state: any} {
        switch (type) {
            case "aws:ec2/securityGroup:SecurityGroup":
                return {
                    id: "sg-12345678",
                    state: {
                        ...inputs,

                        arn: "arn:aws:ec2:us-west-2:123456789012:security-group/sg-12345678",
                        name: inputs.name || name + "-sg",
                    },
                };
            case "aws:ec2/instance:Instance":
                return {
                    id: "i-1234567890abcdef0",
                    state: {
                        ...inputs,

                        arn: "arn:aws:ec2:us-west-2:123456789012:instance/i-1234567890abcdef0",
                        instanceState: "running",
                        primaryNetworkInterfaceId: "eni-12345678",
                        privateDns: "ip-10-0-1-17.ec2.internal",
                        publicDns: "ec2-203-0-113-12.compute-1.amazonaws.com",
                        publicIp: "203.0.113.12",
                    },
                };
            default:
                return {
                    id: inputs.name + "_id",
                    state: {
                        ...inputs,
                    },
                };
        }
    },
    call: function(token: string, args: any, provider?: string) {
    switch (token) {
        case "aws:ec2/getAmi:getAmi":
            return {
                "architecture": "x86_64",
                "id": "ami-0eb1f3cdeeb8eed2a",
            };
        default:
            return args;
    }
},
});

// after
pulumi.runtime.setMocks({
    newResource: function(args: pulumi.runtime.MockResourceArgs): {id: string, state: any} {
        switch (args.type) {
            case "aws:ec2/securityGroup:SecurityGroup":
                return {
                    id: "sg-12345678",
                    state: {
                        ...args.inputs,

                        arn: "arn:aws:ec2:us-west-2:123456789012:security-group/sg-12345678",
                        name: args.inputs.name || name + "-sg",
                    },
                };
            case "aws:ec2/instance:Instance":
                return {
                    id: "i-1234567890abcdef0",
                    state: {
                        ...args.inputs,

                        arn: "arn:aws:ec2:us-west-2:123456789012:instance/i-1234567890abcdef0",
                        instanceState: "running",
                        primaryNetworkInterfaceId: "eni-12345678",
                        privateDns: "ip-10-0-1-17.ec2.internal",
                        publicDns: "ec2-203-0-113-12.compute-1.amazonaws.com",
                        publicIp: "203.0.113.12",
                    },
                };
            default:
                return {
                    id: args.inputs.name + "_id",
                    state: {
                        ...args.inputs,
                    },
                };
        }
    },
    call: function(args: MockCallArgs) {
        switch (args.token) {
            case "aws:ec2/getAmi:getAmi":
                return {
                    "architecture": "x86_64",
                    "id": "ami-0eb1f3cdeeb8eed2a",
                };
            default:
                return args.inputs;
        }
    },
});

Required updates for automation API users ​

If you used a pre-GA release of Automation API, you need to update programs that use automation API to use the following namespaces:

javascript
// before
import as automation from "@pulumi/pulumi/x/automation";

//after
import as automation from "@pulumi/pulumi/automation";

Remaining on Pulumi 2.0 ​

We recommend switching to Pulumi 3.0 if possible. We will only push critical security and bug fixes into the 2.x branch. Other fixes, feature enhancements, and new functionality will not be supported in the 2.x branch. In addition, provider updates will only be built against Pulumi 3.0.

If you wish to remain on the 2.x CLI, you can continue to download the CLI by referring to the manual installation instructions and choosing a specific version.

Running pulumi new will attempt to use the latest versions of the project templates, which pull in the 3.0 SDK. You can continue to use the 2.x templates by running pulumi new https://github.com/pulumi/templates/tree/2.x.

文档内容翻译自 Pulumi 官方文档。