github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/openstack/resource_openstack_compute_instance_v2_test.go (about) 1 package openstack 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 "github.com/hashicorp/terraform/terraform" 9 10 "github.com/gophercloud/gophercloud" 11 "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes" 12 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips" 13 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/secgroups" 14 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach" 15 "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" 16 "github.com/gophercloud/gophercloud/pagination" 17 ) 18 19 func TestAccComputeV2Instance_basic(t *testing.T) { 20 var instance servers.Server 21 22 resource.Test(t, resource.TestCase{ 23 PreCheck: func() { testAccPreCheck(t) }, 24 Providers: testAccProviders, 25 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 26 Steps: []resource.TestStep{ 27 resource.TestStep{ 28 Config: testAccComputeV2Instance_basic, 29 Check: resource.ComposeTestCheckFunc( 30 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 31 testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"), 32 ), 33 }, 34 }, 35 }) 36 } 37 38 func TestAccComputeV2Instance_volumeAttach(t *testing.T) { 39 var instance servers.Server 40 var volume volumes.Volume 41 42 resource.Test(t, resource.TestCase{ 43 PreCheck: func() { testAccPreCheck(t) }, 44 Providers: testAccProviders, 45 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 46 Steps: []resource.TestStep{ 47 resource.TestStep{ 48 Config: testAccComputeV2Instance_volumeAttach, 49 Check: resource.ComposeTestCheckFunc( 50 testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume), 51 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 52 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume), 53 ), 54 }, 55 }, 56 }) 57 } 58 59 func TestAccComputeV2Instance_volumeAttachPostCreation(t *testing.T) { 60 var instance servers.Server 61 var volume volumes.Volume 62 63 resource.Test(t, resource.TestCase{ 64 PreCheck: func() { testAccPreCheck(t) }, 65 Providers: testAccProviders, 66 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 67 Steps: []resource.TestStep{ 68 resource.TestStep{ 69 Config: testAccComputeV2Instance_volumeAttachPostCreation_1, 70 Check: resource.ComposeTestCheckFunc( 71 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 72 ), 73 }, 74 resource.TestStep{ 75 Config: testAccComputeV2Instance_volumeAttachPostCreation_2, 76 Check: resource.ComposeTestCheckFunc( 77 testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume), 78 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 79 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume), 80 ), 81 }, 82 }, 83 }) 84 } 85 86 func TestAccComputeV2Instance_volumeDetachPostCreation(t *testing.T) { 87 var instance servers.Server 88 var volume volumes.Volume 89 90 resource.Test(t, resource.TestCase{ 91 PreCheck: func() { testAccPreCheck(t) }, 92 Providers: testAccProviders, 93 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 94 Steps: []resource.TestStep{ 95 resource.TestStep{ 96 Config: testAccComputeV2Instance_volumeDetachPostCreation_1, 97 Check: resource.ComposeTestCheckFunc( 98 testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume), 99 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 100 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume), 101 ), 102 }, 103 resource.TestStep{ 104 Config: testAccComputeV2Instance_volumeDetachPostCreation_2, 105 Check: resource.ComposeTestCheckFunc( 106 testAccCheckBlockStorageV1VolumeExists("openstack_blockstorage_volume_v1.vol_1", &volume), 107 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 108 testAccCheckComputeV2InstanceVolumesDetached(&instance), 109 ), 110 }, 111 }, 112 }) 113 } 114 115 func TestAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation(t *testing.T) { 116 var instance servers.Server 117 var volume_1 volumes.Volume 118 var volume_2 volumes.Volume 119 120 resource.Test(t, resource.TestCase{ 121 PreCheck: func() { testAccPreCheck(t) }, 122 Providers: testAccProviders, 123 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 124 Steps: []resource.TestStep{ 125 resource.TestStep{ 126 Config: testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_1, 127 Check: resource.ComposeTestCheckFunc( 128 testAccCheckBlockStorageV1VolumeExists( 129 "openstack_blockstorage_volume_v1.root_volume", &volume_1), 130 testAccCheckBlockStorageV1VolumeExists( 131 "openstack_blockstorage_volume_v1.additional_volume", &volume_2), 132 testAccCheckComputeV2InstanceExists( 133 "openstack_compute_instance_v2.instance_1", &instance), 134 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_1), 135 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_2), 136 ), 137 }, 138 resource.TestStep{ 139 Config: testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_2, 140 Check: resource.ComposeTestCheckFunc( 141 testAccCheckBlockStorageV1VolumeExists( 142 "openstack_blockstorage_volume_v1.root_volume", &volume_1), 143 testAccCheckBlockStorageV1VolumeExists( 144 "openstack_blockstorage_volume_v1.additional_volume", &volume_2), 145 testAccCheckComputeV2InstanceExists( 146 "openstack_compute_instance_v2.instance_1", &instance), 147 testAccCheckComputeV2InstanceVolumeDetached( 148 &instance, "openstack_blockstorage_volume_v1.additional_volume"), 149 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_1), 150 ), 151 }, 152 }, 153 }) 154 } 155 156 func TestAccComputeV2Instance_volumeAttachInstanceDelete(t *testing.T) { 157 var instance servers.Server 158 var volume_1 volumes.Volume 159 var volume_2 volumes.Volume 160 161 resource.Test(t, resource.TestCase{ 162 PreCheck: func() { testAccPreCheck(t) }, 163 Providers: testAccProviders, 164 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 165 Steps: []resource.TestStep{ 166 resource.TestStep{ 167 Config: testAccComputeV2Instance_volumeAttachInstanceDelete_1, 168 Check: resource.ComposeTestCheckFunc( 169 testAccCheckBlockStorageV1VolumeExists( 170 "openstack_blockstorage_volume_v1.root_volume", &volume_1), 171 testAccCheckBlockStorageV1VolumeExists( 172 "openstack_blockstorage_volume_v1.additional_volume", &volume_2), 173 testAccCheckComputeV2InstanceExists( 174 "openstack_compute_instance_v2.instance_1", &instance), 175 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_1), 176 testAccCheckComputeV2InstanceVolumeAttachment(&instance, &volume_2), 177 ), 178 }, 179 resource.TestStep{ 180 Config: testAccComputeV2Instance_volumeAttachInstanceDelete_2, 181 Check: resource.ComposeTestCheckFunc( 182 testAccCheckBlockStorageV1VolumeExists( 183 "openstack_blockstorage_volume_v1.root_volume", &volume_1), 184 testAccCheckBlockStorageV1VolumeExists( 185 "openstack_blockstorage_volume_v1.additional_volume", &volume_2), 186 testAccCheckComputeV2InstanceDoesNotExist( 187 "openstack_compute_instance_v2.instance_1", &instance), 188 testAccCheckComputeV2InstanceVolumeDetached( 189 &instance, "openstack_blockstorage_volume_v1.root_volume"), 190 testAccCheckComputeV2InstanceVolumeDetached( 191 &instance, "openstack_blockstorage_volume_v1.additional_volume"), 192 ), 193 }, 194 }, 195 }) 196 } 197 198 func TestAccComputeV2Instance_volumeAttachToNewInstance(t *testing.T) { 199 var instance_1 servers.Server 200 var instance_2 servers.Server 201 var volume_1 volumes.Volume 202 203 resource.Test(t, resource.TestCase{ 204 PreCheck: func() { testAccPreCheck(t) }, 205 Providers: testAccProviders, 206 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 207 Steps: []resource.TestStep{ 208 resource.TestStep{ 209 Config: testAccComputeV2Instance_volumeAttachToNewInstance_1, 210 Check: resource.ComposeTestCheckFunc( 211 testAccCheckBlockStorageV1VolumeExists( 212 "openstack_blockstorage_volume_v1.volume_1", &volume_1), 213 testAccCheckComputeV2InstanceExists( 214 "openstack_compute_instance_v2.instance_1", &instance_1), 215 testAccCheckComputeV2InstanceExists( 216 "openstack_compute_instance_v2.instance_2", &instance_2), 217 testAccCheckComputeV2InstanceVolumeDetached( 218 &instance_2, "openstack_blockstorage_volume_v1.volume_1"), 219 testAccCheckComputeV2InstanceVolumeAttachment(&instance_1, &volume_1), 220 ), 221 }, 222 resource.TestStep{ 223 Config: testAccComputeV2Instance_volumeAttachToNewInstance_2, 224 Check: resource.ComposeTestCheckFunc( 225 testAccCheckBlockStorageV1VolumeExists( 226 "openstack_blockstorage_volume_v1.volume_1", &volume_1), 227 testAccCheckComputeV2InstanceExists( 228 "openstack_compute_instance_v2.instance_1", &instance_1), 229 testAccCheckComputeV2InstanceExists( 230 "openstack_compute_instance_v2.instance_2", &instance_2), 231 testAccCheckComputeV2InstanceVolumeDetached( 232 &instance_1, "openstack_blockstorage_volume_v1.volume_1"), 233 testAccCheckComputeV2InstanceVolumeAttachment(&instance_2, &volume_1), 234 ), 235 }, 236 }, 237 }) 238 } 239 240 func TestAccComputeV2Instance_floatingIPAttachGlobally(t *testing.T) { 241 var instance servers.Server 242 var fip floatingips.FloatingIP 243 244 resource.Test(t, resource.TestCase{ 245 PreCheck: func() { testAccPreCheck(t) }, 246 Providers: testAccProviders, 247 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 248 Steps: []resource.TestStep{ 249 resource.TestStep{ 250 Config: testAccComputeV2Instance_floatingIPAttachGlobally, 251 Check: resource.ComposeTestCheckFunc( 252 testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_1", &fip), 253 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 254 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 255 ), 256 }, 257 }, 258 }) 259 } 260 261 func TestAccComputeV2Instance_floatingIPAttachToNetwork(t *testing.T) { 262 var instance servers.Server 263 var fip floatingips.FloatingIP 264 265 resource.Test(t, resource.TestCase{ 266 PreCheck: func() { testAccPreCheck(t) }, 267 Providers: testAccProviders, 268 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 269 Steps: []resource.TestStep{ 270 resource.TestStep{ 271 Config: testAccComputeV2Instance_floatingIPAttachToNetwork, 272 Check: resource.ComposeTestCheckFunc( 273 testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_1", &fip), 274 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 275 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 276 ), 277 }, 278 }, 279 }) 280 } 281 282 func TestAccComputeV2Instance_floatingIPAttachToNetworkAndChange(t *testing.T) { 283 var instance servers.Server 284 var fip floatingips.FloatingIP 285 286 resource.Test(t, resource.TestCase{ 287 PreCheck: func() { testAccPreCheck(t) }, 288 Providers: testAccProviders, 289 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 290 Steps: []resource.TestStep{ 291 resource.TestStep{ 292 Config: testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_1, 293 Check: resource.ComposeTestCheckFunc( 294 testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_1", &fip), 295 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 296 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 297 ), 298 }, 299 resource.TestStep{ 300 Config: testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_2, 301 Check: resource.ComposeTestCheckFunc( 302 testAccCheckComputeV2FloatingIPExists("openstack_compute_floatingip_v2.fip_2", &fip), 303 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 304 testAccCheckComputeV2InstanceFloatingIPAttach(&instance, &fip), 305 ), 306 }, 307 }, 308 }) 309 } 310 311 func TestAccComputeV2Instance_secgroupMulti(t *testing.T) { 312 var instance_1 servers.Server 313 var secgroup_1 secgroups.SecurityGroup 314 315 resource.Test(t, resource.TestCase{ 316 PreCheck: func() { testAccPreCheck(t) }, 317 Providers: testAccProviders, 318 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 319 Steps: []resource.TestStep{ 320 resource.TestStep{ 321 Config: testAccComputeV2Instance_secgroupMulti, 322 Check: resource.ComposeTestCheckFunc( 323 testAccCheckComputeV2SecGroupExists( 324 "openstack_compute_secgroup_v2.secgroup_1", &secgroup_1), 325 testAccCheckComputeV2InstanceExists( 326 "openstack_compute_instance_v2.instance_1", &instance_1), 327 ), 328 }, 329 }, 330 }) 331 } 332 333 func TestAccComputeV2Instance_secgroupMultiUpdate(t *testing.T) { 334 var instance_1 servers.Server 335 var secgroup_1, secgroup_2 secgroups.SecurityGroup 336 337 resource.Test(t, resource.TestCase{ 338 PreCheck: func() { testAccPreCheck(t) }, 339 Providers: testAccProviders, 340 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 341 Steps: []resource.TestStep{ 342 resource.TestStep{ 343 Config: testAccComputeV2Instance_secgroupMultiUpdate_1, 344 Check: resource.ComposeTestCheckFunc( 345 testAccCheckComputeV2SecGroupExists( 346 "openstack_compute_secgroup_v2.secgroup_1", &secgroup_1), 347 testAccCheckComputeV2SecGroupExists( 348 "openstack_compute_secgroup_v2.secgroup_2", &secgroup_2), 349 testAccCheckComputeV2InstanceExists( 350 "openstack_compute_instance_v2.instance_1", &instance_1), 351 ), 352 }, 353 resource.TestStep{ 354 Config: testAccComputeV2Instance_secgroupMultiUpdate_2, 355 Check: resource.ComposeTestCheckFunc( 356 testAccCheckComputeV2SecGroupExists( 357 "openstack_compute_secgroup_v2.secgroup_1", &secgroup_1), 358 testAccCheckComputeV2SecGroupExists( 359 "openstack_compute_secgroup_v2.secgroup_2", &secgroup_2), 360 testAccCheckComputeV2InstanceExists( 361 "openstack_compute_instance_v2.instance_1", &instance_1), 362 ), 363 }, 364 }, 365 }) 366 } 367 368 func TestAccComputeV2Instance_bootFromVolumeImage(t *testing.T) { 369 var instance servers.Server 370 371 resource.Test(t, resource.TestCase{ 372 PreCheck: func() { testAccPreCheck(t) }, 373 Providers: testAccProviders, 374 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 375 Steps: []resource.TestStep{ 376 resource.TestStep{ 377 Config: testAccComputeV2Instance_bootFromVolumeImage, 378 Check: resource.ComposeTestCheckFunc( 379 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 380 testAccCheckComputeV2InstanceBootVolumeAttachment(&instance), 381 ), 382 }, 383 }, 384 }) 385 } 386 387 func TestAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume(t *testing.T) { 388 var instance servers.Server 389 390 resource.Test(t, resource.TestCase{ 391 PreCheck: func() { testAccPreCheck(t) }, 392 Providers: testAccProviders, 393 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 394 Steps: []resource.TestStep{ 395 resource.TestStep{ 396 Config: testAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume, 397 Check: resource.ComposeTestCheckFunc( 398 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 399 ), 400 }, 401 }, 402 }) 403 } 404 405 func TestAccComputeV2Instance_bootFromVolumeVolume(t *testing.T) { 406 var instance servers.Server 407 408 resource.Test(t, resource.TestCase{ 409 PreCheck: func() { testAccPreCheck(t) }, 410 Providers: testAccProviders, 411 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 412 Steps: []resource.TestStep{ 413 resource.TestStep{ 414 Config: testAccComputeV2Instance_bootFromVolumeVolume, 415 Check: resource.ComposeTestCheckFunc( 416 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 417 testAccCheckComputeV2InstanceBootVolumeAttachment(&instance), 418 ), 419 }, 420 }, 421 }) 422 } 423 424 func TestAccComputeV2Instance_bootFromVolumeForceNew(t *testing.T) { 425 var instance1_1 servers.Server 426 var instance1_2 servers.Server 427 428 resource.Test(t, resource.TestCase{ 429 PreCheck: func() { testAccPreCheck(t) }, 430 Providers: testAccProviders, 431 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 432 Steps: []resource.TestStep{ 433 resource.TestStep{ 434 Config: testAccComputeV2Instance_bootFromVolumeForceNew_1, 435 Check: resource.ComposeTestCheckFunc( 436 testAccCheckComputeV2InstanceExists( 437 "openstack_compute_instance_v2.instance_1", &instance1_1), 438 ), 439 }, 440 resource.TestStep{ 441 Config: testAccComputeV2Instance_bootFromVolumeForceNew_2, 442 Check: resource.ComposeTestCheckFunc( 443 testAccCheckComputeV2InstanceExists( 444 "openstack_compute_instance_v2.instance_1", &instance1_2), 445 testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(&instance1_1, &instance1_2), 446 ), 447 }, 448 }, 449 }) 450 } 451 452 func TestAccComputeV2Instance_blockDeviceNewVolume(t *testing.T) { 453 var instance servers.Server 454 455 resource.Test(t, resource.TestCase{ 456 PreCheck: func() { testAccPreCheck(t) }, 457 Providers: testAccProviders, 458 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 459 Steps: []resource.TestStep{ 460 resource.TestStep{ 461 Config: testAccComputeV2Instance_blockDeviceNewVolume, 462 Check: resource.ComposeTestCheckFunc( 463 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 464 ), 465 }, 466 }, 467 }) 468 } 469 470 func TestAccComputeV2Instance_blockDeviceExistingVolume(t *testing.T) { 471 var instance servers.Server 472 var volume volumes.Volume 473 474 resource.Test(t, resource.TestCase{ 475 PreCheck: func() { testAccPreCheck(t) }, 476 Providers: testAccProviders, 477 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 478 Steps: []resource.TestStep{ 479 resource.TestStep{ 480 Config: testAccComputeV2Instance_blockDeviceExistingVolume, 481 Check: resource.ComposeTestCheckFunc( 482 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 483 testAccCheckBlockStorageV1VolumeExists( 484 "openstack_blockstorage_volume_v1.volume_1", &volume), 485 ), 486 }, 487 }, 488 }) 489 } 490 491 // TODO: verify the personality really exists on the instance. 492 func TestAccComputeV2Instance_personality(t *testing.T) { 493 var instance servers.Server 494 495 resource.Test(t, resource.TestCase{ 496 PreCheck: func() { testAccPreCheck(t) }, 497 Providers: testAccProviders, 498 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 499 Steps: []resource.TestStep{ 500 resource.TestStep{ 501 Config: testAccComputeV2Instance_personality, 502 Check: resource.ComposeTestCheckFunc( 503 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 504 ), 505 }, 506 }, 507 }) 508 } 509 510 func TestAccComputeV2Instance_multiEphemeral(t *testing.T) { 511 var instance servers.Server 512 513 resource.Test(t, resource.TestCase{ 514 PreCheck: func() { testAccPreCheck(t) }, 515 Providers: testAccProviders, 516 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 517 Steps: []resource.TestStep{ 518 resource.TestStep{ 519 Config: testAccComputeV2Instance_multiEphemeral, 520 Check: resource.ComposeTestCheckFunc( 521 testAccCheckComputeV2InstanceExists( 522 "openstack_compute_instance_v2.instance_1", &instance), 523 ), 524 }, 525 }, 526 }) 527 } 528 529 func TestAccComputeV2Instance_accessIPv4(t *testing.T) { 530 var instance servers.Server 531 532 resource.Test(t, resource.TestCase{ 533 PreCheck: func() { testAccPreCheck(t) }, 534 Providers: testAccProviders, 535 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 536 Steps: []resource.TestStep{ 537 resource.TestStep{ 538 Config: testAccComputeV2Instance_accessIPv4, 539 Check: resource.ComposeTestCheckFunc( 540 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 541 resource.TestCheckResourceAttr( 542 "openstack_compute_instance_v2.instance_1", "access_ip_v4", "192.168.1.100"), 543 ), 544 }, 545 }, 546 }) 547 } 548 549 func TestAccComputeV2Instance_changeFixedIP(t *testing.T) { 550 var instance1_1 servers.Server 551 var instance1_2 servers.Server 552 553 resource.Test(t, resource.TestCase{ 554 PreCheck: func() { testAccPreCheck(t) }, 555 Providers: testAccProviders, 556 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 557 Steps: []resource.TestStep{ 558 resource.TestStep{ 559 Config: testAccComputeV2Instance_changeFixedIP_1, 560 Check: resource.ComposeTestCheckFunc( 561 testAccCheckComputeV2InstanceExists( 562 "openstack_compute_instance_v2.instance_1", &instance1_1), 563 ), 564 }, 565 resource.TestStep{ 566 Config: testAccComputeV2Instance_changeFixedIP_2, 567 Check: resource.ComposeTestCheckFunc( 568 testAccCheckComputeV2InstanceExists( 569 "openstack_compute_instance_v2.instance_1", &instance1_2), 570 testAccCheckComputeV2InstanceInstanceIDsDoNotMatch(&instance1_1, &instance1_2), 571 ), 572 }, 573 }, 574 }) 575 } 576 577 func TestAccComputeV2Instance_stopBeforeDestroy(t *testing.T) { 578 var instance servers.Server 579 resource.Test(t, resource.TestCase{ 580 PreCheck: func() { testAccPreCheck(t) }, 581 Providers: testAccProviders, 582 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 583 Steps: []resource.TestStep{ 584 resource.TestStep{ 585 Config: testAccComputeV2Instance_stopBeforeDestroy, 586 Check: resource.ComposeTestCheckFunc( 587 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 588 ), 589 }, 590 }, 591 }) 592 } 593 594 func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error { 595 config := testAccProvider.Meta().(*Config) 596 computeClient, err := config.computeV2Client(OS_REGION_NAME) 597 if err != nil { 598 return fmt.Errorf("Error creating OpenStack compute client: %s", err) 599 } 600 601 for _, rs := range s.RootModule().Resources { 602 if rs.Type != "openstack_compute_instance_v2" { 603 continue 604 } 605 606 _, err := servers.Get(computeClient, rs.Primary.ID).Extract() 607 if err == nil { 608 return fmt.Errorf("Instance still exists") 609 } 610 } 611 612 return nil 613 } 614 615 func testAccCheckComputeV2InstanceExists(n string, instance *servers.Server) resource.TestCheckFunc { 616 return func(s *terraform.State) error { 617 rs, ok := s.RootModule().Resources[n] 618 if !ok { 619 return fmt.Errorf("Not found: %s", n) 620 } 621 622 if rs.Primary.ID == "" { 623 return fmt.Errorf("No ID is set") 624 } 625 626 config := testAccProvider.Meta().(*Config) 627 computeClient, err := config.computeV2Client(OS_REGION_NAME) 628 if err != nil { 629 return fmt.Errorf("Error creating OpenStack compute client: %s", err) 630 } 631 632 found, err := servers.Get(computeClient, rs.Primary.ID).Extract() 633 if err != nil { 634 return err 635 } 636 637 if found.ID != rs.Primary.ID { 638 return fmt.Errorf("Instance not found") 639 } 640 641 *instance = *found 642 643 return nil 644 } 645 } 646 647 func testAccCheckComputeV2InstanceDoesNotExist(n string, instance *servers.Server) resource.TestCheckFunc { 648 return func(s *terraform.State) error { 649 config := testAccProvider.Meta().(*Config) 650 computeClient, err := config.computeV2Client(OS_REGION_NAME) 651 if err != nil { 652 return fmt.Errorf("Error creating OpenStack compute client: %s", err) 653 } 654 655 _, err = servers.Get(computeClient, instance.ID).Extract() 656 if err != nil { 657 if _, ok := err.(gophercloud.ErrDefault404); ok { 658 return nil 659 } 660 return err 661 } 662 663 return fmt.Errorf("Instance still exists") 664 } 665 } 666 667 func testAccCheckComputeV2InstanceMetadata( 668 instance *servers.Server, k string, v string) resource.TestCheckFunc { 669 return func(s *terraform.State) error { 670 if instance.Metadata == nil { 671 return fmt.Errorf("No metadata") 672 } 673 674 for key, value := range instance.Metadata { 675 if k != key { 676 continue 677 } 678 679 if v == value { 680 return nil 681 } 682 683 return fmt.Errorf("Bad value for %s: %s", k, value) 684 } 685 686 return fmt.Errorf("Metadata not found: %s", k) 687 } 688 } 689 690 func testAccCheckComputeV2InstanceVolumeAttachment( 691 instance *servers.Server, volume *volumes.Volume) resource.TestCheckFunc { 692 return func(s *terraform.State) error { 693 var attachments []volumeattach.VolumeAttachment 694 695 config := testAccProvider.Meta().(*Config) 696 computeClient, err := config.computeV2Client(OS_REGION_NAME) 697 if err != nil { 698 return err 699 } 700 701 err = volumeattach.List(computeClient, instance.ID).EachPage( 702 func(page pagination.Page) (bool, error) { 703 704 actual, err := volumeattach.ExtractVolumeAttachments(page) 705 if err != nil { 706 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 707 } 708 709 attachments = actual 710 return true, nil 711 }) 712 713 for _, attachment := range attachments { 714 if attachment.VolumeID == volume.ID { 715 return nil 716 } 717 } 718 719 return fmt.Errorf("Volume not found: %s", volume.ID) 720 } 721 } 722 723 func testAccCheckComputeV2InstanceVolumesDetached(instance *servers.Server) resource.TestCheckFunc { 724 return func(s *terraform.State) error { 725 var attachments []volumeattach.VolumeAttachment 726 727 config := testAccProvider.Meta().(*Config) 728 computeClient, err := config.computeV2Client(OS_REGION_NAME) 729 if err != nil { 730 return err 731 } 732 733 err = volumeattach.List(computeClient, instance.ID).EachPage( 734 func(page pagination.Page) (bool, error) { 735 736 actual, err := volumeattach.ExtractVolumeAttachments(page) 737 if err != nil { 738 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 739 } 740 741 attachments = actual 742 return true, nil 743 }) 744 745 if len(attachments) > 0 { 746 return fmt.Errorf("Volumes are still attached.") 747 } 748 749 return nil 750 } 751 } 752 753 func testAccCheckComputeV2InstanceBootVolumeAttachment( 754 instance *servers.Server) resource.TestCheckFunc { 755 return func(s *terraform.State) error { 756 var attachments []volumeattach.VolumeAttachment 757 758 config := testAccProvider.Meta().(*Config) 759 computeClient, err := config.computeV2Client(OS_REGION_NAME) 760 if err != nil { 761 return err 762 } 763 764 err = volumeattach.List(computeClient, instance.ID).EachPage( 765 func(page pagination.Page) (bool, error) { 766 767 actual, err := volumeattach.ExtractVolumeAttachments(page) 768 if err != nil { 769 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 770 } 771 772 attachments = actual 773 return true, nil 774 }) 775 776 if len(attachments) == 1 { 777 return nil 778 } 779 780 return fmt.Errorf("No attached volume found.") 781 } 782 } 783 784 func testAccCheckComputeV2InstanceFloatingIPAttach( 785 instance *servers.Server, fip *floatingips.FloatingIP) resource.TestCheckFunc { 786 return func(s *terraform.State) error { 787 if fip.InstanceID == instance.ID { 788 return nil 789 } 790 791 return fmt.Errorf("Floating IP %s was not attached to instance %s", fip.ID, instance.ID) 792 } 793 } 794 795 func testAccCheckComputeV2InstanceInstanceIDsDoNotMatch( 796 instance1, instance2 *servers.Server) resource.TestCheckFunc { 797 return func(s *terraform.State) error { 798 if instance1.ID == instance2.ID { 799 return fmt.Errorf("Instance was not recreated.") 800 } 801 802 return nil 803 } 804 } 805 806 func testAccCheckComputeV2InstanceVolumeDetached(instance *servers.Server, volume_id string) resource.TestCheckFunc { 807 return func(s *terraform.State) error { 808 var attachments []volumeattach.VolumeAttachment 809 810 rs, ok := s.RootModule().Resources[volume_id] 811 if !ok { 812 return fmt.Errorf("Not found: %s", volume_id) 813 } 814 815 if rs.Primary.ID == "" { 816 return fmt.Errorf("No ID is set") 817 } 818 819 config := testAccProvider.Meta().(*Config) 820 computeClient, err := config.computeV2Client(OS_REGION_NAME) 821 if err != nil { 822 return err 823 } 824 825 err = volumeattach.List(computeClient, instance.ID).EachPage( 826 func(page pagination.Page) (bool, error) { 827 actual, err := volumeattach.ExtractVolumeAttachments(page) 828 if err != nil { 829 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 830 } 831 832 attachments = actual 833 return true, nil 834 }) 835 836 for _, attachment := range attachments { 837 if attachment.VolumeID == rs.Primary.ID { 838 return fmt.Errorf("Volume is still attached.") 839 } 840 } 841 842 return nil 843 } 844 } 845 846 const testAccComputeV2Instance_basic = ` 847 resource "openstack_compute_instance_v2" "instance_1" { 848 name = "instance_1" 849 security_groups = ["default"] 850 metadata { 851 foo = "bar" 852 } 853 } 854 ` 855 856 const testAccComputeV2Instance_volumeAttach = ` 857 resource "openstack_blockstorage_volume_v1" "vol_1" { 858 name = "vol_1" 859 size = 1 860 } 861 862 resource "openstack_compute_instance_v2" "instance_1" { 863 name = "instance_1" 864 security_groups = ["default"] 865 volume { 866 volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}" 867 } 868 } 869 ` 870 871 const testAccComputeV2Instance_volumeAttachPostCreation_1 = ` 872 resource "openstack_compute_instance_v2" "instance_1" { 873 name = "instance_1" 874 security_groups = ["default"] 875 } 876 ` 877 878 const testAccComputeV2Instance_volumeAttachPostCreation_2 = ` 879 resource "openstack_blockstorage_volume_v1" "vol_1" { 880 name = "vol_1" 881 size = 1 882 } 883 884 resource "openstack_compute_instance_v2" "instance_1" { 885 name = "instance_1" 886 security_groups = ["default"] 887 volume { 888 volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}" 889 } 890 } 891 ` 892 893 const testAccComputeV2Instance_volumeDetachPostCreation_1 = ` 894 resource "openstack_blockstorage_volume_v1" "vol_1" { 895 name = "vol_1" 896 size = 1 897 } 898 899 resource "openstack_compute_instance_v2" "instance_1" { 900 name = "instance_1" 901 security_groups = ["default"] 902 volume { 903 volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}" 904 } 905 } 906 ` 907 908 const testAccComputeV2Instance_volumeDetachPostCreation_2 = ` 909 resource "openstack_blockstorage_volume_v1" "vol_1" { 910 name = "vol_1" 911 size = 1 912 } 913 914 resource "openstack_compute_instance_v2" "instance_1" { 915 name = "instance_1" 916 security_groups = ["default"] 917 } 918 ` 919 920 var testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_1 = fmt.Sprintf(` 921 resource "openstack_blockstorage_volume_v1" "root_volume" { 922 name = "root_volume" 923 size = 1 924 image_id = "%s" 925 } 926 927 resource "openstack_blockstorage_volume_v1" "additional_volume" { 928 name = "additional_volume" 929 size = 1 930 } 931 932 resource "openstack_compute_instance_v2" "instance_1" { 933 name = "instance_1" 934 security_groups = ["default"] 935 936 block_device { 937 uuid = "${openstack_blockstorage_volume_v1.root_volume.id}" 938 source_type = "volume" 939 boot_index = 0 940 destination_type = "volume" 941 delete_on_termination = false 942 } 943 944 volume { 945 volume_id = "${openstack_blockstorage_volume_v1.additional_volume.id}" 946 } 947 } 948 `, OS_IMAGE_ID) 949 950 var testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_2 = fmt.Sprintf(` 951 resource "openstack_blockstorage_volume_v1" "root_volume" { 952 name = "root_volume" 953 size = 1 954 image_id = "%s" 955 } 956 957 resource "openstack_blockstorage_volume_v1" "additional_volume" { 958 name = "additional_volume" 959 size = 1 960 } 961 962 resource "openstack_compute_instance_v2" "instance_1" { 963 name = "instance_1" 964 security_groups = ["default"] 965 966 block_device { 967 uuid = "${openstack_blockstorage_volume_v1.root_volume.id}" 968 source_type = "volume" 969 boot_index = 0 970 destination_type = "volume" 971 delete_on_termination = false 972 } 973 } 974 `, OS_IMAGE_ID) 975 976 var testAccComputeV2Instance_volumeAttachInstanceDelete_1 = fmt.Sprintf(` 977 resource "openstack_blockstorage_volume_v1" "root_volume" { 978 name = "root_volume" 979 size = 1 980 image_id = "%s" 981 } 982 983 resource "openstack_blockstorage_volume_v1" "additional_volume" { 984 name = "additional_volume" 985 size = 1 986 } 987 988 resource "openstack_compute_instance_v2" "instance_1" { 989 name = "instance_1" 990 security_groups = ["default"] 991 992 block_device { 993 uuid = "${openstack_blockstorage_volume_v1.root_volume.id}" 994 source_type = "volume" 995 boot_index = 0 996 destination_type = "volume" 997 delete_on_termination = false 998 } 999 1000 volume { 1001 volume_id = "${openstack_blockstorage_volume_v1.additional_volume.id}" 1002 } 1003 } 1004 `, OS_IMAGE_ID) 1005 1006 var testAccComputeV2Instance_volumeAttachInstanceDelete_2 = fmt.Sprintf(` 1007 resource "openstack_blockstorage_volume_v1" "root_volume" { 1008 name = "root_volume" 1009 size = 1 1010 image_id = "%s" 1011 } 1012 1013 resource "openstack_blockstorage_volume_v1" "additional_volume" { 1014 name = "additional_volume" 1015 size = 1 1016 } 1017 `, OS_IMAGE_ID) 1018 1019 const testAccComputeV2Instance_volumeAttachToNewInstance_1 = ` 1020 resource "openstack_blockstorage_volume_v1" "volume_1" { 1021 name = "volume_1" 1022 size = 1 1023 } 1024 1025 resource "openstack_compute_instance_v2" "instance_1" { 1026 name = "instance_1" 1027 security_groups = ["default"] 1028 1029 volume { 1030 volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}" 1031 } 1032 } 1033 1034 resource "openstack_compute_instance_v2" "instance_2" { 1035 depends_on = ["openstack_compute_instance_v2.instance_1"] 1036 name = "instance_2" 1037 security_groups = ["default"] 1038 } 1039 ` 1040 1041 const testAccComputeV2Instance_volumeAttachToNewInstance_2 = ` 1042 resource "openstack_blockstorage_volume_v1" "volume_1" { 1043 name = "volume_1" 1044 size = 1 1045 } 1046 1047 resource "openstack_compute_instance_v2" "instance_1" { 1048 name = "instance_1" 1049 security_groups = ["default"] 1050 } 1051 1052 resource "openstack_compute_instance_v2" "instance_2" { 1053 depends_on = ["openstack_compute_instance_v2.instance_1"] 1054 name = "instance_2" 1055 security_groups = ["default"] 1056 1057 volume { 1058 volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}" 1059 } 1060 } 1061 ` 1062 1063 const testAccComputeV2Instance_floatingIPAttachGlobally = ` 1064 resource "openstack_compute_floatingip_v2" "fip_1" { 1065 } 1066 1067 resource "openstack_compute_instance_v2" "instance_1" { 1068 name = "instance_1" 1069 security_groups = ["default"] 1070 floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}" 1071 } 1072 ` 1073 1074 var testAccComputeV2Instance_floatingIPAttachToNetwork = fmt.Sprintf(` 1075 resource "openstack_compute_floatingip_v2" "fip_1" { 1076 } 1077 1078 resource "openstack_compute_instance_v2" "instance_1" { 1079 name = "instance_1" 1080 security_groups = ["default"] 1081 1082 network { 1083 uuid = "%s" 1084 floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}" 1085 access_network = true 1086 } 1087 } 1088 `, OS_NETWORK_ID) 1089 1090 var testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_1 = fmt.Sprintf(` 1091 resource "openstack_compute_floatingip_v2" "fip_1" { 1092 } 1093 1094 resource "openstack_compute_floatingip_v2" "fip_2" { 1095 } 1096 1097 resource "openstack_compute_instance_v2" "instance_1" { 1098 name = "instance_1" 1099 security_groups = ["default"] 1100 1101 network { 1102 uuid = "%s" 1103 floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}" 1104 access_network = true 1105 } 1106 } 1107 `, OS_NETWORK_ID) 1108 1109 var testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_2 = fmt.Sprintf(` 1110 resource "openstack_compute_floatingip_v2" "fip_1" { 1111 } 1112 1113 resource "openstack_compute_floatingip_v2" "fip_2" { 1114 } 1115 1116 resource "openstack_compute_instance_v2" "instance_1" { 1117 name = "instance_1" 1118 security_groups = ["default"] 1119 1120 network { 1121 uuid = "%s" 1122 floating_ip = "${openstack_compute_floatingip_v2.fip_2.address}" 1123 access_network = true 1124 } 1125 } 1126 `, OS_NETWORK_ID) 1127 1128 const testAccComputeV2Instance_secgroupMulti = ` 1129 resource "openstack_compute_secgroup_v2" "secgroup_1" { 1130 name = "secgroup_1" 1131 description = "a security group" 1132 rule { 1133 from_port = 22 1134 to_port = 22 1135 ip_protocol = "tcp" 1136 cidr = "0.0.0.0/0" 1137 } 1138 } 1139 1140 resource "openstack_compute_instance_v2" "instance_1" { 1141 name = "instance_1" 1142 security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"] 1143 } 1144 ` 1145 1146 const testAccComputeV2Instance_secgroupMultiUpdate_1 = ` 1147 resource "openstack_compute_secgroup_v2" "secgroup_1" { 1148 name = "secgroup_1" 1149 description = "a security group" 1150 rule { 1151 from_port = 22 1152 to_port = 22 1153 ip_protocol = "tcp" 1154 cidr = "0.0.0.0/0" 1155 } 1156 } 1157 1158 resource "openstack_compute_secgroup_v2" "secgroup_2" { 1159 name = "secgroup_2" 1160 description = "another security group" 1161 rule { 1162 from_port = 80 1163 to_port = 80 1164 ip_protocol = "tcp" 1165 cidr = "0.0.0.0/0" 1166 } 1167 } 1168 1169 resource "openstack_compute_instance_v2" "instance_1" { 1170 name = "instance_1" 1171 security_groups = ["default"] 1172 } 1173 ` 1174 1175 const testAccComputeV2Instance_secgroupMultiUpdate_2 = ` 1176 resource "openstack_compute_secgroup_v2" "secgroup_1" { 1177 name = "secgroup_1" 1178 description = "a security group" 1179 rule { 1180 from_port = 22 1181 to_port = 22 1182 ip_protocol = "tcp" 1183 cidr = "0.0.0.0/0" 1184 } 1185 } 1186 1187 resource "openstack_compute_secgroup_v2" "secgroup_2" { 1188 name = "secgroup_2" 1189 description = "another security group" 1190 rule { 1191 from_port = 80 1192 to_port = 80 1193 ip_protocol = "tcp" 1194 cidr = "0.0.0.0/0" 1195 } 1196 } 1197 1198 resource "openstack_compute_instance_v2" "instance_1" { 1199 name = "instance_1" 1200 security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}", "${openstack_compute_secgroup_v2.secgroup_2.name}"] 1201 } 1202 ` 1203 1204 var testAccComputeV2Instance_bootFromVolumeImage = fmt.Sprintf(` 1205 resource "openstack_compute_instance_v2" "instance_1" { 1206 name = "instance_1" 1207 security_groups = ["default"] 1208 block_device { 1209 uuid = "%s" 1210 source_type = "image" 1211 volume_size = 5 1212 boot_index = 0 1213 destination_type = "volume" 1214 delete_on_termination = true 1215 } 1216 } 1217 `, OS_IMAGE_ID) 1218 1219 var testAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume = fmt.Sprintf(` 1220 resource "openstack_blockstorage_volume_v1" "volume_1" { 1221 name = "volume_1" 1222 size = 1 1223 } 1224 1225 resource "openstack_compute_instance_v2" "instance_1" { 1226 name = "instance_1" 1227 security_groups = ["default"] 1228 block_device { 1229 uuid = "%s" 1230 source_type = "image" 1231 volume_size = 2 1232 boot_index = 0 1233 destination_type = "volume" 1234 delete_on_termination = true 1235 } 1236 1237 volume { 1238 volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}" 1239 } 1240 } 1241 `, OS_IMAGE_ID) 1242 1243 var testAccComputeV2Instance_bootFromVolumeVolume = fmt.Sprintf(` 1244 resource "openstack_blockstorage_volume_v1" "vol_1" { 1245 name = "vol_1" 1246 size = 5 1247 image_id = "%s" 1248 } 1249 1250 resource "openstack_compute_instance_v2" "instance_1" { 1251 name = "instance_1" 1252 security_groups = ["default"] 1253 block_device { 1254 uuid = "${openstack_blockstorage_volume_v1.vol_1.id}" 1255 source_type = "volume" 1256 boot_index = 0 1257 destination_type = "volume" 1258 delete_on_termination = true 1259 } 1260 } 1261 `, OS_IMAGE_ID) 1262 1263 var testAccComputeV2Instance_bootFromVolumeForceNew_1 = fmt.Sprintf(` 1264 resource "openstack_compute_instance_v2" "instance_1" { 1265 name = "instance_1" 1266 security_groups = ["default"] 1267 block_device { 1268 uuid = "%s" 1269 source_type = "image" 1270 volume_size = 5 1271 boot_index = 0 1272 destination_type = "volume" 1273 delete_on_termination = true 1274 } 1275 } 1276 `, OS_IMAGE_ID) 1277 1278 var testAccComputeV2Instance_bootFromVolumeForceNew_2 = fmt.Sprintf(` 1279 resource "openstack_compute_instance_v2" "instance_1" { 1280 name = "instance_1" 1281 security_groups = ["default"] 1282 block_device { 1283 uuid = "%s" 1284 source_type = "image" 1285 volume_size = 4 1286 boot_index = 0 1287 destination_type = "volume" 1288 delete_on_termination = true 1289 } 1290 } 1291 `, OS_IMAGE_ID) 1292 1293 var testAccComputeV2Instance_blockDeviceNewVolume = fmt.Sprintf(` 1294 resource "openstack_compute_instance_v2" "instance_1" { 1295 name = "instance_1" 1296 security_groups = ["default"] 1297 block_device { 1298 uuid = "%s" 1299 source_type = "image" 1300 destination_type = "local" 1301 boot_index = 0 1302 delete_on_termination = true 1303 } 1304 block_device { 1305 source_type = "blank" 1306 destination_type = "volume" 1307 volume_size = 1 1308 boot_index = 1 1309 delete_on_termination = true 1310 } 1311 } 1312 `, OS_IMAGE_ID) 1313 1314 var testAccComputeV2Instance_blockDeviceExistingVolume = fmt.Sprintf(` 1315 resource "openstack_blockstorage_volume_v1" "volume_1" { 1316 name = "volume_1" 1317 size = 1 1318 } 1319 1320 resource "openstack_compute_instance_v2" "instance_1" { 1321 name = "instance_1" 1322 security_groups = ["default"] 1323 block_device { 1324 uuid = "%s" 1325 source_type = "image" 1326 destination_type = "local" 1327 boot_index = 0 1328 delete_on_termination = true 1329 } 1330 block_device { 1331 uuid = "${openstack_blockstorage_volume_v1.volume_1.id}" 1332 source_type = "volume" 1333 destination_type = "volume" 1334 boot_index = 1 1335 delete_on_termination = true 1336 } 1337 } 1338 `, OS_IMAGE_ID) 1339 1340 const testAccComputeV2Instance_personality = ` 1341 resource "openstack_compute_instance_v2" "instance_1" { 1342 name = "instance_1" 1343 security_groups = ["default"] 1344 personality { 1345 file = "/tmp/foobar.txt" 1346 content = "happy" 1347 } 1348 personality { 1349 file = "/tmp/barfoo.txt" 1350 content = "angry" 1351 } 1352 } 1353 ` 1354 1355 var testAccComputeV2Instance_multiEphemeral = fmt.Sprintf(` 1356 resource "openstack_compute_instance_v2" "instance_1" { 1357 name = "terraform-test" 1358 security_groups = ["default"] 1359 block_device { 1360 boot_index = 0 1361 delete_on_termination = true 1362 destination_type = "local" 1363 source_type = "image" 1364 uuid = "%s" 1365 } 1366 block_device { 1367 boot_index = -1 1368 delete_on_termination = true 1369 destination_type = "local" 1370 source_type = "blank" 1371 volume_size = 1 1372 } 1373 block_device { 1374 boot_index = -1 1375 delete_on_termination = true 1376 destination_type = "local" 1377 source_type = "blank" 1378 volume_size = 1 1379 } 1380 } 1381 `, OS_IMAGE_ID) 1382 1383 var testAccComputeV2Instance_accessIPv4 = fmt.Sprintf(` 1384 resource "openstack_compute_floatingip_v2" "myip" { 1385 } 1386 1387 resource "openstack_networking_network_v2" "network_1" { 1388 name = "network_1" 1389 } 1390 1391 resource "openstack_networking_subnet_v2" "subnet_1" { 1392 name = "subnet_1" 1393 network_id = "${openstack_networking_network_v2.network_1.id}" 1394 cidr = "192.168.1.0/24" 1395 ip_version = 4 1396 enable_dhcp = true 1397 no_gateway = true 1398 } 1399 1400 resource "openstack_compute_instance_v2" "instance_1" { 1401 depends_on = ["openstack_networking_subnet_v2.subnet_1"] 1402 1403 name = "instance_1" 1404 security_groups = ["default"] 1405 floating_ip = "${openstack_compute_floatingip_v2.myip.address}" 1406 1407 network { 1408 uuid = "%s" 1409 } 1410 1411 network { 1412 uuid = "${openstack_networking_network_v2.network_1.id}" 1413 fixed_ip_v4 = "192.168.1.100" 1414 access_network = true 1415 } 1416 } 1417 `, OS_NETWORK_ID) 1418 1419 var testAccComputeV2Instance_changeFixedIP_1 = fmt.Sprintf(` 1420 resource "openstack_compute_instance_v2" "instance_1" { 1421 name = "instance_1" 1422 security_groups = ["default"] 1423 network { 1424 uuid = "%s" 1425 fixed_ip_v4 = "10.0.0.24" 1426 } 1427 } 1428 `, OS_NETWORK_ID) 1429 1430 var testAccComputeV2Instance_changeFixedIP_2 = fmt.Sprintf(` 1431 resource "openstack_compute_instance_v2" "instance_1" { 1432 name = "instance_1" 1433 security_groups = ["default"] 1434 network { 1435 uuid = "%s" 1436 fixed_ip_v4 = "10.0.0.25" 1437 } 1438 } 1439 `, OS_NETWORK_ID) 1440 1441 const testAccComputeV2Instance_stopBeforeDestroy = ` 1442 resource "openstack_compute_instance_v2" "instance_1" { 1443 name = "instance_1" 1444 security_groups = ["default"] 1445 stop_before_destroy = true 1446 } 1447 `