terraform aws 提供程序:在子模块中添加默认标签
我在根模块 my_terraform
中使用 terraform aws 提供程序 default_tags
块。该模块有一个名为 my_submodule
的子模块,我想在该子模块中添加其他默认标签。我在 my_terraform/my_submodule/main.tf
中尝试过:
provider "aws" {
default_tags {
tags = {
"extra_tag" = "something"
}
}
}
但我收到此错误:
$ terraform init
Initializing modules...
- my_terraform.my_submodule in my_terraform/my_submodule
There are some problems with the configuration, described below.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Module module.my_submodule contains provider configuration
│
│ Providers cannot be configured within modules using count, for_each or depends_on.
有什么办法解决这个问题吗?
I'm using terraform aws provider default_tags
block in a root module my_terraform
. That module has a submodule called my_submodule
, and I would like to have additional default tags in that submodule. I tried this in my_terraform/my_submodule/main.tf
:
provider "aws" {
default_tags {
tags = {
"extra_tag" = "something"
}
}
}
But I get this error:
$ terraform init
Initializing modules...
- my_terraform.my_submodule in my_terraform/my_submodule
There are some problems with the configuration, described below.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Module module.my_submodule contains provider configuration
│
│ Providers cannot be configured within modules using count, for_each or depends_on.
Is there any way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方法是为每个所需的标签集创建一个不同的别名提供程序块,并 显式地将其传递到每个子模块。
A workaround is to create a different aliased provider block for each needed tag set and pass it explicitly to each submodule.
您还可以在模块中的每个资源上手动定义标签,并使用全局变量调用它。
You can also define your tags manually on each resource in the module and call it with a global variable.