github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go (about) 1 package openstack 2 3 import ( 4 "fmt" 5 "os" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/resource" 9 "github.com/hashicorp/terraform/terraform" 10 11 "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes" 12 "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip" 13 "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/secgroups" 14 "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach" 15 "github.com/rackspace/gophercloud/openstack/compute/v2/servers" 16 "github.com/rackspace/gophercloud/pagination" 17 ) 18 19 func TestAccComputeV2Instance_basic(t *testing.T) { 20 var instance servers.Server 21 var testAccComputeV2Instance_basic = fmt.Sprintf(` 22 resource "openstack_compute_instance_v2" "foo" { 23 name = "terraform-test" 24 security_groups = ["default"] 25 network { 26 uuid = "%s" 27 } 28 metadata { 29 foo = "bar" 30 } 31 }`, 32 os.Getenv("OS_NETWORK_ID")) 33 34 resource.Test(t, resource.TestCase{ 35 PreCheck: func() { testAccPreCheck(t) }, 36 Providers: testAccProviders, 37 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 38 Steps: []resource.TestStep{ 39 resource.TestStep{ 40 Config: testAccComputeV2Instance_basic, 41 Check: resource.ComposeTestCheckFunc( 42 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 43 testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"), 44 ), 45 }, 46 }, 47 }) 48 } 49 50 func TestAccComputeV2Instance_volumeAttach(t *testing.T) { 51 var instance servers.Server 52 var volume volumes.Volume 53 54 var testAccComputeV2Instance_volumeAttach = fmt.Sprintf(` 55 resource "openstack_blockstorage_volume_v1" "myvol" { 56 name = "myvol" 57 size = 1 58 } 59 60 resource "openstack_compute_instance_v2" "foo" { 61 name = "terraform-test" 62 security_groups = ["default"] 63 volume { 64 volume_id = "${openstack_blockstorage_volume_v1.myvol.id}" 65 } 66 }`) 67 68 resource.Test(t, resource.TestCase{ 69 PreCheck: func() { testAccPreCheck(t) }, 70 Providers: testAccProviders, 71 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 72 Steps: []resource.TestStep{ 73 resource.TestStep{ 74 Config: testAccComputeV2Instance_volumeAttach, 75 Check: resource.ComposeTestCheckFunc( 76 testAccCheckBlockStorageV1VolumeExists(t, "openstack_blockstorage_volume_v1.myvol", &volume), 77 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 78 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume), 79 ), 80 }, 81 }, 82 }) 83 } 84 85 func TestAccComputeV2Instance_volumeAttachPostCreation(t *testing.T) { 86 var instance servers.Server 87 var volume volumes.Volume 88 89 var testAccComputeV2Instance_volumeAttachPostCreationInstance = fmt.Sprintf(` 90 resource "openstack_compute_instance_v2" "foo" { 91 name = "terraform-test" 92 security_groups = ["default"] 93 }`) 94 95 var testAccComputeV2Instance_volumeAttachPostCreationInstanceAndVolume = fmt.Sprintf(` 96 resource "openstack_blockstorage_volume_v1" "myvol" { 97 name = "myvol" 98 size = 1 99 } 100 101 resource "openstack_compute_instance_v2" "foo" { 102 name = "terraform-test" 103 security_groups = ["default"] 104 volume { 105 volume_id = "${openstack_blockstorage_volume_v1.myvol.id}" 106 } 107 }`) 108 109 resource.Test(t, resource.TestCase{ 110 PreCheck: func() { testAccPreCheck(t) }, 111 Providers: testAccProviders, 112 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 113 Steps: []resource.TestStep{ 114 resource.TestStep{ 115 Config: testAccComputeV2Instance_volumeAttachPostCreationInstance, 116 Check: resource.ComposeTestCheckFunc( 117 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 118 ), 119 }, 120 resource.TestStep{ 121 Config: testAccComputeV2Instance_volumeAttachPostCreationInstanceAndVolume, 122 Check: resource.ComposeTestCheckFunc( 123 testAccCheckBlockStorageV1VolumeExists(t, "openstack_blockstorage_volume_v1.myvol", &volume), 124 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 125 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume), 126 ), 127 }, 128 }, 129 }) 130 } 131 132 func TestAccComputeV2Instance_volumeDetachPostCreation(t *testing.T) { 133 var instance servers.Server 134 var volume volumes.Volume 135 136 var testAccComputeV2Instance_volumeDetachPostCreationInstanceAndVolume = fmt.Sprintf(` 137 resource "openstack_blockstorage_volume_v1" "myvol" { 138 name = "myvol" 139 size = 1 140 } 141 142 resource "openstack_compute_instance_v2" "foo" { 143 name = "terraform-test" 144 security_groups = ["default"] 145 volume { 146 volume_id = "${openstack_blockstorage_volume_v1.myvol.id}" 147 } 148 }`) 149 150 var testAccComputeV2Instance_volumeDetachPostCreationInstance = fmt.Sprintf(` 151 resource "openstack_compute_instance_v2" "foo" { 152 name = "terraform-test" 153 security_groups = ["default"] 154 }`) 155 156 resource.Test(t, resource.TestCase{ 157 PreCheck: func() { testAccPreCheck(t) }, 158 Providers: testAccProviders, 159 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 160 Steps: []resource.TestStep{ 161 resource.TestStep{ 162 Config: testAccComputeV2Instance_volumeDetachPostCreationInstanceAndVolume, 163 Check: resource.ComposeTestCheckFunc( 164 testAccCheckBlockStorageV1VolumeExists(t, "openstack_blockstorage_volume_v1.myvol", &volume), 165 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 166 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume), 167 ), 168 }, 169 resource.TestStep{ 170 Config: testAccComputeV2Instance_volumeDetachPostCreationInstance, 171 Check: resource.ComposeTestCheckFunc( 172 testAccCheckBlockStorageV1VolumeDoesNotExist(t, "openstack_blockstorage_volume_v1.myvol", &volume), 173 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 174 testAccCheckComputeV2InstanceVolumesDetached(&instance), 175 ), 176 }, 177 }, 178 }) 179 } 180 181 func TestAccComputeV2Instance_floatingIPAttachGlobally(t *testing.T) { 182 var instance servers.Server 183 var fip floatingip.FloatingIP 184 var testAccComputeV2Instance_floatingIPAttachGlobally = fmt.Sprintf(` 185 resource "openstack_compute_floatingip_v2" "myip" { 186 } 187 188 resource "openstack_compute_instance_v2" "foo" { 189 name = "terraform-test" 190 security_groups = ["default"] 191 floating_ip = "${openstack_compute_floatingip_v2.myip.address}" 192 193 network { 194 uuid = "%s" 195 } 196 }`, 197 os.Getenv("OS_NETWORK_ID")) 198 199 resource.Test(t, resource.TestCase{ 200 PreCheck: func() { testAccPreCheck(t) }, 201 Providers: testAccProviders, 202 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 203 Steps: []resource.TestStep{ 204 resource.TestStep{ 205 Config: testAccComputeV2Instance_floatingIPAttachGlobally, 206 Check: resource.ComposeTestCheckFunc( 207 testAccCheckComputeV2FloatingIPExists(t, "openstack_compute_floatingip_v2.myip", &fip), 208 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 209 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 210 ), 211 }, 212 }, 213 }) 214 } 215 216 func TestAccComputeV2Instance_floatingIPAttachToNetwork(t *testing.T) { 217 var instance servers.Server 218 var fip floatingip.FloatingIP 219 var testAccComputeV2Instance_floatingIPAttachToNetwork = fmt.Sprintf(` 220 resource "openstack_compute_floatingip_v2" "myip" { 221 } 222 223 resource "openstack_compute_instance_v2" "foo" { 224 name = "terraform-test" 225 security_groups = ["default"] 226 227 network { 228 uuid = "%s" 229 floating_ip = "${openstack_compute_floatingip_v2.myip.address}" 230 access_network = true 231 } 232 }`, 233 os.Getenv("OS_NETWORK_ID")) 234 235 resource.Test(t, resource.TestCase{ 236 PreCheck: func() { testAccPreCheck(t) }, 237 Providers: testAccProviders, 238 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 239 Steps: []resource.TestStep{ 240 resource.TestStep{ 241 Config: testAccComputeV2Instance_floatingIPAttachToNetwork, 242 Check: resource.ComposeTestCheckFunc( 243 testAccCheckComputeV2FloatingIPExists(t, "openstack_compute_floatingip_v2.myip", &fip), 244 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 245 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 246 ), 247 }, 248 }, 249 }) 250 } 251 252 func TestAccComputeV2Instance_floatingIPAttachAndChange(t *testing.T) { 253 var instance servers.Server 254 var fip floatingip.FloatingIP 255 var testAccComputeV2Instance_floatingIPAttachToNetwork_1 = fmt.Sprintf(` 256 resource "openstack_compute_floatingip_v2" "myip_1" { 257 } 258 259 resource "openstack_compute_floatingip_v2" "myip_2" { 260 } 261 262 resource "openstack_compute_instance_v2" "foo" { 263 name = "terraform-test" 264 security_groups = ["default"] 265 266 network { 267 uuid = "%s" 268 floating_ip = "${openstack_compute_floatingip_v2.myip_1.address}" 269 access_network = true 270 } 271 }`, 272 os.Getenv("OS_NETWORK_ID")) 273 274 var testAccComputeV2Instance_floatingIPAttachToNetwork_2 = fmt.Sprintf(` 275 resource "openstack_compute_floatingip_v2" "myip_1" { 276 } 277 278 resource "openstack_compute_floatingip_v2" "myip_2" { 279 } 280 281 resource "openstack_compute_instance_v2" "foo" { 282 name = "terraform-test" 283 security_groups = ["default"] 284 285 network { 286 uuid = "%s" 287 floating_ip = "${openstack_compute_floatingip_v2.myip_2.address}" 288 access_network = true 289 } 290 }`, 291 os.Getenv("OS_NETWORK_ID")) 292 293 resource.Test(t, resource.TestCase{ 294 PreCheck: func() { testAccPreCheck(t) }, 295 Providers: testAccProviders, 296 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 297 Steps: []resource.TestStep{ 298 resource.TestStep{ 299 Config: testAccComputeV2Instance_floatingIPAttachToNetwork_1, 300 Check: resource.ComposeTestCheckFunc( 301 testAccCheckComputeV2FloatingIPExists(t, "openstack_compute_floatingip_v2.myip_1", &fip), 302 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 303 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 304 ), 305 }, 306 resource.TestStep{ 307 Config: testAccComputeV2Instance_floatingIPAttachToNetwork_2, 308 Check: resource.ComposeTestCheckFunc( 309 testAccCheckComputeV2FloatingIPExists(t, "openstack_compute_floatingip_v2.myip_2", &fip), 310 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 311 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 312 ), 313 }, 314 }, 315 }) 316 } 317 318 func TestAccComputeV2Instance_multi_secgroups(t *testing.T) { 319 var instance servers.Server 320 var secgroup secgroups.SecurityGroup 321 var testAccComputeV2Instance_multi_secgroups = fmt.Sprintf(` 322 resource "openstack_compute_secgroup_v2" "foo" { 323 name = "terraform-test" 324 description = "a security group" 325 rule { 326 from_port = 22 327 to_port = 22 328 ip_protocol = "tcp" 329 cidr = "0.0.0.0/0" 330 } 331 } 332 333 resource "openstack_compute_instance_v2" "foo" { 334 name = "terraform-test" 335 security_groups = ["default", "${openstack_compute_secgroup_v2.foo.name}"] 336 network { 337 uuid = "%s" 338 } 339 }`, 340 os.Getenv("OS_NETWORK_ID")) 341 342 resource.Test(t, resource.TestCase{ 343 PreCheck: func() { testAccPreCheck(t) }, 344 Providers: testAccProviders, 345 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 346 Steps: []resource.TestStep{ 347 resource.TestStep{ 348 Config: testAccComputeV2Instance_multi_secgroups, 349 Check: resource.ComposeTestCheckFunc( 350 testAccCheckComputeV2SecGroupExists(t, "openstack_compute_secgroup_v2.foo", &secgroup), 351 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 352 ), 353 }, 354 }, 355 }) 356 } 357 358 func TestAccComputeV2Instance_bootFromVolumeImage(t *testing.T) { 359 var instance servers.Server 360 var testAccComputeV2Instance_bootFromVolumeImage = fmt.Sprintf(` 361 resource "openstack_compute_instance_v2" "foo" { 362 name = "terraform-test" 363 security_groups = ["default"] 364 block_device { 365 uuid = "%s" 366 source_type = "image" 367 volume_size = 5 368 boot_index = 0 369 destination_type = "volume" 370 delete_on_termination = true 371 } 372 }`, 373 os.Getenv("OS_IMAGE_ID")) 374 375 resource.Test(t, resource.TestCase{ 376 PreCheck: func() { testAccPreCheck(t) }, 377 Providers: testAccProviders, 378 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 379 Steps: []resource.TestStep{ 380 resource.TestStep{ 381 Config: testAccComputeV2Instance_bootFromVolumeImage, 382 Check: resource.ComposeTestCheckFunc( 383 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 384 testAccCheckComputeV2InstanceBootVolumeAttachment(&instance), 385 ), 386 }, 387 }, 388 }) 389 } 390 391 func TestAccComputeV2Instance_bootFromVolumeVolume(t *testing.T) { 392 var instance servers.Server 393 var testAccComputeV2Instance_bootFromVolumeVolume = fmt.Sprintf(` 394 resource "openstack_blockstorage_volume_v1" "foo" { 395 name = "terraform-test" 396 size = 5 397 image_id = "%s" 398 } 399 400 resource "openstack_compute_instance_v2" "foo" { 401 name = "terraform-test" 402 security_groups = ["default"] 403 block_device { 404 uuid = "${openstack_blockstorage_volume_v1.foo.id}" 405 source_type = "volume" 406 boot_index = 0 407 destination_type = "volume" 408 delete_on_termination = true 409 } 410 }`, 411 os.Getenv("OS_IMAGE_ID")) 412 413 resource.Test(t, resource.TestCase{ 414 PreCheck: func() { testAccPreCheck(t) }, 415 Providers: testAccProviders, 416 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 417 Steps: []resource.TestStep{ 418 resource.TestStep{ 419 Config: testAccComputeV2Instance_bootFromVolumeVolume, 420 Check: resource.ComposeTestCheckFunc( 421 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 422 testAccCheckComputeV2InstanceBootVolumeAttachment(&instance), 423 ), 424 }, 425 }, 426 }) 427 } 428 429 // TODO: verify the personality really exists on the instance. 430 func TestAccComputeV2Instance_personality(t *testing.T) { 431 var instance servers.Server 432 var testAccComputeV2Instance_personality = fmt.Sprintf(` 433 resource "openstack_compute_instance_v2" "foo" { 434 name = "terraform-test" 435 security_groups = ["default"] 436 personality { 437 file = "/tmp/foobar.txt" 438 content = "happy" 439 } 440 personality { 441 file = "/tmp/barfoo.txt" 442 content = "angry" 443 } 444 }`) 445 446 resource.Test(t, resource.TestCase{ 447 PreCheck: func() { testAccPreCheck(t) }, 448 Providers: testAccProviders, 449 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 450 Steps: []resource.TestStep{ 451 resource.TestStep{ 452 Config: testAccComputeV2Instance_personality, 453 Check: resource.ComposeTestCheckFunc( 454 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 455 ), 456 }, 457 }, 458 }) 459 } 460 461 func TestAccComputeV2Instance_multiEphemeral(t *testing.T) { 462 var instance servers.Server 463 var testAccComputeV2Instance_multiEphemeral = fmt.Sprintf(` 464 resource "openstack_compute_instance_v2" "foo" { 465 name = "terraform-test" 466 security_groups = ["default"] 467 block_device { 468 boot_index = 0 469 delete_on_termination = true 470 destination_type = "local" 471 source_type = "image" 472 uuid = "%s" 473 } 474 block_device { 475 boot_index = -1 476 delete_on_termination = true 477 destination_type = "local" 478 source_type = "blank" 479 volume_size = 1 480 } 481 block_device { 482 boot_index = -1 483 delete_on_termination = true 484 destination_type = "local" 485 source_type = "blank" 486 volume_size = 1 487 } 488 }`, 489 os.Getenv("OS_IMAGE_ID")) 490 491 resource.Test(t, resource.TestCase{ 492 PreCheck: func() { testAccPreCheck(t) }, 493 Providers: testAccProviders, 494 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 495 Steps: []resource.TestStep{ 496 resource.TestStep{ 497 Config: testAccComputeV2Instance_multiEphemeral, 498 Check: resource.ComposeTestCheckFunc( 499 testAccCheckComputeV2InstanceExists(t, "openstack_compute_instance_v2.foo", &instance), 500 ), 501 }, 502 }, 503 }) 504 } 505 506 func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error { 507 config := testAccProvider.Meta().(*Config) 508 computeClient, err := config.computeV2Client(OS_REGION_NAME) 509 if err != nil { 510 return fmt.Errorf("(testAccCheckComputeV2InstanceDestroy) Error creating OpenStack compute client: %s", err) 511 } 512 513 for _, rs := range s.RootModule().Resources { 514 if rs.Type != "openstack_compute_instance_v2" { 515 continue 516 } 517 518 _, err := servers.Get(computeClient, rs.Primary.ID).Extract() 519 if err == nil { 520 return fmt.Errorf("Instance still exists") 521 } 522 } 523 524 return nil 525 } 526 527 func testAccCheckComputeV2InstanceExists(t *testing.T, n string, instance *servers.Server) resource.TestCheckFunc { 528 return func(s *terraform.State) error { 529 rs, ok := s.RootModule().Resources[n] 530 if !ok { 531 return fmt.Errorf("Not found: %s", n) 532 } 533 534 if rs.Primary.ID == "" { 535 return fmt.Errorf("No ID is set") 536 } 537 538 config := testAccProvider.Meta().(*Config) 539 computeClient, err := config.computeV2Client(OS_REGION_NAME) 540 if err != nil { 541 return fmt.Errorf("(testAccCheckComputeV2InstanceExists) Error creating OpenStack compute client: %s", err) 542 } 543 544 found, err := servers.Get(computeClient, rs.Primary.ID).Extract() 545 if err != nil { 546 return err 547 } 548 549 if found.ID != rs.Primary.ID { 550 return fmt.Errorf("Instance not found") 551 } 552 553 *instance = *found 554 555 return nil 556 } 557 } 558 559 func testAccCheckComputeV2InstanceMetadata( 560 instance *servers.Server, k string, v string) resource.TestCheckFunc { 561 return func(s *terraform.State) error { 562 if instance.Metadata == nil { 563 return fmt.Errorf("No metadata") 564 } 565 566 for key, value := range instance.Metadata { 567 if k != key { 568 continue 569 } 570 571 if v == value.(string) { 572 return nil 573 } 574 575 return fmt.Errorf("Bad value for %s: %s", k, value) 576 } 577 578 return fmt.Errorf("Metadata not found: %s", k) 579 } 580 } 581 582 func testAccCheckComputeV2InstanceVolumeAttachment( 583 instance *servers.Server, volume *volumes.Volume) resource.TestCheckFunc { 584 return func(s *terraform.State) error { 585 var attachments []volumeattach.VolumeAttachment 586 587 config := testAccProvider.Meta().(*Config) 588 computeClient, err := config.computeV2Client(OS_REGION_NAME) 589 if err != nil { 590 return err 591 } 592 err = volumeattach.List(computeClient, instance.ID).EachPage(func(page pagination.Page) (bool, error) { 593 actual, err := volumeattach.ExtractVolumeAttachments(page) 594 if err != nil { 595 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 596 } 597 598 attachments = actual 599 return true, nil 600 }) 601 602 for _, attachment := range attachments { 603 if attachment.VolumeID == volume.ID { 604 return nil 605 } 606 } 607 608 return fmt.Errorf("Volume not found: %s", volume.ID) 609 } 610 } 611 612 func testAccCheckComputeV2InstanceVolumesDetached(instance *servers.Server) resource.TestCheckFunc { 613 return func(s *terraform.State) error { 614 var attachments []volumeattach.VolumeAttachment 615 616 config := testAccProvider.Meta().(*Config) 617 computeClient, err := config.computeV2Client(OS_REGION_NAME) 618 if err != nil { 619 return err 620 } 621 err = volumeattach.List(computeClient, instance.ID).EachPage(func(page pagination.Page) (bool, error) { 622 actual, err := volumeattach.ExtractVolumeAttachments(page) 623 if err != nil { 624 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 625 } 626 627 attachments = actual 628 return true, nil 629 }) 630 631 if len(attachments) > 0 { 632 return fmt.Errorf("Volumes are still attached.") 633 } 634 635 return nil 636 } 637 } 638 639 func testAccCheckComputeV2InstanceBootVolumeAttachment( 640 instance *servers.Server) resource.TestCheckFunc { 641 return func(s *terraform.State) error { 642 var attachments []volumeattach.VolumeAttachment 643 644 config := testAccProvider.Meta().(*Config) 645 computeClient, err := config.computeV2Client(OS_REGION_NAME) 646 if err != nil { 647 return err 648 } 649 err = volumeattach.List(computeClient, instance.ID).EachPage(func(page pagination.Page) (bool, error) { 650 actual, err := volumeattach.ExtractVolumeAttachments(page) 651 if err != nil { 652 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 653 } 654 655 attachments = actual 656 return true, nil 657 }) 658 659 if len(attachments) == 1 { 660 return nil 661 } 662 663 return fmt.Errorf("No attached volume found.") 664 } 665 } 666 667 func testAccCheckComputeV2InstanceFloatingIPAttach( 668 instance *servers.Server, fip *floatingip.FloatingIP) resource.TestCheckFunc { 669 return func(s *terraform.State) error { 670 if fip.InstanceID == instance.ID { 671 return nil 672 } 673 674 return fmt.Errorf("Floating IP %s was not attached to instance %s", fip.ID, instance.ID) 675 676 } 677 }