Incorrect attribute value type (tuple with one element) azurerm_subnet

770 views
Skip to first unread message

Harri

unread,
Jan 21, 2020, 11:06:10 AM1/21/20
to Terraform
I'm creating a subnet resource based on a map:

#from module subnet variable subnet_block { type = map default = { subnet01 = "10.0.0.0/24" #subnet02 = "10.0.2.0/24" #subnet03 = "10.0.3.0/24" } } resource "azurerm_subnet" "subnet_block" { for_each = var.subnet_block resource_group_name = var.vnet_rg_name virtual_network_name = var.vnet_name name = each.key address_prefix = each.value } output "vnet_subnet_block" { description = "The ids of subnets created outside of vnet via subnet_block" value = [for i in azurerm_subnet.subnet_block: flatten(i.*.id)] depends_on = [ # azurerm_subnet subnets must be created before these ids could # actually be used azurerm_subnet.subnet_block ] } #module aks variable vnet_subnet_id { default = flatten([module.subnet.vnet_subnet_block]) } resource "azurerm_kubernetes_cluster" "k8s" { name = var.aks_cluster_name location = var.location resource_group_name = var.aks_rg_name dns_prefix = var.aks_dns_prefix default_node_pool { name = "default" type = "VirtualMachineScaleSets" node_count = var.aks_agent_count vm_size = "Standard_B2s" vnet_subnet_id = var.vnet_subnet_id #this is line 39 }

getting the error:

Error: Incorrect attribute value type on ..\modules\aks\aks.tf line 39, in resource "azurerm_kubernetes_cluster" "k8s": 39: vnet_subnet_id = var.vnet_subnet_id |---------------- | var.vnet_subnet_id is tuple with 1 element Inappropriate value for attribute "vnet_subnet_id": string required.

tf output is:

vnet_subnet_block = [
[ "/subscriptions/<redacted>/providers/Microsoft.Network/subnet01",
] ]

I tried to flatten vnet_subnet_block but that doesn't seem to do the trick.

any ideas?


Lowe Schmidt

unread,
Jan 21, 2020, 12:02:50 PM1/21/20
to Terraform
flatten works on lists, not on sets. 

What does var.vnet_subnet_idlook like?
--
Lowe Schmidt | +46 723 867 157


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/f235b7ca-a08a-4d4d-9ab3-406870924cb4%40googlegroups.com.

Harri

unread,
Jan 21, 2020, 6:03:52 PM1/21/20
to Terraform
var.vnet_subnet_id looks like the first item on the list:
[
"/subscriptions/<redacted>/providers/Microsoft.Network/subnet01",
]

I ended up just doing this: (not sure if that's best practice heh.

 vnet_subnet_id = flatten(module.subnet.vnet_subnet_block)[0]

Thanks for responding!

On Tuesday, January 21, 2020 at 12:02:50 PM UTC-5, Lowe Schmidt wrote:
flatten works on lists, not on sets. 

What does var.vnet_subnet_idlook like?
--
Lowe Schmidt | +46 723 867 157


On Tue, 21 Jan 2020 at 17:06, Harri <harr...@gmail.com> wrote:
I'm creating a subnet resource based on a map:

#from module subnet variable subnet_block { type = map default = { subnet01 = "10.0.0.0/24" #subnet02 = "10.0.2.0/24" #subnet03 = "10.0.3.0/24" } } resource "azurerm_subnet" "subnet_block" { for_each = var.subnet_block resource_group_name = var.vnet_rg_name virtual_network_name = var.vnet_name name = each.key address_prefix = each.value } output "vnet_subnet_block" { description = "The ids of subnets created outside of vnet via subnet_block" value = [for i in azurerm_subnet.subnet_block: flatten(i.*.id)] depends_on = [ # azurerm_subnet subnets must be created before these ids could # actually be used azurerm_subnet.subnet_block ] } #module aks variable vnet_subnet_id { default = flatten([module.subnet.vnet_subnet_block]) } resource "azurerm_kubernetes_cluster" "k8s" { name = var.aks_cluster_name location = var.location resource_group_name = var.aks_rg_name dns_prefix = var.aks_dns_prefix default_node_pool { name = "default" type = "VirtualMachineScaleSets" node_count = var.aks_agent_count vm_size = "Standard_B2s" vnet_subnet_id = var.vnet_subnet_id #this is line 39 }

getting the error:

Error: Incorrect attribute value type on ..\modules\aks\aks.tf line 39, in resource "azurerm_kubernetes_cluster" "k8s": 39: vnet_subnet_id = var.vnet_subnet_id |---------------- | var.vnet_subnet_id is tuple with 1 element Inappropriate value for attribute "vnet_subnet_id": string required.

tf output is:

vnet_subnet_block = [
[ "/subscriptions/<redacted>/providers/Microsoft.Network/subnet01",
] ]

I tried to flatten vnet_subnet_block but that doesn't seem to do the trick.

any ideas?


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terrafo...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages