IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
342 stars 673 forks source link

ibm_container_vpc_cluster.zones cannot be assigned a list from null_data_source #874

Closed ossm1db closed 2 years ago

ossm1db commented 5 years ago

Terraform Version

Terraform v0.11.14

Affected Resource(s)

Terraform Configuration Files

resource "ibm_is_vpc" "vpc" {
  name = "${var.cluster_name}-vpc"
  resource_group = "${var.resource_group_id}"
}

resource "ibm_is_subnet" "subnets" {
  count = "${var.zone_count}"
  name  = "${var.cluster_name}-subnet${count.index + 1}"
  vpc   = "${ibm_is_vpc.vpc.id}"
  zone  = "${var.region}-${count.index + 1}"
  total_ipv4_address_count = 256
}

data "null_data_source" "zones" {
  count  = "${var.zone_count}"
  inputs = {
    name      = "${var.region}-${count.index + 1}"
    subnet_id = "${element(ibm_is_subnet.subnets.*.id,count.index)}"
  }
}

output "zones" {
  value = "${data.null_data_source.zones.*.outputs}"
}

resource "ibm_container_vpc_cluster" "cluster" {
  name              = "${var.cluster_name}"
  vpc_id            = "${ibm_is_vpc.vpc.id}"
  flavor            = "c2.2x4"
  worker_count      = "1"
  resource_group_id = "${data.ibm_resource_group.resource_group.id}"
  zones             = "${data.null_data_source.zones.*.outputs}"
}

Expected Behavior

No errors.

Actual Behavior

Error: ibm_container_vpc_cluster.cluster: zones: should be a list

Steps to Reproduce

  1. terraform plan

Important Factoids

Is the zones field a child block and not a standard attribute? See link below.

zones = [
    {
        name = us-south-1,
        subnet_id = 6ebec0b3-c081-44a2-98a1-8c6427372597
    },
    {
        name = us-south-2,
        subnet_id = 2d2907cb-d856-4122-a33c-57081ddd81ce
    }
]

References

hkantare commented 5 years ago

zone is a list type. As per below issues https://github.com/terraform-providers/terraform-provider-null/issues/18 https://github.com/terraform-providers/terraform-provider-spotinst/issues/62#issuecomment-506493618

We can't use output from null_resource to set to zone(list)

hkantare commented 5 years ago

It may work in Terraform v0.12 by using dynamic blocks

ossm1db commented 5 years ago

Thanks for the quick response. I was thinking that one of two solutions might be possible:

hkantare commented 2 years ago

closing the issue due to no recent activity. Please feel free to open new issue