is there a way to clean up pending operations from...
# automation-api
is there a way to clean up pending operations from the state using automation api?
currently we stack export, clean them and stack import, but there's a big notice on unmarshalling state to versioned deployment
I don't think there is an easy way, but you could do export/clean/import in your automation program I think
pulumi refresh
clears pending operations, so I would think you should be able to use the refresh method on a stack in automation API to do so.
Yes, newer versions of the Pulumi CLI clean the delete operations, which were the only ones that you needed to use the export/clean/import workaround to deal with. These days, refresh should cover all bases.
👍 1
I'm running
and refresh doesn't modify state via automation api. It doesn't remove pending operations and doesn't reimport running resources, which is pretty annoying
It works for me. I have this inline program:
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an AWS resource (S3 Bucket)
const bucket = new aws.s3.Bucket("my-bucket", {
    versioning: {
        enabled: false

// Export the name of the bucket
export const bucketName =;
I have this automation API program:
Copy code
import { LocalProgramArgs, LocalWorkspace } from "@pulumi/pulumi/automation";
import * as upath from "upath";

const process = require('process');

const args = process.argv.slice(2);
let destroy = false;
if (args.length > 0 && args[0]) {
    destroy = args[0] === "destroy";

const run = async () => {

    // Create our stack using a local program
    // in the ../website directory
    const args: LocalProgramArgs = {
        stackName: "dev",
        workDir: upath.joinSafe(__dirname, "..", "bucket"),

    // create (or select if one already exists) a stack that uses our local program
    const stack = await LocalWorkspace.createOrSelectStack(args);

    <|>("successfully initialized stack");
    <|>("setting up config");
    await stack.setConfig("aws:region", { value: "us-west-2" });
    <|>("config set");
    <|>("refreshing stack...");
    await stack.refresh({ onOutput: <|> });
    <|>("refresh complete");

    if (destroy) {
        <|>("destroying stack...");
        await stack.destroy({onOutput: <|>});
        <|>("stack destroy complete");

    <|>("updating stack...");
    const upRes = await stack.up({ onOutput: <|> });
    console.log(`update summary: \n${JSON.stringify(upRes.summary.resourceChanges, null, 4)}`);

If I run the automation API program and then go into the AWS console and change versioning to Enabled and then run the automation API program again, versioning will then be disabled.
pulumi stack export | jq 'del(.deployment.pending_operations)' | pulumi stack import
in case you were still looking