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

Teo*_*oro 15 amazon-web-services pulumi

我在文档中没有看到任何有关如何从堆栈中删除导入资源的选项。如果我尝试从代码中删除资源的引用,则会在运行时收到以下错误pulumi up
error: Preview failed: refusing to delete protected resource 'urn:pulumi:dev::my-cloud-infrastructure::aws:iam/instanceProfile:InstanceProfile::EC2CodeDeploy'

Teo*_*oro 31

正如 Pulumi Slack 社区频道中的回答,可以使用以下命令:
pulumi state delete <urn>

这将从您的状态文件中删除引用,但不会从 aws 中删除引用。

此外,如果资源受到保护,您首先必须取消保护它或使用 flag 运行上述命令--force


Gre*_*egK 12

对于“更庞大”的操作,您可以将堆栈导出为 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
Run Code Online (Sandbox Code Playgroud)