Terraform:错误:提供程序配置不存在。模块已创建,但当我删除或评论时,它会抛出错误

问题描述 投票:0回答:1

所以我使用 terraform 模块,其中源是另一个内部 git 存储库。我可以使用该模块成功创建资源,但是当我尝试删除(或注释)时,该模块不会被删除。它抛出一个错误。但是,当我使用 terraform destroy 命令时,我可以通过命令行删除此模块。然而,很难识别代码删除并在 CI/CD 管道中运行 terraform destroy 命令。有解决方法吗?错误信息如下,

Error: Provider configuration not present

To work with module.foo (orphan) its original provider configuration at module.foo.provider["registry.terraform.io/datadog/datadog"] is required, but it has been removed. 
This occurs when a provider configuration is removed while objects created by that provider still exist in the state. 
Re-add the provider configuration to destroy module.foo (orphan), after which you can remove the provider configuration again.
terraform devops datadog infrastructure-as-code infrastructure
1个回答
0
投票

来自模块内的提供者(强调我的):

打算由一个或多个其他模块调用的模块不得包含任何提供程序块。

提供者配置用于关联资源上的所有操作,包括销毁远程对象和刷新状态。 Terraform 保留对最近用于将更改应用于每个资源的提供程序配置的引用,作为其状态的一部分。当从配置中删除

resource
块时,状态中的此记录将用于定位适当的配置,因为资源的
provider
参数(如果有)将不再出现在配置中。

因此,您必须确保属于特定提供程序配置的所有资源都已销毁,然后才能从您的配置中删除该提供程序配置的块。如果 Terraform 发现在提供程序配置块不再可用的状态下跟踪的资源实例,那么它将在规划期间返回错误,提示您重新引入提供程序配置。

另请参阅:

© www.soinside.com 2019 - 2024. All rights reserved.