Is there a way to control the Pulumi destroy order...
# general
g
Is there a way to control the Pulumi destroy order? I have an AWS Apigateway, and it's trying to delete the Stage before removing the Custom Domain API mappings, and of course this error results:
Copy code
aws:apigateway:Deployment (api_admin_secondDeployment):
    error: deleting urn:pulumi:demo::my-app::aws:apigateway/deployment:Deployment::api_admin_secondDeployment: 1 error occurred:
        * deleting API Gateway Stage (demo): BadRequestException: Deleting stage demo failed. Please remove all base path mappings related to the stage in your domains: my-domain.com
I can work around this by targeting the custom domain resource first but would be nice not to have to do this.
d
You can make the custom domain mapping depend on the api gateway, which will order the deletes as you want. https://www.pulumi.com/docs/concepts/options/dependson/
g
Ah, of course. Thanks @dry-keyboard-94795 . For some reason I had in my head that the customdomain already referred to the API gateway
In fact it already does
Copy code
apiCustomMapping_admin:
  type: aws:apigatewayv2:ApiMapping
  properties:
    apiId: ${api_admin.api.id}
I also added
Copy code
options:
      dependsOn:
        - ${api_admin.stage}
        - ${api_admin.api}
        - ${api_admin_secondDeployment}
But still getting
Copy code
* deleting API Gateway Stage (develop): BadRequestException: Deleting stage develop failed. Please remove all base path mappings related to the stage in your domains: <http://admin.develop.mydomain.com|admin.develop.mydomain.com>
I wonder if the added dependencies only take effect when the resources are recreated?
I guess so, because after destroying the entire stack and doing
pulumi up
again, I get this error
Copy code
error: resource option dependsOn value must be a list of resource, not an output
    
      on Pulumi.yaml line 437:
     437:         - ${api_admin.stage}
     438:         - ${api_admin.api}
     439:         - ${api_admin_secondDeployment}
So I guess that the config wasn't taking effect at all
d
Yes, dependsOn only takes effect after you've done an update so they're saved in state. Once it's in state, it should respect the chain while destroying. This sounds like a bug, as your use of
api.id
in the mapping properties should be a dependency