github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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 TestAccComputeV2Instance_metadataRemove(t *testing.T) { 595 var instance servers.Server 596 597 resource.Test(t, resource.TestCase{ 598 PreCheck: func() { testAccPreCheck(t) }, 599 Providers: testAccProviders, 600 CheckDestroy: testAccCheckComputeV2InstanceDestroy, 601 Steps: []resource.TestStep{ 602 resource.TestStep{ 603 Config: testAccComputeV2Instance_metadataRemove_1, 604 Check: resource.ComposeTestCheckFunc( 605 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 606 testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"), 607 testAccCheckComputeV2InstanceMetadata(&instance, "abc", "def"), 608 ), 609 }, 610 resource.TestStep{ 611 Config: testAccComputeV2Instance_metadataRemove_2, 612 Check: resource.ComposeTestCheckFunc( 613 testAccCheckComputeV2InstanceExists("openstack_compute_instance_v2.instance_1", &instance), 614 testAccCheckComputeV2InstanceMetadata(&instance, "foo", "bar"), 615 testAccCheckComputeV2InstanceMetadata(&instance, "ghi", "jkl"), 616 testAccCheckComputeV2InstanceNoMetadataKey(&instance, "abc"), 617 ), 618 }, 619 }, 620 }) 621 } 622 623 func testAccCheckComputeV2InstanceDestroy(s *terraform.State) error { 624 config := testAccProvider.Meta().(*Config) 625 computeClient, err := config.computeV2Client(OS_REGION_NAME) 626 if err != nil { 627 return fmt.Errorf("Error creating OpenStack compute client: %s", err) 628 } 629 630 for _, rs := range s.RootModule().Resources { 631 if rs.Type != "openstack_compute_instance_v2" { 632 continue 633 } 634 635 _, err := servers.Get(computeClient, rs.Primary.ID).Extract() 636 if err == nil { 637 return fmt.Errorf("Instance still exists") 638 } 639 } 640 641 return nil 642 } 643 644 func testAccCheckComputeV2InstanceExists(n string, instance *servers.Server) resource.TestCheckFunc { 645 return func(s *terraform.State) error { 646 rs, ok := s.RootModule().Resources[n] 647 if !ok { 648 return fmt.Errorf("Not found: %s", n) 649 } 650 651 if rs.Primary.ID == "" { 652 return fmt.Errorf("No ID is set") 653 } 654 655 config := testAccProvider.Meta().(*Config) 656 computeClient, err := config.computeV2Client(OS_REGION_NAME) 657 if err != nil { 658 return fmt.Errorf("Error creating OpenStack compute client: %s", err) 659 } 660 661 found, err := servers.Get(computeClient, rs.Primary.ID).Extract() 662 if err != nil { 663 return err 664 } 665 666 if found.ID != rs.Primary.ID { 667 return fmt.Errorf("Instance not found") 668 } 669 670 *instance = *found 671 672 return nil 673 } 674 } 675 676 func testAccCheckComputeV2InstanceDoesNotExist(n string, instance *servers.Server) resource.TestCheckFunc { 677 return func(s *terraform.State) error { 678 config := testAccProvider.Meta().(*Config) 679 computeClient, err := config.computeV2Client(OS_REGION_NAME) 680 if err != nil { 681 return fmt.Errorf("Error creating OpenStack compute client: %s", err) 682 } 683 684 _, err = servers.Get(computeClient, instance.ID).Extract() 685 if err != nil { 686 if _, ok := err.(gophercloud.ErrDefault404); ok { 687 return nil 688 } 689 return err 690 } 691 692 return fmt.Errorf("Instance still exists") 693 } 694 } 695 696 func testAccCheckComputeV2InstanceMetadata( 697 instance *servers.Server, k string, v string) resource.TestCheckFunc { 698 return func(s *terraform.State) error { 699 if instance.Metadata == nil { 700 return fmt.Errorf("No metadata") 701 } 702 703 for key, value := range instance.Metadata { 704 if k != key { 705 continue 706 } 707 708 if v == value { 709 return nil 710 } 711 712 return fmt.Errorf("Bad value for %s: %s", k, value) 713 } 714 715 return fmt.Errorf("Metadata not found: %s", k) 716 } 717 } 718 719 func testAccCheckComputeV2InstanceNoMetadataKey( 720 instance *servers.Server, k string) resource.TestCheckFunc { 721 return func(s *terraform.State) error { 722 if instance.Metadata == nil { 723 return nil 724 } 725 726 for key, _ := range instance.Metadata { 727 if k == key { 728 return fmt.Errorf("Metadata found: %s", k) 729 } 730 } 731 732 return nil 733 } 734 } 735 736 func testAccCheckComputeV2InstanceVolumeAttachment( 737 instance *servers.Server, volume *volumes.Volume) resource.TestCheckFunc { 738 return func(s *terraform.State) error { 739 var attachments []volumeattach.VolumeAttachment 740 741 config := testAccProvider.Meta().(*Config) 742 computeClient, err := config.computeV2Client(OS_REGION_NAME) 743 if err != nil { 744 return err 745 } 746 747 err = volumeattach.List(computeClient, instance.ID).EachPage( 748 func(page pagination.Page) (bool, error) { 749 750 actual, err := volumeattach.ExtractVolumeAttachments(page) 751 if err != nil { 752 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 753 } 754 755 attachments = actual 756 return true, nil 757 }) 758 759 for _, attachment := range attachments { 760 if attachment.VolumeID == volume.ID { 761 return nil 762 } 763 } 764 765 return fmt.Errorf("Volume not found: %s", volume.ID) 766 } 767 } 768 769 func testAccCheckComputeV2InstanceVolumesDetached(instance *servers.Server) resource.TestCheckFunc { 770 return func(s *terraform.State) error { 771 var attachments []volumeattach.VolumeAttachment 772 773 config := testAccProvider.Meta().(*Config) 774 computeClient, err := config.computeV2Client(OS_REGION_NAME) 775 if err != nil { 776 return err 777 } 778 779 err = volumeattach.List(computeClient, instance.ID).EachPage( 780 func(page pagination.Page) (bool, error) { 781 782 actual, err := volumeattach.ExtractVolumeAttachments(page) 783 if err != nil { 784 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 785 } 786 787 attachments = actual 788 return true, nil 789 }) 790 791 if len(attachments) > 0 { 792 return fmt.Errorf("Volumes are still attached.") 793 } 794 795 return nil 796 } 797 } 798 799 func testAccCheckComputeV2InstanceBootVolumeAttachment( 800 instance *servers.Server) resource.TestCheckFunc { 801 return func(s *terraform.State) error { 802 var attachments []volumeattach.VolumeAttachment 803 804 config := testAccProvider.Meta().(*Config) 805 computeClient, err := config.computeV2Client(OS_REGION_NAME) 806 if err != nil { 807 return err 808 } 809 810 err = volumeattach.List(computeClient, instance.ID).EachPage( 811 func(page pagination.Page) (bool, error) { 812 813 actual, err := volumeattach.ExtractVolumeAttachments(page) 814 if err != nil { 815 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 816 } 817 818 attachments = actual 819 return true, nil 820 }) 821 822 if len(attachments) == 1 { 823 return nil 824 } 825 826 return fmt.Errorf("No attached volume found.") 827 } 828 } 829 830 func testAccCheckComputeV2InstanceFloatingIPAttach( 831 instance *servers.Server, fip *floatingips.FloatingIP) resource.TestCheckFunc { 832 return func(s *terraform.State) error { 833 if fip.InstanceID == instance.ID { 834 return nil 835 } 836 837 return fmt.Errorf("Floating IP %s was not attached to instance %s", fip.ID, instance.ID) 838 } 839 } 840 841 func testAccCheckComputeV2InstanceInstanceIDsDoNotMatch( 842 instance1, instance2 *servers.Server) resource.TestCheckFunc { 843 return func(s *terraform.State) error { 844 if instance1.ID == instance2.ID { 845 return fmt.Errorf("Instance was not recreated.") 846 } 847 848 return nil 849 } 850 } 851 852 func testAccCheckComputeV2InstanceVolumeDetached(instance *servers.Server, volume_id string) resource.TestCheckFunc { 853 return func(s *terraform.State) error { 854 var attachments []volumeattach.VolumeAttachment 855 856 rs, ok := s.RootModule().Resources[volume_id] 857 if !ok { 858 return fmt.Errorf("Not found: %s", volume_id) 859 } 860 861 if rs.Primary.ID == "" { 862 return fmt.Errorf("No ID is set") 863 } 864 865 config := testAccProvider.Meta().(*Config) 866 computeClient, err := config.computeV2Client(OS_REGION_NAME) 867 if err != nil { 868 return err 869 } 870 871 err = volumeattach.List(computeClient, instance.ID).EachPage( 872 func(page pagination.Page) (bool, error) { 873 actual, err := volumeattach.ExtractVolumeAttachments(page) 874 if err != nil { 875 return false, fmt.Errorf("Unable to lookup attachment: %s", err) 876 } 877 878 attachments = actual 879 return true, nil 880 }) 881 882 for _, attachment := range attachments { 883 if attachment.VolumeID == rs.Primary.ID { 884 return fmt.Errorf("Volume is still attached.") 885 } 886 } 887 888 return nil 889 } 890 } 891 892 const testAccComputeV2Instance_basic = ` 893 resource "openstack_compute_instance_v2" "instance_1" { 894 name = "instance_1" 895 security_groups = ["default"] 896 metadata { 897 foo = "bar" 898 } 899 } 900 ` 901 902 const testAccComputeV2Instance_volumeAttach = ` 903 resource "openstack_blockstorage_volume_v1" "vol_1" { 904 name = "vol_1" 905 size = 1 906 } 907 908 resource "openstack_compute_instance_v2" "instance_1" { 909 name = "instance_1" 910 security_groups = ["default"] 911 volume { 912 volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}" 913 } 914 } 915 ` 916 917 const testAccComputeV2Instance_volumeAttachPostCreation_1 = ` 918 resource "openstack_compute_instance_v2" "instance_1" { 919 name = "instance_1" 920 security_groups = ["default"] 921 } 922 ` 923 924 const testAccComputeV2Instance_volumeAttachPostCreation_2 = ` 925 resource "openstack_blockstorage_volume_v1" "vol_1" { 926 name = "vol_1" 927 size = 1 928 } 929 930 resource "openstack_compute_instance_v2" "instance_1" { 931 name = "instance_1" 932 security_groups = ["default"] 933 volume { 934 volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}" 935 } 936 } 937 ` 938 939 const testAccComputeV2Instance_volumeDetachPostCreation_1 = ` 940 resource "openstack_blockstorage_volume_v1" "vol_1" { 941 name = "vol_1" 942 size = 1 943 } 944 945 resource "openstack_compute_instance_v2" "instance_1" { 946 name = "instance_1" 947 security_groups = ["default"] 948 volume { 949 volume_id = "${openstack_blockstorage_volume_v1.vol_1.id}" 950 } 951 } 952 ` 953 954 const testAccComputeV2Instance_volumeDetachPostCreation_2 = ` 955 resource "openstack_blockstorage_volume_v1" "vol_1" { 956 name = "vol_1" 957 size = 1 958 } 959 960 resource "openstack_compute_instance_v2" "instance_1" { 961 name = "instance_1" 962 security_groups = ["default"] 963 } 964 ` 965 966 var testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_1 = fmt.Sprintf(` 967 resource "openstack_blockstorage_volume_v1" "root_volume" { 968 name = "root_volume" 969 size = 1 970 image_id = "%s" 971 } 972 973 resource "openstack_blockstorage_volume_v1" "additional_volume" { 974 name = "additional_volume" 975 size = 1 976 } 977 978 resource "openstack_compute_instance_v2" "instance_1" { 979 name = "instance_1" 980 security_groups = ["default"] 981 982 block_device { 983 uuid = "${openstack_blockstorage_volume_v1.root_volume.id}" 984 source_type = "volume" 985 boot_index = 0 986 destination_type = "volume" 987 delete_on_termination = false 988 } 989 990 volume { 991 volume_id = "${openstack_blockstorage_volume_v1.additional_volume.id}" 992 } 993 } 994 `, OS_IMAGE_ID) 995 996 var testAccComputeV2Instance_volumeDetachAdditionalVolumePostCreation_2 = fmt.Sprintf(` 997 resource "openstack_blockstorage_volume_v1" "root_volume" { 998 name = "root_volume" 999 size = 1 1000 image_id = "%s" 1001 } 1002 1003 resource "openstack_blockstorage_volume_v1" "additional_volume" { 1004 name = "additional_volume" 1005 size = 1 1006 } 1007 1008 resource "openstack_compute_instance_v2" "instance_1" { 1009 name = "instance_1" 1010 security_groups = ["default"] 1011 1012 block_device { 1013 uuid = "${openstack_blockstorage_volume_v1.root_volume.id}" 1014 source_type = "volume" 1015 boot_index = 0 1016 destination_type = "volume" 1017 delete_on_termination = false 1018 } 1019 } 1020 `, OS_IMAGE_ID) 1021 1022 var testAccComputeV2Instance_volumeAttachInstanceDelete_1 = fmt.Sprintf(` 1023 resource "openstack_blockstorage_volume_v1" "root_volume" { 1024 name = "root_volume" 1025 size = 1 1026 image_id = "%s" 1027 } 1028 1029 resource "openstack_blockstorage_volume_v1" "additional_volume" { 1030 name = "additional_volume" 1031 size = 1 1032 } 1033 1034 resource "openstack_compute_instance_v2" "instance_1" { 1035 name = "instance_1" 1036 security_groups = ["default"] 1037 1038 block_device { 1039 uuid = "${openstack_blockstorage_volume_v1.root_volume.id}" 1040 source_type = "volume" 1041 boot_index = 0 1042 destination_type = "volume" 1043 delete_on_termination = false 1044 } 1045 1046 volume { 1047 volume_id = "${openstack_blockstorage_volume_v1.additional_volume.id}" 1048 } 1049 } 1050 `, OS_IMAGE_ID) 1051 1052 var testAccComputeV2Instance_volumeAttachInstanceDelete_2 = fmt.Sprintf(` 1053 resource "openstack_blockstorage_volume_v1" "root_volume" { 1054 name = "root_volume" 1055 size = 1 1056 image_id = "%s" 1057 } 1058 1059 resource "openstack_blockstorage_volume_v1" "additional_volume" { 1060 name = "additional_volume" 1061 size = 1 1062 } 1063 `, OS_IMAGE_ID) 1064 1065 const testAccComputeV2Instance_volumeAttachToNewInstance_1 = ` 1066 resource "openstack_blockstorage_volume_v1" "volume_1" { 1067 name = "volume_1" 1068 size = 1 1069 } 1070 1071 resource "openstack_compute_instance_v2" "instance_1" { 1072 name = "instance_1" 1073 security_groups = ["default"] 1074 1075 volume { 1076 volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}" 1077 } 1078 } 1079 1080 resource "openstack_compute_instance_v2" "instance_2" { 1081 depends_on = ["openstack_compute_instance_v2.instance_1"] 1082 name = "instance_2" 1083 security_groups = ["default"] 1084 } 1085 ` 1086 1087 const testAccComputeV2Instance_volumeAttachToNewInstance_2 = ` 1088 resource "openstack_blockstorage_volume_v1" "volume_1" { 1089 name = "volume_1" 1090 size = 1 1091 } 1092 1093 resource "openstack_compute_instance_v2" "instance_1" { 1094 name = "instance_1" 1095 security_groups = ["default"] 1096 } 1097 1098 resource "openstack_compute_instance_v2" "instance_2" { 1099 depends_on = ["openstack_compute_instance_v2.instance_1"] 1100 name = "instance_2" 1101 security_groups = ["default"] 1102 1103 volume { 1104 volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}" 1105 } 1106 } 1107 ` 1108 1109 const testAccComputeV2Instance_floatingIPAttachGlobally = ` 1110 resource "openstack_compute_floatingip_v2" "fip_1" { 1111 } 1112 1113 resource "openstack_compute_instance_v2" "instance_1" { 1114 name = "instance_1" 1115 security_groups = ["default"] 1116 floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}" 1117 } 1118 ` 1119 1120 var testAccComputeV2Instance_floatingIPAttachToNetwork = fmt.Sprintf(` 1121 resource "openstack_compute_floatingip_v2" "fip_1" { 1122 } 1123 1124 resource "openstack_compute_instance_v2" "instance_1" { 1125 name = "instance_1" 1126 security_groups = ["default"] 1127 1128 network { 1129 uuid = "%s" 1130 floating_ip = "${openstack_compute_floatingip_v2.fip_1.address}" 1131 access_network = true 1132 } 1133 } 1134 `, OS_NETWORK_ID) 1135 1136 var testAccComputeV2Instance_floatingIPAttachToNetworkAndChange_1 = fmt.Sprintf(` 1137 resource "openstack_compute_floatingip_v2" "fip_1" { 1138 } 1139 1140 resource "openstack_compute_floatingip_v2" "fip_2" { 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_2 = 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_2.address}" 1169 access_network = true 1170 } 1171 } 1172 `, OS_NETWORK_ID) 1173 1174 const testAccComputeV2Instance_secgroupMulti = ` 1175 resource "openstack_compute_secgroup_v2" "secgroup_1" { 1176 name = "secgroup_1" 1177 description = "a security group" 1178 rule { 1179 from_port = 22 1180 to_port = 22 1181 ip_protocol = "tcp" 1182 cidr = "0.0.0.0/0" 1183 } 1184 } 1185 1186 resource "openstack_compute_instance_v2" "instance_1" { 1187 name = "instance_1" 1188 security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}"] 1189 } 1190 ` 1191 1192 const testAccComputeV2Instance_secgroupMultiUpdate_1 = ` 1193 resource "openstack_compute_secgroup_v2" "secgroup_1" { 1194 name = "secgroup_1" 1195 description = "a security group" 1196 rule { 1197 from_port = 22 1198 to_port = 22 1199 ip_protocol = "tcp" 1200 cidr = "0.0.0.0/0" 1201 } 1202 } 1203 1204 resource "openstack_compute_secgroup_v2" "secgroup_2" { 1205 name = "secgroup_2" 1206 description = "another security group" 1207 rule { 1208 from_port = 80 1209 to_port = 80 1210 ip_protocol = "tcp" 1211 cidr = "0.0.0.0/0" 1212 } 1213 } 1214 1215 resource "openstack_compute_instance_v2" "instance_1" { 1216 name = "instance_1" 1217 security_groups = ["default"] 1218 } 1219 ` 1220 1221 const testAccComputeV2Instance_secgroupMultiUpdate_2 = ` 1222 resource "openstack_compute_secgroup_v2" "secgroup_1" { 1223 name = "secgroup_1" 1224 description = "a security group" 1225 rule { 1226 from_port = 22 1227 to_port = 22 1228 ip_protocol = "tcp" 1229 cidr = "0.0.0.0/0" 1230 } 1231 } 1232 1233 resource "openstack_compute_secgroup_v2" "secgroup_2" { 1234 name = "secgroup_2" 1235 description = "another security group" 1236 rule { 1237 from_port = 80 1238 to_port = 80 1239 ip_protocol = "tcp" 1240 cidr = "0.0.0.0/0" 1241 } 1242 } 1243 1244 resource "openstack_compute_instance_v2" "instance_1" { 1245 name = "instance_1" 1246 security_groups = ["default", "${openstack_compute_secgroup_v2.secgroup_1.name}", "${openstack_compute_secgroup_v2.secgroup_2.name}"] 1247 } 1248 ` 1249 1250 var testAccComputeV2Instance_bootFromVolumeImage = fmt.Sprintf(` 1251 resource "openstack_compute_instance_v2" "instance_1" { 1252 name = "instance_1" 1253 security_groups = ["default"] 1254 block_device { 1255 uuid = "%s" 1256 source_type = "image" 1257 volume_size = 5 1258 boot_index = 0 1259 destination_type = "volume" 1260 delete_on_termination = true 1261 } 1262 } 1263 `, OS_IMAGE_ID) 1264 1265 var testAccComputeV2Instance_bootFromVolumeImageWithAttachedVolume = fmt.Sprintf(` 1266 resource "openstack_blockstorage_volume_v1" "volume_1" { 1267 name = "volume_1" 1268 size = 1 1269 } 1270 1271 resource "openstack_compute_instance_v2" "instance_1" { 1272 name = "instance_1" 1273 security_groups = ["default"] 1274 block_device { 1275 uuid = "%s" 1276 source_type = "image" 1277 volume_size = 2 1278 boot_index = 0 1279 destination_type = "volume" 1280 delete_on_termination = true 1281 } 1282 1283 volume { 1284 volume_id = "${openstack_blockstorage_volume_v1.volume_1.id}" 1285 } 1286 } 1287 `, OS_IMAGE_ID) 1288 1289 var testAccComputeV2Instance_bootFromVolumeVolume = fmt.Sprintf(` 1290 resource "openstack_blockstorage_volume_v1" "vol_1" { 1291 name = "vol_1" 1292 size = 5 1293 image_id = "%s" 1294 } 1295 1296 resource "openstack_compute_instance_v2" "instance_1" { 1297 name = "instance_1" 1298 security_groups = ["default"] 1299 block_device { 1300 uuid = "${openstack_blockstorage_volume_v1.vol_1.id}" 1301 source_type = "volume" 1302 boot_index = 0 1303 destination_type = "volume" 1304 delete_on_termination = true 1305 } 1306 } 1307 `, OS_IMAGE_ID) 1308 1309 var testAccComputeV2Instance_bootFromVolumeForceNew_1 = fmt.Sprintf(` 1310 resource "openstack_compute_instance_v2" "instance_1" { 1311 name = "instance_1" 1312 security_groups = ["default"] 1313 block_device { 1314 uuid = "%s" 1315 source_type = "image" 1316 volume_size = 5 1317 boot_index = 0 1318 destination_type = "volume" 1319 delete_on_termination = true 1320 } 1321 } 1322 `, OS_IMAGE_ID) 1323 1324 var testAccComputeV2Instance_bootFromVolumeForceNew_2 = fmt.Sprintf(` 1325 resource "openstack_compute_instance_v2" "instance_1" { 1326 name = "instance_1" 1327 security_groups = ["default"] 1328 block_device { 1329 uuid = "%s" 1330 source_type = "image" 1331 volume_size = 4 1332 boot_index = 0 1333 destination_type = "volume" 1334 delete_on_termination = true 1335 } 1336 } 1337 `, OS_IMAGE_ID) 1338 1339 var testAccComputeV2Instance_blockDeviceNewVolume = fmt.Sprintf(` 1340 resource "openstack_compute_instance_v2" "instance_1" { 1341 name = "instance_1" 1342 security_groups = ["default"] 1343 block_device { 1344 uuid = "%s" 1345 source_type = "image" 1346 destination_type = "local" 1347 boot_index = 0 1348 delete_on_termination = true 1349 } 1350 block_device { 1351 source_type = "blank" 1352 destination_type = "volume" 1353 volume_size = 1 1354 boot_index = 1 1355 delete_on_termination = true 1356 } 1357 } 1358 `, OS_IMAGE_ID) 1359 1360 var testAccComputeV2Instance_blockDeviceExistingVolume = fmt.Sprintf(` 1361 resource "openstack_blockstorage_volume_v1" "volume_1" { 1362 name = "volume_1" 1363 size = 1 1364 } 1365 1366 resource "openstack_compute_instance_v2" "instance_1" { 1367 name = "instance_1" 1368 security_groups = ["default"] 1369 block_device { 1370 uuid = "%s" 1371 source_type = "image" 1372 destination_type = "local" 1373 boot_index = 0 1374 delete_on_termination = true 1375 } 1376 block_device { 1377 uuid = "${openstack_blockstorage_volume_v1.volume_1.id}" 1378 source_type = "volume" 1379 destination_type = "volume" 1380 boot_index = 1 1381 delete_on_termination = true 1382 } 1383 } 1384 `, OS_IMAGE_ID) 1385 1386 const testAccComputeV2Instance_personality = ` 1387 resource "openstack_compute_instance_v2" "instance_1" { 1388 name = "instance_1" 1389 security_groups = ["default"] 1390 personality { 1391 file = "/tmp/foobar.txt" 1392 content = "happy" 1393 } 1394 personality { 1395 file = "/tmp/barfoo.txt" 1396 content = "angry" 1397 } 1398 } 1399 ` 1400 1401 var testAccComputeV2Instance_multiEphemeral = fmt.Sprintf(` 1402 resource "openstack_compute_instance_v2" "instance_1" { 1403 name = "terraform-test" 1404 security_groups = ["default"] 1405 block_device { 1406 boot_index = 0 1407 delete_on_termination = true 1408 destination_type = "local" 1409 source_type = "image" 1410 uuid = "%s" 1411 } 1412 block_device { 1413 boot_index = -1 1414 delete_on_termination = true 1415 destination_type = "local" 1416 source_type = "blank" 1417 volume_size = 1 1418 } 1419 block_device { 1420 boot_index = -1 1421 delete_on_termination = true 1422 destination_type = "local" 1423 source_type = "blank" 1424 volume_size = 1 1425 } 1426 } 1427 `, OS_IMAGE_ID) 1428 1429 var testAccComputeV2Instance_accessIPv4 = fmt.Sprintf(` 1430 resource "openstack_compute_floatingip_v2" "myip" { 1431 } 1432 1433 resource "openstack_networking_network_v2" "network_1" { 1434 name = "network_1" 1435 } 1436 1437 resource "openstack_networking_subnet_v2" "subnet_1" { 1438 name = "subnet_1" 1439 network_id = "${openstack_networking_network_v2.network_1.id}" 1440 cidr = "192.168.1.0/24" 1441 ip_version = 4 1442 enable_dhcp = true 1443 no_gateway = true 1444 } 1445 1446 resource "openstack_compute_instance_v2" "instance_1" { 1447 depends_on = ["openstack_networking_subnet_v2.subnet_1"] 1448 1449 name = "instance_1" 1450 security_groups = ["default"] 1451 floating_ip = "${openstack_compute_floatingip_v2.myip.address}" 1452 1453 network { 1454 uuid = "%s" 1455 } 1456 1457 network { 1458 uuid = "${openstack_networking_network_v2.network_1.id}" 1459 fixed_ip_v4 = "192.168.1.100" 1460 access_network = true 1461 } 1462 } 1463 `, OS_NETWORK_ID) 1464 1465 var testAccComputeV2Instance_changeFixedIP_1 = fmt.Sprintf(` 1466 resource "openstack_compute_instance_v2" "instance_1" { 1467 name = "instance_1" 1468 security_groups = ["default"] 1469 network { 1470 uuid = "%s" 1471 fixed_ip_v4 = "10.0.0.24" 1472 } 1473 } 1474 `, OS_NETWORK_ID) 1475 1476 var testAccComputeV2Instance_changeFixedIP_2 = fmt.Sprintf(` 1477 resource "openstack_compute_instance_v2" "instance_1" { 1478 name = "instance_1" 1479 security_groups = ["default"] 1480 network { 1481 uuid = "%s" 1482 fixed_ip_v4 = "10.0.0.25" 1483 } 1484 } 1485 `, OS_NETWORK_ID) 1486 1487 const testAccComputeV2Instance_stopBeforeDestroy = ` 1488 resource "openstack_compute_instance_v2" "instance_1" { 1489 name = "instance_1" 1490 security_groups = ["default"] 1491 stop_before_destroy = true 1492 } 1493 ` 1494 1495 const testAccComputeV2Instance_metadataRemove_1 = ` 1496 resource "openstack_compute_instance_v2" "instance_1" { 1497 name = "instance_1" 1498 security_groups = ["default"] 1499 metadata { 1500 foo = "bar" 1501 abc = "def" 1502 } 1503 } 1504 ` 1505 1506 const testAccComputeV2Instance_metadataRemove_2 = ` 1507 resource "openstack_compute_instance_v2" "instance_1" { 1508 name = "instance_1" 1509 security_groups = ["default"] 1510 metadata { 1511 foo = "bar" 1512 ghi = "jkl" 1513 } 1514 } 1515 `