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