【问题标题】:How to execute one module using conditionals?如何使用条件执行一个模块?
【发布时间】:2022-01-12 08:53:01
【问题描述】:
module "s3_bucket" {source = "./module/s3_bucket"}
module "s3_bucket_2" {source = "./module/s3_bucket_2"}
这是我在 main.tf 文件中调用的两个模块,但我想使用一些条件,以便我可以在任何时间点调用我想要的任何一个模块,并且只有那个模块在那个时候被执行时间,那么他们有什么办法吗?
【问题讨论】:
标签:
amazon-web-services
amazon-s3
terraform
【解决方案1】:
我不太了解您的问题,但我想您想要或至少有助于回答您的问题如下。
您可以在 variables.tf 中创建一个名为 create 的变量,然后将其传递给模块。
# Set a variable to know if the resources inside the module should be created
module "s3_bucket" {
source = "./module/s3_bucket"
create = var.create
}
# For every resource inside use the count to create or not each resource
resource "resource_type" "resource_name" {
count = var.create ? 1 : 0
... other resource attributes
}