简体   繁体   English

Pulumi - 如何从堆栈中删除导入的资源而不从 aws 中删除它们?

[英]Pulumi - How can I remove imported resources from my stack without deleting them from aws?

I don't see any options in the documentation on how to delete imported resources from my stack.我在文档中没有看到有关如何从我的堆栈中删除导入资源的任何选项。 If I try to remove the resource's reference from my code I get the following error when running pulumi up :如果我尝试从我的代码中删除资源的引用,我会在运行pulumi up时收到以下错误:
error: Preview failed: refusing to delete protected resource 'urn:pulumi:dev::my-cloud-infrastructure::aws:iam/instanceProfile:InstanceProfile::EC2CodeDeploy'

As answered in the Pulumi Slack community channel, one can use the command:正如 Pulumi Slack 社区频道中所回答的那样,可以使用以下命令:
pulumi state delete <urn>

This will remove the reference from your state file but not from aws.这将从您的 state 文件中删除引用,但不会从 aws 中删除。

Also, if the resource is protected you'll first have to unprotect it or run the above command with the flag --force .此外,如果资源受到保护,您首先必须取消保护它或使用标志运行上述命令--force

For "bulkier" operations, you can export the stack as a JSON, delete the resources and import it back in ( docs ):对于“更大”的操作,您可以将堆栈导出为 JSON,删除资源并将其重新导入( 文档):

# Get the current stack as json:
pulumi stack export --file stack.json

# Delete what you don't want from your stack file and then:
pulumi stack import --file stack.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 AWS 胶水访问 VPC 中的 aws 资源? - How can I access aws resources in VPC from AWS glue? 如何从 C# 访问 AWS CLI 资源? - How can I access AWS CLI resources from C#? 如何通过忽略未使用的资源从 aws cli 创建 aws java lambda function? - how can i create the aws java lambda function from aws cli by ignoring unused resources? AWS CDK:如何从单个堆栈部署多个堆栈 - AWS CDK: How can I deploy multiple stack from a single stack 如何阻止 Terraform 删除导入的资源? - How to block Terraform from deleting an imported resource? 如何在 cloudformation 堆栈更新期间删除资源而不将其删除 - How to remove a resource without deleting it during a cloudformation stack update 如何从 aws 导入所有现有基础设施 state 并将其与生成的反向地形资源进行比较? - How can I import all the existing infrastructure state from aws and compare it with the generated reverse-terraformed resources? 如何从 AWS Config Advanced 查询中获取唯一的资源计数 - How can I get a unique count of resources from AWS Config Advanced query 如何在 Pulumi 中实现共享资源 - How to implement shared resources in Pulumi 我在哪里可以找到pulumi aws.apigateway.x文档 - Where can I find pulumi aws.apigateway.x Documentation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM