Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plan error: delete-replaced is not allowed by the plan: this resource is constrained to replace #10924

Closed
adam-kiss-sg opened this issue Oct 5, 2022 · 1 comment · Fixed by #11009
Assignees
Labels
area/update-plans kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@adam-kiss-sg
Copy link

adam-kiss-sg commented Oct 5, 2022

What happened?

Was trying to deploy using update plans, and got the following error: delete-replaced is not allowed by the plan: this resource is constrained to replace

Steps to reproduce

  1. Create the following stack with pulumi up:
    "use strict";
    const pulumi = require("@pulumi/pulumi");
    const aws = require("@pulumi/aws");
    
    const iamForLambda = new aws.iam.Role("iamForLambda", {
      assumeRolePolicy: `{
        "Version": "2012-10-17",
        "Statement": [
          {
            "Action": "sts:AssumeRole",
            "Principal": {
              "Service": "lambda.amazonaws.com"
            },
            "Effect": "Allow",
            "Sid": ""
          }
        ]
      }
      `,
    });
    const testLambda = new aws.lambda.Function("testLambda", {
      code: new pulumi.asset.FileArchive("lambda"),
      role: iamForLambda.arn,
      handler: "index.test",
      runtime: "nodejs16.x",
      name: "repro-test"
    });
    
    const eventRuleDaily = new aws.cloudwatch.EventRule("eventRuleDaily", {
      scheduleExpression: "cron(0 12 * * ? *)",
    })
    
    new aws.cloudwatch.EventTarget("event-target-daily", {
      arn: testLambda.arn,
      rule: eventRuleDaily.name,
      targetId: "TestTarget",
    })
    
    new aws.lambda.Permission("permission-daily", {
      action: "lambda:InvokeFunction",
      function: testLambda.arn,
      principal: "events.amazonaws.com",
      source_arn: eventRuleDaily.arn,
    })
    
  2. change the lambda name
  3. run pulumi preview --save-plan plan.json
  4. run pulumi up --plan plan.json

Expected Behavior

The update should work

Actual Behavior

Get the error message: delete-replaced is not allowed by the plan: this resource is constrained to replace

Output of pulumi about

CLI
Version 3.40.2
Go Version go1.19.1
Go Compiler gc

Plugins
NAME VERSION
aws 5.16.2
docker 3.4.1
nodejs unknown

Host
OS ubuntu
Version 20.04
Arch x86_64

This project is written in nodejs: executable='/usr/bin/node' version='v16.13.0'

Current Stack: dev

TYPE URN
pulumi:pulumi:Stack urn:pulumi:dev::pulumilambda::pulumi:pulumi:Stack::pulumilambda-dev
pulumi:providers:aws urn:pulumi:dev::pulumilambda::pulumi:providers:aws::default_5_16_2
aws:iam/role:Role urn:pulumi:dev::pulumilambda::aws:iam/role:Role::iamForLambda
aws:cloudwatch/eventRule:EventRule urn:pulumi:dev::pulumilambda::aws:cloudwatch/eventRule:EventRule::eventRuleDaily
aws:lambda/function:Function urn:pulumi:dev::pulumilambda::aws:lambda/function:Function::testLambda
aws:cloudwatch/eventTarget:EventTarget urn:pulumi:dev::pulumilambda::aws:cloudwatch/eventTarget:EventTarget::event-target-daily
aws:lambda/permission:Permission urn:pulumi:dev::pulumilambda::aws:lambda/permission:Permission::permission-daily

Found no pending operations associated with dev

Backend
Name SG0166
URL file://stacks
User adam-kiss
Organizations

Dependencies:
NAME VERSION
@pulumi/awsx 0.40.1
@pulumi/pulumi 3.40.2
@pulumi/aws 5.16.2

Pulumi locates its logs in /tmp by default

Additional context

$ pulumi preview --save-plan plan.json
Previewing update (dev):
     Type                           Name                Plan        Info
     pulumi:pulumi:Stack            pulumilambda-dev                
 +-  ├─ aws:lambda:Permission       permission-daily    replace     [diff: ~function,statementId]
 +-  ├─ aws:lambda:Function         testLambda          replace     [diff: ~name]
 ~   └─ aws:cloudwatch:EventTarget  event-target-daily  update      [diff: ~arn]
 
Resources:
    ~ 1 to update
    +-2 to replace
    3 changes. 3 unchanged

Update plan written to 'plan.json'
Run `pulumi up --plan='plan.json'` to constrain the update to the operations planned by this preview

$ pulumi up --plan plan.json
Previewing update (dev):
     Type                    Name              Plan     Info
     pulumi:pulumi:Stack     pulumilambda-dev           
     └─ aws:lambda:Function  testLambda                 1 error
 
Diagnostics:
  aws:lambda:Function (testLambda):
    error: delete-replaced is not allowed by the plan: this resource is constrained to replace

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@adam-kiss-sg adam-kiss-sg added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Oct 5, 2022
@Frassle Frassle added area/update-plans and removed needs-triage Needs attention from the triage team labels Oct 5, 2022
@Frassle Frassle self-assigned this Oct 10, 2022
@Frassle Frassle added this to the 0.79 milestone Oct 10, 2022
@Frassle
Copy link
Member

Frassle commented Oct 13, 2022

Thanks for this report, I've tracked this down to an issue with generating the plans for resources that are being replaced due to dependencies on others resources that are being replaced. Working on a smaller reproduction to add to our test suite and a fix now.

Frassle added a commit that referenced this issue Oct 13, 2022
We weren't correctly handling the case where a resource was marked for
deletion due to one of it's dependencies being deleted. We would add an
entry to it's "Ops" list, but then overwrite that "Ops" list when we
came to generate the recreation step.

Fixes #10924
@mikhailshilkov mikhailshilkov modified the milestones: 0.79, 0.80 Oct 25, 2022
bors bot added a commit that referenced this issue Nov 1, 2022
11009: Fix update plans with dependent replacements r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

We weren't correctly handling the case where a resource was marked for deletion due to one of it's dependencies being deleted. We would add an entry to it's "Ops" list, but then overwrite that "Ops" list when we came to generate the recreation step.

Fixes #10924

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11027: Do not execute pending deletes at the start of deployment r=Frassle a=Frassle

<!--- 
Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation.
-->

# Description

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

This removes all the handling of pending deletes from the start of deployments. Instead we allow resources to just be deleted as they usually would at the end of the deployment.

There's a big comment in TestPendingDeleteOrder that explains the order of operations in a succesful run and how that order differs if we try and do pending deletes up-front.

Fixes #2948

## Checklist

<!--- Please provide details if the checkbox below is to be left unchecked. -->
- [x] I have added tests that prove my fix is effective or that my feature works
<!--- 
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the Pulumi Service,
then the service should honor older versions of the CLI where this change would not exist.
You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


Co-authored-by: Fraser Waters <fraser@pulumi.com>
@bors bors bot closed this as completed in 1482df9 Nov 1, 2022
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/update-plans kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants