github.com/jrasell/terraform@v0.6.17-0.20160523115548-2652f5232949/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 ### Instance With Multiple Networks 114 115 ``` 116 resource "openstack_compute_floatingip_v2" "myip" { 117 pool = "my_pool" 118 } 119 120 resource "openstack_compute_instance_v2" "multi-net" { 121 name = "multi-net" 122 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 123 flavor_id = "3" 124 key_pair = "my_key_pair_name" 125 security_groups = ["default"] 126 127 network { 128 name = "my_first_network" 129 } 130 131 network { 132 name = "my_second_network" 133 floating_ip = "${openstack_compute_floatingip_v2.myip.address}" 134 # Terraform will use this network for provisioning 135 access_network = true 136 } 137 } 138 ``` 139 140 ### Instance With Personality 141 142 ``` 143 resource "openstack_compute_instance_v2" "personality" { 144 name = "personality" 145 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 146 flavor_id = "3" 147 key_pair = "my_key_pair_name" 148 security_groups = ["default"] 149 150 personality { 151 file = "/path/to/file/on/instance.txt 152 content = "contents of file" 153 } 154 155 network { 156 name = "my_network" 157 } 158 } 159 ``` 160 161 ### Instance with Multiple Ephemeral Disks 162 163 ``` 164 resource "openstack_compute_instance_v2" "multi-eph" { 165 name = "multi_eph" 166 image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743" 167 flavor_id = "3" 168 key_pair = "my_key_pair_name" 169 security_groups = ["default"] 170 171 block_device { 172 boot_index = 0 173 delete_on_termination = true 174 destination_type = "local" 175 source_type = "image" 176 uuid = "<image-id>" 177 } 178 179 block_device { 180 boot_index = -1 181 delete_on_termination = true 182 destination_type = "local" 183 source_type = "blank" 184 volume_size = 1 185 } 186 187 block_device { 188 boot_index = -1 189 delete_on_termination = true 190 destination_type = "local" 191 source_type = "blank" 192 volume_size = 1 193 } 194 } 195 ``` 196 197 ## Argument Reference 198 199 The following arguments are supported: 200 201 * `region` - (Required) The region in which to create the server instance. If 202 omitted, the `OS_REGION_NAME` environment variable is used. Changing this 203 creates a new server. 204 205 * `name` - (Required) A unique name for the resource. 206 207 * `image_id` - (Optional; Required if `image_name` is empty and not booting 208 from a volume. Do not specify if booting from a volume.) The image ID of 209 the desired image for the server. Changing this creates a new server. 210 211 * `image_name` - (Optional; Required if `image_id` is empty and not booting 212 from a volume. Do not specify if booting from a volume.) The name of the 213 desired image for the server. Changing this creates a new server. 214 215 * `flavor_id` - (Optional; Required if `flavor_name` is empty) The flavor ID of 216 the desired flavor for the server. Changing this resizes the existing server. 217 218 * `flavor_name` - (Optional; Required if `flavor_id` is empty) The name of the 219 desired flavor for the server. Changing this resizes the existing server. 220 221 * `floating_ip` - (Optional) A *Compute* Floating IP that will be associated 222 with the Instance. The Floating IP must be provisioned already. See *Notes* 223 for more information about Floating IPs. 224 225 * `user_data` - (Optional) The user data to provide when launching the instance. 226 Changing this creates a new server. 227 228 * `security_groups` - (Optional) An array of one or more security group names 229 to associate with the server. Changing this results in adding/removing 230 security groups from the existing server. 231 232 * `availability_zone` - (Optional) The availability zone in which to create 233 the server. Changing this creates a new server. 234 235 * `network` - (Optional) An array of one or more networks to attach to the 236 instance. The network object structure is documented below. Changing this 237 creates a new server. 238 239 * `metadata` - (Optional) Metadata key/value pairs to make available from 240 within the instance. Changing this updates the existing server metadata. 241 242 * `config_drive` - (Optional) Whether to use the config_drive feature to 243 configure the instance. Changing this creates a new server. 244 245 * `admin_pass` - (Optional) The administrative password to assign to the server. 246 Changing this changes the root password on the existing server. 247 248 * `key_pair` - (Optional) The name of a key pair to put on the server. The key 249 pair must already be created and associated with the tenant's account. 250 Changing this creates a new server. 251 252 * `block_device` - (Optional) The object for booting by volume. The block_device 253 object structure is documented below. Changing this creates a new server. 254 You can specify multiple block devices which will create an instance with 255 multiple ephemeral (local) disks. 256 257 * `volume` - (Optional) Attach an existing volume to the instance. The volume 258 structure is described below. 259 260 * `scheduler_hints` - (Optional) Provide the Nova scheduler with hints on how 261 the instance should be launched. The available hints are described below. 262 263 * `personality` - (Optional) Customize the personality of an instance by 264 defining one or more files and their contents. The personality structure 265 is described below. 266 267 The `network` block supports: 268 269 * `uuid` - (Required unless `port` or `name` is provided) The network UUID to 270 attach to the server. 271 272 * `name` - (Required unless `uuid` or `port` is provided) The human-readable 273 name of the network. 274 275 * `port` - (Required unless `uuid` or `name` is provided) The port UUID of a 276 network to attach to the server. 277 278 * `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this 279 network. 280 281 * `floating_ip` - (Optional) Specifies a floating IP address to be associated 282 with this network. Cannot be combined with a top-level floating IP. See 283 *Notes* for more information about Floating IPs. 284 285 * `access_network` - (Optional) Specifies if this network should be used for 286 provisioning access. Accepts true or false. Defaults to false. 287 288 The `block_device` block supports: 289 290 * `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of the image, volume, or snapshot. 291 292 * `source_type` - (Required) The source type of the device. Must be one of 293 "blank", "image", "volume", or "snapshot". 294 295 * `volume_size` - The size of the volume to create (in gigabytes). Required 296 in the following combinations: source=image and destination=volume, 297 source=blank and destination=local. 298 299 * `boot_index` - (Optional) The boot index of the volume. It defaults to 0. 300 301 * `destination_type` - (Optional) The type that gets created. Possible values 302 are "volume" and "local". 303 304 The `volume` block supports: 305 306 * `volume_id` - (Required) The UUID of the volume to attach. 307 308 * `device` - (Optional) The device that the volume will be attached as. For 309 example: `/dev/vdc`. Omit this option to allow the volume to be 310 auto-assigned a device. 311 312 The `scheduler_hints` block supports: 313 314 * `group` - (Optional) A UUID of a Server Group. The instance will be placed 315 into that group. 316 317 * `different_host` - (Optional) A list of instance UUIDs. The instance will 318 be scheduled on a different host than all other instances. 319 320 * `same_host` - (Optional) A list of instance UUIDs. The instance will be 321 scheduled on the same host of those specified. 322 323 * `query` - (Optional) A conditional query that a compute node must pass in 324 order to host an instance. 325 326 * `target_cell` - (Optional) The name of a cell to host the instance. 327 328 * `build_near_host_ip` - (Optional) An IP Address in CIDR form. The instance 329 will be placed on a compute node that is in the same subnet. 330 331 The `personality` block supports: 332 333 * `file` - (Required) The absolute path of the destination file. 334 335 * `contents` - (Required) The contents of the file. Limited to 255 bytes. 336 337 ## Attributes Reference 338 339 The following attributes are exported: 340 341 * `region` - See Argument Reference above. 342 * `name` - See Argument Reference above. 343 * `access_ip_v4` - The first detected Fixed IPv4 address _or_ the 344 Floating IP. 345 * `access_ip_v6` - The first detected Fixed IPv6 address. 346 * `metadata` - See Argument Reference above. 347 * `security_groups` - See Argument Reference above. 348 * `flavor_id` - See Argument Reference above. 349 * `flavor_name` - See Argument Reference above. 350 * `network/uuid` - See Argument Reference above. 351 * `network/name` - See Argument Reference above. 352 * `network/port` - See Argument Reference above. 353 * `network/fixed_ip_v4` - The Fixed IPv4 address of the Instance on that 354 network. 355 * `network/fixed_ip_v6` - The Fixed IPv6 address of the Instance on that 356 network. 357 * `network/floating_ip` - The Floating IP address of the Instance on that 358 network. 359 * `network/mac` - The MAC address of the NIC on that network. 360 361 ## Notes 362 363 ### Floating IPs 364 365 Floating IPs can be associated in one of two ways: 366 367 * You can specify a Floating IP address by using the top-level `floating_ip` 368 attribute. This floating IP will be associated with either the network defined 369 in the first `network` block or the default network if no `network` blocks are 370 defined. 371 372 * You can specify a Floating IP address by using the `floating_ip` attribute 373 defined in the `network` block. Each `network` block can have its own floating 374 IP address. 375 376 Only one of the above methods can be used. 377 378 ### Multiple Ephemeral Disks 379 380 It's possible to specify multiple `block_device` entries to create an instance 381 with multiple ephemeral (local) disks. In order to create multiple ephemeral 382 disks, the sum of the total amount of ephemeral space must be less than or 383 equal to what the chosen flavor supports. 384 385 The following example shows how to create an instance with multiple ephemeral 386 disks: 387 388 ``` 389 resource "openstack_compute_instance_v2" "foo" { 390 name = "terraform-test" 391 security_groups = ["default"] 392 393 block_device { 394 boot_index = 0 395 delete_on_termination = true 396 destination_type = "local" 397 source_type = "image" 398 uuid = "<image uuid>" 399 } 400 401 block_device { 402 boot_index = -1 403 delete_on_termination = true 404 destination_type = "local" 405 source_type = "blank" 406 volume_size = 1 407 } 408 409 block_device { 410 boot_index = -1 411 delete_on_termination = true 412 destination_type = "local" 413 source_type = "blank" 414 volume_size = 1 415 } 416 } 417 ```