DimensionDataResearch / terraform-provider-ddcloud

Terraform provider for Dimension Data cloud compute.
MIT License
16 stars 13 forks source link

ports property in ddcloud_port_list resources cause the terraform to crash #71

Closed kumarappanc closed 7 years ago

kumarappanc commented 7 years ago

When applying the following resource terraform crashes

resource "ddcloud_port_list" "test_port_list1" {
       name = "test_port_list1"
       description = "test_port_list1"
       networkdomain = "${ddcloud_networkdomain.network_domain.id}"
       ports = [80]
}
Error:
Error applying plan:

1 error(s) occurred:
 interface conversion: interface is string, not int
* ddcloud_port_list.test_port_list1: unexpected EOF

When I use the port option instead of ports, it works.

tintoy commented 7 years ago

Hi.

It's a list of strings not a list of integers (try "80" instead of 80), so technically this behaviour is by design. This is because all other port values (e.g. in firewall rules) in our resources are specified as strings (mainly because in some places, any is a valid port).

Having said that, I understand that it could be confusing so I'm open to switching them to purely integers. Is that what you'd prefer? Either way, I'll update the documentation so that it's more explicit in describing the property data type.

CC: @mingsheng36 @wninobla

tintoy commented 7 years ago

Actually, looking at the documentation it already shows examples where they ports are integers. I'm just going to switch it over to being integers. This will be fixed in v1.2 but if you need to keep working for now, just wrap each port in quotes (e.g. "80" instead of 80) and you'll be good to go. Later when you upgrade to v1.2 you can simply remove the quotes and everything will keep working.

wninobla commented 7 years ago

I don't think we can use a port list here unless we explicitly keep each group of ports explicit. In the case of doing noncontinuous ports like in the simple example, you'd have to parse it out that way. May be easy to change on your end but I'm not the one coding. 😀. I am good so long as I know what it expects integer vs. a string.

wninobla commented 7 years ago

Ok you answered my question on the same note... Lol

kumarappanc commented 7 years ago

Even the string values doesn't work.

It looks like the problem is in the following function

func (helper resourcePropertyHelper) GetIntSetItems(key string) (items []int) { value, ok := helper.data.GetOk(key) if !ok || value == nil { return } rawItems := value.(*schema.Set).List()

items = make([]int, len(rawItems))
for index, item := range rawItems {
    items[index] = item.(int)
}

return

}

conversion item.(int) not working

tintoy commented 7 years ago

There are actually 2 ways to configure ports in a ddcloud_port_list:

  1. Simple (just a list of ports)
  2. Complex (port ranges, etc)
tintoy commented 7 years ago

@kumarappanc Ugh. Sorry, I'll have to fix that.

Give me 5 mins and I'll see if I can build a hotfixed version of 1.1.x.

tintoy commented 7 years ago

Ok @kumarappanc - can you give v1.1.10 a try?

tintoy commented 7 years ago

BTW, I've updated the acceptance tests for ddcloud_port_list - they work correctly now.

tintoy commented 7 years ago

Verified in alpha4.