是否有添加条件来选择资源本身
如果env = dev
,我需要以下资源resource "aws_rds_cluster" "myDB" {
cluster_identifier = "aurora-cluster-demo"
engine = "aurora-mysql"
engine_version = "5.7.mysql_aurora.2.03.2"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
database_name = "mydb"
master_username = "foo"
master_password = "bar"
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
}
resource "route53" "dns" {
}
其他低于资源
resource "aws_rds_cluster" "myDB" {
cluster_identifier = "aurora-cluster-demo"
engine = "aurora-postgres"
engine_version = "5.7.mysql_aurora.2.03.2"
database_name = "mydb"
master_username = "foo"
master_password = "bar"
preferred_backup_window = "07:00-09:00"
}
我可以开始如下所示添加所有变量,或创建局部变量。 engine = var.env = dev?“ aurora-mysql”:“ aurora-postgres”
还有其他方法可以禁用资源本身吗?
答案 0 :(得分:1)
也许在count
的帮助下,类似的事情也应该起作用
resource "aws_rds_cluster" "myDB-mysql" {
count = var.env == dev ? 1 : 0
cluster_identifier = "aurora-cluster-demo"
engine = "aurora-mysql"
engine_version = "5.7.mysql_aurora.2.03.2"
availability_zones = ["us-west-2a", "us-west-2b", "us-west-2c"]
database_name = "mydb"
master_username = "foo"
master_password = "bar"
backup_retention_period = 5
preferred_backup_window = "07:00-09:00"
}
resource "aws_rds_cluster" "myDB-postgres" {
count = var.env != dev ? 1 : 0
cluster_identifier = "aurora-cluster-demo"
engine = "aurora-postgres"
engine_version = "5.7.mysql_aurora.2.03.2"
database_name = "mydb"
master_username = "foo"
master_password = "bar"
preferred_backup_window = "07:00-09:00"
}