【发布时间】:2021-11-26 14:04:50
【问题描述】:
我正在 terraform 中创建 RDS 数据库,如果 var 等于任何值,我不知道如何声明参数。我的代码:
resource "aws_db_instance" "mariaDB" {
for_each = var.rds_databases[terraform.workspace]
identifier = "api-mariadb-${each.value.name}"
allocated_storage = each.value.allocated_storage
storage_type = each.value.storage_type
engine = each.value.engine
engine_version = each.value.engine_version
allow_major_version_upgrade = each.value.allow_major_version_upgrade
auto_minor_version_upgrade = each.value.auto_minor_version_upgrade
instance_class = each.value.instance_class
name = each.value.dbname
username = each.value.dbusername
password = each.value.dbpassword
db_subnet_group_name = aws_db_subnet_group.subnet-mariadb[each.value.name].name
skip_final_snapshot = true
vpc_security_group_ids = [aws_security_group.rds_SG.id]
storage_encrypted = true
snapshot_identifier = each.value.snapshot_identifier <--- THIS VALUE ONLY HAVE TO BE DECLARED IF THE VAR SNAPSHOT_IDENTIFIER != null
说明:我必须声明 snapshot_identifier 仅当不等于“null”时(例如)。有什么办法吗?
谢谢!
【问题讨论】:
-
该资源应该按照当前编写的方式运行。如果
each.value.snapshot_identifier是null,则参数将被省略。如果它已被分配一个值,那么该值同样会被分配给参数snapshot_identifier。您能否提供更多关于观察到的行为与预期行为有何不同的信息?
标签: terraform amazon-rds