github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/website/source/docs/providers/openstack/r/compute_instance_v2.html.markdown (about) 1 --- 2 layout: "openstack" 3 page_title: "OpenStack: openstack_compute_instance_v2" 4 sidebar_current: "docs-openstack-resource-compute-instance-v2" 5 description: |- 6 Manages a V2 VM instance resource within OpenStack. 7 --- 8 9 # openstack\_compute\_instance_v2 10 11 Manages a V2 VM instance resource within OpenStack. 12 13 ## Example Usage 14 15 ### Basic Instance 16 17 ``` 18 resource "openstack_compute_instance_v2" "basic" { 19 name = "basic" 20 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 21 flavor_id = "3" 22 key_pair = "my_key_pair_name" 23 security_groups = ["default"] 24 25 metadata { 26 this = "that" 27 } 28 29 network { 30 name = "my_network" 31 } 32 } 33 ``` 34 35 ### Instance With Attached Volume 36 37 ``` 38 resource "openstack_blockstorage_volume_v1" "myvol" { 39 name = "myvol" 40 size = 1 41 } 42 43 resource "openstack_compute_instance_v2" "volume-attached" { 44 name = "volume-attached" 45 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 46 flavor_id = "3" 47 key_pair = "my_key_pair_name" 48 security_groups = ["default"] 49 50 network { 51 name = "my_network" 52 } 53 54 volume { 55 volume_id = "${openstack_blockstorage_volume_v1.myvol.id}" 56 } 57 } 58 ``` 59 60 ### Boot From Volume 61 62 ``` 63 resource "openstack_compute_instance_v2" "boot-from-volume" { 64 name = "boot-from-volume" 65 flavor_id = "3" 66 key_pair = "my_key_pair_name" 67 security_groups = ["default"] 68 69 block_device { 70 uuid = "<image-id>" 71 source_type = "image" 72 volume_size = 5 73 boot_index = 0 74 destination_type = "volume" 75 delete_on_termination = true 76 } 77 78 network { 79 name = "my_network" 80 } 81 } 82 ``` 83 84 ### Boot From an Existing Volume 85 86 ``` 87 resource "openstack_blockstorage_volume_v1" "myvol" { 88 name = "myvol" 89 size = 5 90 image_id = "<image-id>" 91 } 92 93 resource "openstack_compute_instance_v2" "boot-from-volume" { 94 name = "bootfromvolume" 95 flavor_id = "3" 96 key_pair = "my_key_pair_name" 97 security_groups = ["default"] 98 99 block_device { 100 uuid = "${openstack_blockstorage_volume_v1.myvol.id}" 101 source_type = "volume" 102 boot_index = 0 103 destination_type = "volume" 104 delete_on_termination = true 105 } 106 107 network { 108 name = "my_network" 109 } 110 } 111 ``` 112 113 ### Boot Instance, Create Volume, and Attach Volume as a Block Device 114 115 ``` 116 resource "openstack_compute_instance_v2" "instance_1" { 117 name = "instance_1" 118 image_id = "<image-id>" 119 flavor_id = "3" 120 key_pair = "my_key_pair_name" 121 security_groups = ["default"] 122 123 block_device { 124 uuid = "<image-id>" 125 source_type = "image" 126 destination_type = "local" 127 boot_index = 0 128 delete_on_termination = true 129 } 130 131 block_device { 132 source_type = "blank" 133 destination_type = "volume" 134 volume_size = 1 135 boot_index = 1 136 delete_on_termination = true 137 } 138 } 139 ``` 140 141 ### Boot Instance and Attach Existing Volume as a Block Device 142 143 ``` 144 resource "openstack_blockstorage_volume_v2" "volume_1" { 145 name = "volume_1" 146 size = 1 147 } 148 149 resource "openstack_compute_instance_v2" "instance_1" { 150 name = "instance_1" 151 image_id = "<image-id>" 152 flavor_id = "3" 153 key_pair = "my_key_pair_name" 154 security_groups = ["default"] 155 156 block_device { 157 uuid = "<image-id>" 158 source_type = "image" 159 destination_type = "local" 160 boot_index = 0 161 delete_on_termination = true 162 } 163 164 block_device { 165 uuid = "${openstack_blockstorage_volume_v2.volume_1.id}" 166 source_type = "volume" 167 destination_type = "volume" 168 boot_index = 1 169 delete_on_termination = true 170 } 171 } 172 ``` 173 174 ### Instance With Multiple Networks 175 176 ``` 177 resource "openstack_compute_floatingip_v2" "myip" { 178 pool = "my_pool" 179 } 180 181 resource "openstack_compute_instance_v2" "multi-net" { 182 name = "multi-net" 183 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 184 flavor_id = "3" 185 key_pair = "my_key_pair_name" 186 security_groups = ["default"] 187 188 network { 189 name = "my_first_network" 190 } 191 192 network { 193 name = "my_second_network" 194 floating_ip = "${openstack_compute_floatingip_v2.myip.address}" 195 196 # Terraform will use this network for provisioning 197 access_network = true 198 } 199 } 200 ``` 201 202 ### Instance With Personality 203 204 ``` 205 resource "openstack_compute_instance_v2" "personality" { 206 name = "personality" 207 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 208 flavor_id = "3" 209 key_pair = "my_key_pair_name" 210 security_groups = ["default"] 211 212 personality { 213 file = "/path/to/file/on/instance.txt" 214 content = "contents of file" 215 } 216 217 network { 218 name = "my_network" 219 } 220 } 221 ``` 222 223 ### Instance with Multiple Ephemeral Disks 224 225 ``` 226 resource "openstack_compute_instance_v2" "multi-eph" { 227 name = "multi_eph" 228 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 229 flavor_id = "3" 230 key_pair = "my_key_pair_name" 231 security_groups = ["default"] 232 233 block_device { 234 boot_index = 0 235 delete_on_termination = true 236 destination_type = "local" 237 source_type = "image" 238 uuid = "<image-id>" 239 } 240 241 block_device { 242 boot_index = -1 243 delete_on_termination = true 244 destination_type = "local" 245 source_type = "blank" 246 volume_size = 1 247 } 248 249 block_device { 250 boot_index = -1 251 delete_on_termination = true 252 destination_type = "local" 253 source_type = "blank" 254 volume_size = 1 255 } 256 } 257 ``` 258 259 ## Argument Reference 260 261 The following arguments are supported: 262 263 * `region` - (Required) The region in which to create the server instance. If 264 omitted, the `OS_REGION_NAME` environment variable is used. Changing this 265 creates a new server. 266 267 * `name` - (Required) A unique name for the resource. 268 269 * `image_id` - (Optional; Required if `image_name` is empty and not booting 270 from a volume. Do not specify if booting from a volume.) The image ID of 271 the desired image for the server. Changing this creates a new server. 272 273 * `image_name` - (Optional; Required if `image_id` is empty and not booting 274 from a volume. Do not specify if booting from a volume.) The name of the 275 desired image for the server. Changing this creates a new server. 276 277 * `flavor_id` - (Optional; Required if `flavor_name` is empty) The flavor ID of 278 the desired flavor for the server. Changing this resizes the existing server. 279 280 * `flavor_name` - (Optional; Required if `flavor_id` is empty) The name of the 281 desired flavor for the server. Changing this resizes the existing server. 282 283 * `floating_ip` - (Optional) A *Compute* Floating IP that will be associated 284 with the Instance. The Floating IP must be provisioned already. See *Notes* 285 for more information about Floating IPs. 286 287 * `user_data` - (Optional) The user data to provide when launching the instance. 288 Changing this creates a new server. 289 290 * `security_groups` - (Optional) An array of one or more security group names 291 to associate with the server. Changing this results in adding/removing 292 security groups from the existing server. *Note*: When attaching the 293 instance to networks using Ports, place the security groups on the Port 294 and not the instance. 295 296 * `availability_zone` - (Optional) The availability zone in which to create 297 the server. Changing this creates a new server. 298 299 * `network` - (Optional) An array of one or more networks to attach to the 300 instance. The network object structure is documented below. Changing this 301 creates a new server. 302 303 * `metadata` - (Optional) Metadata key/value pairs to make available from 304 within the instance. Changing this updates the existing server metadata. 305 306 * `config_drive` - (Optional) Whether to use the config_drive feature to 307 configure the instance. Changing this creates a new server. 308 309 * `admin_pass` - (Optional) The administrative password to assign to the server. 310 Changing this changes the root password on the existing server. 311 312 * `key_pair` - (Optional) The name of a key pair to put on the server. The key 313 pair must already be created and associated with the tenant's account. 314 Changing this creates a new server. 315 316 * `block_device` - (Optional) Configuration of block devices. The block_device 317 structure is documented below. Changing this creates a new server. 318 You can specify multiple block devices which will create an instance with 319 multiple disks. This configuration is very flexible, so please see the 320 following [reference](http://docs.openstack.org/developer/nova/block_device_mapping.html) 321 for more information. 322 323 * `volume` - (Optional) Attach an existing volume to the instance. The volume 324 structure is described below. *Note*: This is no longer the recommended 325 method of attaching a volume to an instance. Please see `block_device` 326 (above) or the `openstack_compute_volume_attach_v2` and 327 `openstack_blockstorage_volume_attach_v2` resources. 328 329 * `scheduler_hints` - (Optional) Provide the Nova scheduler with hints on how 330 the instance should be launched. The available hints are described below. 331 332 * `personality` - (Optional) Customize the personality of an instance by 333 defining one or more files and their contents. The personality structure 334 is described below. 335 336 * `stop_before_destroy` - (Optional) Whether to try stop instance gracefully 337 before destroying it, thus giving chance for guest OS daemons to stop correctly. 338 If instance doesn't stop within timeout, it will be destroyed anyway. 339 340 341 The `network` block supports: 342 343 * `uuid` - (Required unless `port` or `name` is provided) The network UUID to 344 attach to the server. Changing this creates a new server. 345 346 * `name` - (Required unless `uuid` or `port` is provided) The human-readable 347 name of the network. Changing this creates a new server. 348 349 * `port` - (Required unless `uuid` or `name` is provided) The port UUID of a 350 network to attach to the server. Changing this creates a new server. 351 352 * `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this 353 network. Changing this creates a new server. 354 355 * `fixed_ip_v6` - (Optional) Specifies a fixed IPv6 address to be used on this 356 network. Changing this creates a new server. 357 358 * `floating_ip` - (Optional) Specifies a floating IP address to be associated 359 with this network. Cannot be combined with a top-level floating IP. See 360 *Notes* for more information about Floating IPs. 361 362 * `access_network` - (Optional) Specifies if this network should be used for 363 provisioning access. Accepts true or false. Defaults to false. 364 365 The `block_device` block supports: 366 367 * `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of 368 the image, volume, or snapshot. Changing this creates a new server. 369 370 * `source_type` - (Required) The source type of the device. Must be one of 371 "blank", "image", "volume", or "snapshot". Changing this creates a new 372 server. 373 374 * `volume_size` - The size of the volume to create (in gigabytes). Required 375 in the following combinations: source=image and destination=volume, 376 source=blank and destination=local, and source=blank and destination=volume. 377 Changing this creates a new server. 378 379 * `boot_index` - (Optional) The boot index of the volume. It defaults to 0. 380 Changing this creates a new server. 381 382 * `destination_type` - (Optional) The type that gets created. Possible values 383 are "volume" and "local". Changing this creates a new server. 384 385 * `delete_on_termination` - (Optional) Delete the volume / block device upon 386 termination of the instance. Defaults to false. Changing this creates a 387 new server. 388 389 The `volume` block supports: 390 391 * `volume_id` - (Required) The UUID of the volume to attach. 392 393 * `device` - (Optional) The device that the volume will be attached as. For 394 example: `/dev/vdc`. Omit this option to allow the volume to be 395 auto-assigned a device. 396 397 The `scheduler_hints` block supports: 398 399 * `group` - (Optional) A UUID of a Server Group. The instance will be placed 400 into that group. 401 402 * `different_host` - (Optional) A list of instance UUIDs. The instance will 403 be scheduled on a different host than all other instances. 404 405 * `same_host` - (Optional) A list of instance UUIDs. The instance will be 406 scheduled on the same host of those specified. 407 408 * `query` - (Optional) A conditional query that a compute node must pass in 409 order to host an instance. 410 411 * `target_cell` - (Optional) The name of a cell to host the instance. 412 413 * `build_near_host_ip` - (Optional) An IP Address in CIDR form. The instance 414 will be placed on a compute node that is in the same subnet. 415 416 The `personality` block supports: 417 418 * `file` - (Required) The absolute path of the destination file. 419 420 * `contents` - (Required) The contents of the file. Limited to 255 bytes. 421 422 ## Attributes Reference 423 424 The following attributes are exported: 425 426 * `region` - See Argument Reference above. 427 * `name` - See Argument Reference above. 428 * `access_ip_v4` - The first detected Fixed IPv4 address _or_ the 429 Floating IP. 430 * `access_ip_v6` - The first detected Fixed IPv6 address. 431 * `metadata` - See Argument Reference above. 432 * `security_groups` - See Argument Reference above. 433 * `flavor_id` - See Argument Reference above. 434 * `flavor_name` - See Argument Reference above. 435 * `network/uuid` - See Argument Reference above. 436 * `network/name` - See Argument Reference above. 437 * `network/port` - See Argument Reference above. 438 * `network/fixed_ip_v4` - The Fixed IPv4 address of the Instance on that 439 network. 440 * `network/fixed_ip_v6` - The Fixed IPv6 address of the Instance on that 441 network. 442 * `network/floating_ip` - The Floating IP address of the Instance on that 443 network. 444 * `network/mac` - The MAC address of the NIC on that network. 445 446 ## Notes 447 448 ### Floating IPs 449 450 Floating IPs can be associated in one of two ways: 451 452 * You can specify a Floating IP address by using the top-level `floating_ip` 453 attribute. This floating IP will be associated with either the network defined 454 in the first `network` block or the default network if no `network` blocks are 455 defined. 456 457 * You can specify a Floating IP address by using the `floating_ip` attribute 458 defined in the `network` block. Each `network` block can have its own floating 459 IP address. 460 461 Only one of the above methods can be used. 462 463 ### Multiple Ephemeral Disks 464 465 It's possible to specify multiple `block_device` entries to create an instance 466 with multiple ephemeral (local) disks. In order to create multiple ephemeral 467 disks, the sum of the total amount of ephemeral space must be less than or 468 equal to what the chosen flavor supports. 469 470 The following example shows how to create an instance with multiple ephemeral 471 disks: 472 473 ``` 474 resource "openstack_compute_instance_v2" "foo" { 475 name = "terraform-test" 476 security_groups = ["default"] 477 478 block_device { 479 boot_index = 0 480 delete_on_termination = true 481 destination_type = "local" 482 source_type = "image" 483 uuid = "<image uuid>" 484 } 485 486 block_device { 487 boot_index = -1 488 delete_on_termination = true 489 destination_type = "local" 490 source_type = "blank" 491 volume_size = 1 492 } 493 494 block_device { 495 boot_index = -1 496 delete_on_termination = true 497 destination_type = "local" 498 source_type = "blank" 499 volume_size = 1 500 } 501 } 502 ``` 503 504 ### Instances and Ports 505 506 Neutron Ports are a great feature and provide a lot of functionality. However, 507 there are some notes to be aware of when mixing Instances and Ports: 508 509 * When attaching an Instance to one or more networks using Ports, place the 510 security groups on the Port and not the Instance. If you place the security 511 groups on the Instance, the security groups will not be applied upon creation, 512 but they will be applied upon a refresh. This is a known OpenStack bug. 513 514 * Network IP information is not available within an instance for networks that 515 are attached with Ports. This is mostly due to the flexibility Neutron Ports 516 provide when it comes to IP addresses. For example, a Neutron Port can have 517 multiple Fixed IP addresses associated with it. It's not possible to know which 518 single IP address the user would want returned to the Instance's state 519 information. Therefore, in order for a Provisioner to connect to an Instance 520 via it's network Port, customize the `connection` information: 521 522 ``` 523 resource "openstack_networking_port_v2" "port_1" { 524 name = "port_1" 525 admin_state_up = "true" 526 527 network_id = "0a1d0a27-cffa-4de3-92c5-9d3fd3f2e74d" 528 529 security_group_ids = [ 530 "2f02d20a-8dca-49b7-b26f-b6ce9fddaf4f", 531 "ca1e5ed7-dae8-4605-987b-fadaeeb30461", 532 ] 533 } 534 535 resource "openstack_compute_instance_v2" "instance_1" { 536 name = "instance_1" 537 538 network { 539 port = "${openstack_networking_port_v2.port_1.id}" 540 } 541 542 connection { 543 user = "root" 544 host = "${openstack_networking_port_v2.port_1.fixed_ip.0.ip_address}" 545 private_key = "~/path/to/key" 546 } 547 548 provisioner "remote-exec" { 549 inline = [ 550 "echo terraform executed > /tmp/foo", 551 ] 552 } 553 } 554 ```