将属性设置为 null 与不在 Terraform 配置中设置它一样吗?

Is setting an attribute to null the same as not setting it in Terraform configuration?

我在查看terraform VPC模块的代码,发现

resource "aws_subnet" "public" {
   vpc_id     = aws_vpc_ipv4_cidr_block_association.secondary_cidr.vpc_id
   cidr_block = "172.2.0.0/24"
   availability_zone = null
}

availability_zone 属性是可选的,基于 AWS 提供商的 docs

availability_zone设置为null是否与不全部列出一样?比如下面这样写配置也是一样的:

resource "aws_subnet" "in_secondary_cidr" {
  vpc_id     = aws_vpc_ipv4_cidr_block_association.secondary_cidr.vpc_id
  cidr_block = "172.2.0.0/24"
}

我以前从未见过。似乎这是在模块中声明可选变量的流行方式:

variable "private_subnet_assign_ipv6_address_on_creation" {
  description = "Assign IPv6 address on private subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map_public_ip_on_launch"
  type        = bool
  default     = null
}

是的,如果你使用 null 就等于没有全部列出。来自文档:

a value that represents absence or omission. If you set an argument of a resource to null, Terraform behaves as though you had completely omitted it — it will use the argument's default value if it has one, or raise an error if the argument is mandatory. null is most useful in conditional expressions, so you can dynamically omit an argument if a condition isn't met.