-
Notifications
You must be signed in to change notification settings - Fork 11
Closed
Description
Terraform providers generally use the schema.Block type for ordered nested attributes. Specifically, for ordered nested attributes that are an "array of structs" rather than an array of primitive types like strings, numbers, etc.
Moving to schema.Block allows the code to use typed structs for nested attributes and, more importantly, unlocks our ability to support dynamic blocks.
Here's what setting multiple network interfaces looks like today.
resource "oxide_instance" "example" {
network_interfaces = [
{
subnet_id = "692b78f6-57e7-4b25-9799-8468481ccb35"
vpc_id = "0e463e0e-6dd2-4442-991b-60dc457b421f"
description = "Primary NIC."
name = "primary"
},
{
subnet_id = "692b78f6-57e7-4b25-9799-8468481ccb35"
vpc_id = "0e463e0e-6dd2-4442-991b-60dc457b421f"
description = "Secondary NIC."
name = "secondary"
},
]
}Here's what it would look like using schema.Block.
resource "oxide_instance" "example" {
network_interface {
subnet_id = "692b78f6-57e7-4b25-9799-8468481ccb35"
vpc_id = "0e463e0e-6dd2-4442-991b-60dc457b421f"
description = "Primary NIC."
name = "primary"
}
network_interface {
subnet_id = "692b78f6-57e7-4b25-9799-8468481ccb35"
vpc_id = "0e463e0e-6dd2-4442-991b-60dc457b421f"
description = "Secondary NIC."
name = "secondary"
}
}Here's what it would look like using schema.Block and dynamic blocks.
resource "oxide_instance" "example" {
dynamic "network_interface" {
for_each = toset(["primary", "secondary"])
content {
subnet_id = "692b78f6-57e7-4b25-9799-8468481ccb35"
vpc_id = "0e463e0e-6dd2-4442-991b-60dc457b421f"
description = "${network_interface.value} NIC."
name = network_interface.value
}
}
}Metadata
Metadata
Assignees
Labels
No labels