jtopjian / terraform-provider-openstack-old

OpenStack Provider for Terraform using gophercloud
12 stars 4 forks source link

Broken network code #2

Closed teancom closed 9 years ago

teancom commented 9 years ago

Let me start by saying 1) it looks like you're kicking butt and taking names and 2) please don't view this bug report as me complaining. I have absolutely read the README and understand this isn't beta (or even alpha) quality. Just trying to help you keep track of possible breakage as you move forward. Now that that's out of the way:

Commit ddeabee broke the ability to specify a network, which is required when you have more than one. This is still broken with ac390b7.

Using:

provider "openstack" {}

resource "openstack_compute" "test" {
  name = "test"
  image_id = "cb33496b-a6b5-4e1f-9eab-93b0cd462a91"
  flavor_name = "m1.small"
  key_name = "dbishop-test"
  networks = [ "c9b60cf1-6268-4388-976c-87a77ad6db0c" ]
}

I now get back:

$ TF_LOG=1 terraform apply
2015/01/31 16:10:42 [INFO] Terraform version: 0.3.6 dev 3b5c8a44ea569b70e15ce5f4fdeee4f717b2f3f2+CHANGES
2015/01/31 16:10:42 Detected home directory from env var: /Users/dbishop
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: atlas = /usr/local/bin/terraform-provider-atlas
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: aws = /usr/local/bin/terraform-provider-aws
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: cloudflare = /usr/local/bin/terraform-provider-cloudflare
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: cloudstack = /usr/local/bin/terraform-provider-cloudstack
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: consul = /usr/local/bin/terraform-provider-consul
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: digitalocean = /usr/local/bin/terraform-provider-digitalocean
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: dnsimple = /usr/local/bin/terraform-provider-dnsimple
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: google = /usr/local/bin/terraform-provider-google
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: heroku = /usr/local/bin/terraform-provider-heroku
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: mailgun = /usr/local/bin/terraform-provider-mailgun
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: null = /usr/local/bin/terraform-provider-null
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: openstack = /usr/local/bin/terraform-provider-openstack
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: file = /usr/local/bin/terraform-provisioner-file
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: local-exec = /usr/local/bin/terraform-provisioner-local-exec
2015/01/31 16:10:42 [DEBUG] Discoverd plugin: remote-exec = /usr/local/bin/terraform-provisioner-remote-exec
2015/01/31 16:10:42 Detected home directory from env var: /Users/dbishop
2015/01/31 16:10:42 [DEBUG] Attempting to open CLI config file: /Users/dbishop/.terraformrc
2015/01/31 16:10:42 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2015/01/31 16:10:42 [DEBUG] Creating graph for path: [root]
2015/01/31 16:10:42 [DEBUG] Starting plugin: /usr/local/bin/terraform-provider-openstack []string{"/usr/local/bin/terraform-provider-openstack"}
2015/01/31 16:10:42 [DEBUG] Waiting for RPC address for: /usr/local/bin/terraform-provider-openstack
2015/01/31 16:10:42 Detected home directory from env var: /Users/dbishop
2015/01/31 16:10:42 terraform-provider-openstack: 2015/01/31 16:10:42 Plugin address: unix /var/folders/jv/k0f64c6x1qz1zt9st9c5235c0000gn/T/tf-plugin185952609
2015/01/31 16:10:42 [DEBUG] Graph [root] created and valid. 3 nouns.
2015/01/31 16:10:42 [INFO] Validating provider: openstack
2015/01/31 16:10:42 [DEBUG] openstack_compute.test: expanding to count = 1
2015/01/31 16:10:42 [INFO] Validating resource: openstack_compute.test
2015/01/31 16:10:42 [DEBUG] Creating graph for path: [root]
2015/01/31 16:10:42 [DEBUG] Graph [root] created and valid. 3 nouns.
2015/01/31 16:10:42 [DEBUG] Creating graph for path: [root]
2015/01/31 16:10:42 [DEBUG] Graph [root] created and valid. 3 nouns.
2015/01/31 16:10:42 [INFO] Configuring provider: openstack
2015/01/31 16:10:43 terraform-provider-openstack: 2015/01/31 16:10:43 [INFO] Openstack Client configured for user dbishop
2015/01/31 16:10:43 [DEBUG] openstack_compute.test: expanding to count = 1
2015/01/31 16:10:43 [INFO] Module root walking: openstack_compute.test (Graph node: openstack_compute.test)
2015/01/31 16:10:43 [DEBUG] openstack_compute.test: Not refreshing, ID is empty
2015/01/31 16:10:43 [DEBUG] Creating graph for path: [root]
2015/01/31 16:10:43 [DEBUG] Graph [root] created and valid. 3 nouns.
2015/01/31 16:10:43 [INFO] Configuring provider: openstack
2015/01/31 16:10:43 terraform-provider-openstack: 2015/01/31 16:10:43 [INFO] Openstack Client configured for user dbishop
2015/01/31 16:10:43 [DEBUG] openstack_compute.test: expanding to count = 1
2015/01/31 16:10:43 [INFO] Module root walking: openstack_compute.test (Graph node: openstack_compute.test)
2015/01/31 16:10:43 [DEBUG] openstack_compute.test: Executing diff
2015/01/31 16:10:43 [DEBUG] openstack_compute.test: Diff: &terraform.InstanceDiff{Attributes:map[string]*terraform.ResourceAttrDiff{"flavor_name":*terraform.ResourceAttrDiff{Old:"", New:"m1.small", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "networks.#":*terraform.ResourceAttrDiff{Old:"", New:"1", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "created":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "flavor_id":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network_provider":*terraform.ResourceAttrDiff{Old:"", New:"neutron", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "networks.469603591":*terraform.ResourceAttrDiff{Old:"", New:"c9b60cf1-6268-4388-976c-87a77ad6db0c", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "image_name":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "key_name":*terraform.ResourceAttrDiff{Old:"", New:"dbishop-test", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "id":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x2}, "metadata.#":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network.#":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "floating_ip":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "network_info.#":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "name":*terraform.ResourceAttrDiff{Old:"", New:"test", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}, "image_id":*terraform.ResourceAttrDiff{Old:"", New:"cb33496b-a6b5-4e1f-9eab-93b0cd462a91", NewComputed:false, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:true, Type:0x0}, "updated":*terraform.ResourceAttrDiff{Old:"", New:"", NewComputed:true, NewRemoved:false, NewExtra:interface {}(nil), RequiresNew:false, Type:0x0}}, Destroy:false, DestroyTainted:false}
2015/01/31 16:10:43 [INFO] Apply walk starting
2015/01/31 16:10:43 [DEBUG] Creating graph for path: [root]
2015/01/31 16:10:43 [DEBUG] Graph [root] created and valid. 3 nouns.
2015/01/31 16:10:43 [INFO] Configuring provider: openstack
2015/01/31 16:10:43 terraform-provider-openstack: 2015/01/31 16:10:43 [INFO] Openstack Client configured for user dbishop
2015/01/31 16:10:43 [DEBUG] openstack_compute.test: expanding to count = 1
2015/01/31 16:10:43 [INFO] Module root walking: openstack_compute.test (Graph node: openstack_compute.test)
2015/01/31 16:10:43 [DEBUG] openstack_compute.test: Executing Apply
openstack_compute.test: Creating...
  created:            "" => "<computed>"
  flavor_id:          "" => "<computed>"
  flavor_name:        "" => "m1.small"
  floating_ip:        "" => "<computed>"
  image_id:           "" => "cb33496b-a6b5-4e1f-9eab-93b0cd462a91"
  image_name:         "" => "<computed>"
2015/01/31 16:10:43 terraform-provider-openstack: 2015/01/31 16:10:43 network: &{0x4bd30 map[] {{0 0} 0}}
  key_name:           "" => "dbishop-test"
  metadata.#:         "" => "<computed>"
  name:               "" => "test"
  network.#:          "" => "<computed>"
  network_info.#:     "" => "<computed>"
  network_provider:   "" => "neutron"
  networks.#:         "" => "1"
  networks.469603591: "" => "c9b60cf1-6268-4388-976c-87a77ad6db0c"
  updated:            "" => "<computed>"
2015/01/31 16:10:44 [ERROR] Error walking 'openstack_compute.test': 1 error(s) occurred:

* Expected HTTP response code [202] when accessing URL(http://10.2.95.100:8774/v2/034121797c1a4b6aa4129aaca3498e31/servers); got 400 instead with the following body:
{"badRequest": {"message": "Multiple possible networks found, use a Network ID to be more specific.", "code": 400}}
2015/01/31 16:10:44 [INFO] Apply walk complete
2015/01/31 16:10:44 [INFO] Writing backup state to: terraform.tfstate.backup
2015/01/31 16:10:44 waiting for all plugin processes to complete...
openstack_compute.test: Error: Expected HTTP response code [202] when accessing URL(http://10.2.95.100:8774/v2/034121797c1a4b6aa4129aaca3498e31/servers); got 400 instead with the following body:
{"badRequest": {"message": "Multiple possible networks found, use a Network ID to be more specific.", "code": 400}}
Error applying plan:

1 error(s) occurred:

* Expected HTTP response code [202] when accessing URL(http://10.2.95.100:8774/v2/034121797c1a4b6aa4129aaca3498e31/servers); got 400 instead with the following body:
{"badRequest": {"message": "Multiple possible networks found, use a Network ID to be more specific.", "code": 400}}

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
2015/01/31 16:10:44 [DEBUG] /usr/local/bin/terraform-provider-openstack: plugin process exited

instead of:

$ terraform apply
openstack_compute.test: Creating...
  created:            "" => "<computed>"
  flavor_id:          "" => "<computed>"
  flavor_name:        "" => "m1.small"
  floating_ip:        "" => "<computed>"
  image_id:           "" => "cb33496b-a6b5-4e1f-9eab-93b0cd462a91"
  image_name:         "" => "<computed>"
  key_name:           "" => "dbishop-test"
  metadata.#:         "" => "<computed>"
  name:               "" => "test"
  networks.#:         "" => "1"
  networks.469603591: "" => "c9b60cf1-6268-4388-976c-87a77ad6db0c"
  updated:            "" => "<computed>"
openstack_compute.test: Creation complete

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

The state of your infrastructure has been saved to the path
below. This state is required to modify and destroy your
infrastructure, so keep it safe. To inspect the complete state
use the `terraform show` command.

State path: terraform.tfstate
jtopjian commented 9 years ago

No offence taken at all. Thanks for the heads up -- I'll look into it shortly and get it resolved.

I really need to sit down and understand how the unit tests work from the other providers.

jtopjian commented 9 years ago

OK, the latest commit should fix this issue. I believe the logic in the network/networks conditional was incorrect and so the else portion was never being hit.

Let me know if this works for you now. Sorry about that!

jtopjian commented 9 years ago

Oh, and just to clarify:

Commit ddeabee broke the ability to specify a network, which is required when you have more than one.

The network block should be able to be specified multiple times. I haven't actually verified that, but that's the intention. I have access to a multi-network Neutron-based OpenStack environment that I'll be verifying this against within the next day or so.

I've updated the README to clarify how network can be used.

teancom commented 9 years ago

Works like a champ. Fixed in f2b17c8. And yeah, I was going to look into unit tests myself. I'm no go programmer, but maybe I can help out with some sort of testing.

jtopjian commented 9 years ago

Awesome! Thanks again for the heads up. Please let me know of any more issues you run into.

At the moment, I'm stuck trying to figure out Floating IPs for nova-network. Floating IPs for Neutron should be easy enough as that support is now in gophercloud. I might end up writing a quick openstack_keypair resource or similar to take my mind off it.