github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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      # Terraform will use this network for provisioning
   196      access_network = true
   197    }
   198  }
   199  ```
   200  
   201  ### Instance With Personality
   202  
   203  ```
   204  resource "openstack_compute_instance_v2" "personality" {
   205    name = "personality"
   206    image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743"
   207    flavor_id = "3"
   208    key_pair = "my_key_pair_name"
   209    security_groups = ["default"]
   210  
   211    personality {
   212      file = "/path/to/file/on/instance.txt
   213      content = "contents of file"
   214    }
   215  
   216    network {
   217      name = "my_network"
   218    }
   219  }
   220  ```
   221  
   222  ### Instance with Multiple Ephemeral Disks
   223  
   224  ```
   225  resource "openstack_compute_instance_v2" "multi-eph" {
   226    name = "multi_eph"
   227    image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743"
   228    flavor_id = "3"
   229    key_pair = "my_key_pair_name"
   230    security_groups = ["default"]
   231  
   232    block_device {
   233      boot_index = 0
   234      delete_on_termination = true
   235      destination_type = "local"
   236      source_type = "image"
   237      uuid = "<image-id>"
   238    }
   239  
   240    block_device {
   241      boot_index = -1
   242      delete_on_termination = true
   243      destination_type = "local"
   244      source_type = "blank"
   245      volume_size = 1
   246    }
   247  
   248    block_device {
   249      boot_index = -1
   250      delete_on_termination = true
   251      destination_type = "local"
   252      source_type = "blank"
   253      volume_size = 1
   254    }
   255  }
   256  ```
   257  
   258  ## Argument Reference
   259  
   260  The following arguments are supported:
   261  
   262  * `region` - (Required) The region in which to create the server instance. If
   263      omitted, the `OS_REGION_NAME` environment variable is used. Changing this
   264      creates a new server.
   265  
   266  * `name` - (Required) A unique name for the resource.
   267  
   268  * `image_id` - (Optional; Required if `image_name` is empty and not booting
   269      from a volume. Do not specify if booting from a volume.) The image ID of
   270      the desired image for the server. Changing this creates a new server.
   271  
   272  * `image_name` - (Optional; Required if `image_id` is empty and not booting
   273      from a volume. Do not specify if booting from a volume.) The name of the
   274      desired image for the server. Changing this creates a new server.
   275  
   276  * `flavor_id` - (Optional; Required if `flavor_name` is empty) The flavor ID of
   277      the desired flavor for the server. Changing this resizes the existing server.
   278  
   279  * `flavor_name` - (Optional; Required if `flavor_id` is empty) The name of the
   280      desired flavor for the server. Changing this resizes the existing server.
   281  
   282  * `floating_ip` - (Optional) A *Compute* Floating IP that will be associated
   283      with the Instance. The Floating IP must be provisioned already. See *Notes*
   284      for more information about Floating IPs.
   285  
   286  * `user_data` - (Optional) The user data to provide when launching the instance.
   287      Changing this creates a new server.
   288  
   289  * `security_groups` - (Optional) An array of one or more security group names
   290      to associate with the server. Changing this results in adding/removing
   291      security groups from the existing server. *Note*: When attaching the
   292      instance to networks using Ports, place the security groups on the Port
   293      and not the instance.
   294  
   295  * `availability_zone` - (Optional) The availability zone in which to create
   296      the server. Changing this creates a new server.
   297  
   298  * `network` - (Optional) An array of one or more networks to attach to the
   299      instance. The network object structure is documented below. Changing this
   300      creates a new server.
   301  
   302  * `metadata` - (Optional) Metadata key/value pairs to make available from
   303      within the instance. Changing this updates the existing server metadata.
   304  
   305  * `config_drive` - (Optional) Whether to use the config_drive feature to
   306      configure the instance. Changing this creates a new server.
   307  
   308  * `admin_pass` - (Optional) The administrative password to assign to the server.
   309      Changing this changes the root password on the existing server.
   310  
   311  * `key_pair` - (Optional) The name of a key pair to put on the server. The key
   312      pair must already be created and associated with the tenant's account.
   313      Changing this creates a new server.
   314  
   315  * `block_device` - (Optional) Configuration of block devices. The block_device
   316      structure is documented below. Changing this creates a new server.
   317      You can specify multiple block devices which will create an instance with
   318      multiple disks. This configuration is very flexible, so please see the
   319      following [reference](http://docs.openstack.org/developer/nova/block_device_mapping.html)
   320      for more information.
   321  
   322  * `volume` - (Optional) Attach an existing volume to the instance. The volume
   323      structure is described below. *Note*: This is no longer the recommended
   324      method of attaching a volume to an instance. Please see `block_device`
   325      (above) or the `openstack_compute_volume_attach_v2` and
   326      `openstack_blockstorage_volume_attach_v2` resources.
   327  
   328  * `scheduler_hints` - (Optional) Provide the Nova scheduler with hints on how
   329      the instance should be launched. The available hints are described below.
   330  
   331  * `personality` - (Optional) Customize the personality of an instance by
   332      defining one or more files and their contents. The personality structure
   333      is described below.
   334  
   335  * `stop_before_destroy` - (Optional) Whether to try stop instance gracefully
   336      before destroying it, thus giving chance for guest OS daemons to stop correctly.
   337      If instance doesn't stop within timeout, it will be destroyed anyway.
   338  
   339  
   340  The `network` block supports:
   341  
   342  * `uuid` - (Required unless `port`  or `name` is provided) The network UUID to
   343      attach to the server. Changing this creates a new server.
   344  
   345  * `name` - (Required unless `uuid` or `port` is provided) The human-readable
   346      name of the network. Changing this creates a new server.
   347  
   348  * `port` - (Required unless `uuid` or `name` is provided) The port UUID of a
   349      network to attach to the server. Changing this creates a new server.
   350  
   351  * `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this
   352      network. Changing this creates a new server.
   353  
   354  * `fixed_ip_v6` - (Optional) Specifies a fixed IPv6 address to be used on this
   355      network. Changing this creates a new server.
   356  
   357  * `floating_ip` - (Optional) Specifies a floating IP address to be associated
   358      with this network. Cannot be combined with a top-level floating IP. See
   359      *Notes* for more information about Floating IPs.
   360  
   361  * `access_network` - (Optional) Specifies if this network should be used for
   362      provisioning access. Accepts true or false. Defaults to false.
   363  
   364  The `block_device` block supports:
   365  
   366  * `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of
   367      the image, volume, or snapshot. Changing this creates a new server.
   368  
   369  * `source_type` - (Required) The source type of the device. Must be one of
   370      "blank", "image", "volume", or "snapshot". Changing this creates a new
   371      server.
   372  
   373  * `volume_size` - The size of the volume to create (in gigabytes). Required
   374      in the following combinations: source=image and destination=volume,
   375      source=blank and destination=local, and source=blank and destination=volume.
   376      Changing this creates a new server.
   377  
   378  * `boot_index` - (Optional) The boot index of the volume. It defaults to 0.
   379      Changing this creates a new server.
   380  
   381  * `destination_type` - (Optional) The type that gets created. Possible values
   382      are "volume" and "local". Changing this creates a new server.
   383  
   384  * `delete_on_termination` - (Optional) Delete the volume / block device upon
   385      termination of the instance. Defaults to false. Changing this creates a
   386      new server.
   387  
   388  The `volume` block supports:
   389  
   390  * `volume_id` - (Required) The UUID of the volume to attach.
   391  
   392  * `device` - (Optional) The device that the volume will be attached as. For
   393      example:  `/dev/vdc`. Omit this option to allow the volume to be
   394      auto-assigned a device.
   395  
   396  The `scheduler_hints` block supports:
   397  
   398  * `group` - (Optional) A UUID of a Server Group. The instance will be placed
   399      into that group.
   400  
   401  * `different_host` - (Optional) A list of instance UUIDs. The instance will
   402      be scheduled on a different host than all other instances.
   403  
   404  * `same_host` - (Optional) A list of instance UUIDs. The instance will be
   405      scheduled on the same host of those specified.
   406  
   407  * `query` - (Optional) A conditional query that a compute node must pass in
   408      order to host an instance.
   409  
   410  * `target_cell` - (Optional) The name of a cell to host the instance.
   411  
   412  * `build_near_host_ip` - (Optional) An IP Address in CIDR form. The instance
   413      will be placed on a compute node that is in the same subnet.
   414  
   415  The `personality` block supports:
   416  
   417  * `file` - (Required) The absolute path of the destination file.
   418  
   419  * `contents` - (Required) The contents of the file. Limited to 255 bytes.
   420  
   421  ## Attributes Reference
   422  
   423  The following attributes are exported:
   424  
   425  * `region` - See Argument Reference above.
   426  * `name` - See Argument Reference above.
   427  * `access_ip_v4` - The first detected Fixed IPv4 address _or_ the
   428      Floating IP.
   429  * `access_ip_v6` - The first detected Fixed IPv6 address.
   430  * `metadata` - See Argument Reference above.
   431  * `security_groups` - See Argument Reference above.
   432  * `flavor_id` - See Argument Reference above.
   433  * `flavor_name` - See Argument Reference above.
   434  * `network/uuid` - See Argument Reference above.
   435  * `network/name` - See Argument Reference above.
   436  * `network/port` - See Argument Reference above.
   437  * `network/fixed_ip_v4` - The Fixed IPv4 address of the Instance on that
   438      network.
   439  * `network/fixed_ip_v6` - The Fixed IPv6 address of the Instance on that
   440      network.
   441  * `network/floating_ip` - The Floating IP address of the Instance on that
   442      network.
   443  * `network/mac` - The MAC address of the NIC on that network.
   444  
   445  ## Notes
   446  
   447  ### Floating IPs
   448  
   449  Floating IPs can be associated in one of two ways:
   450  
   451  * You can specify a Floating IP address by using the top-level `floating_ip`
   452  attribute. This floating IP will be associated with either the network defined
   453  in the first `network` block or the default network if no `network` blocks are
   454  defined.
   455  
   456  * You can specify a Floating IP address by using the `floating_ip` attribute
   457  defined in the `network` block. Each `network` block can have its own floating
   458  IP address.
   459  
   460  Only one of the above methods can be used.
   461  
   462  ### Multiple Ephemeral Disks
   463  
   464  It's possible to specify multiple `block_device` entries to create an instance
   465  with multiple ephemeral (local) disks. In order to create multiple ephemeral
   466  disks, the sum of the total amount of ephemeral space must be less than or
   467  equal to what the chosen flavor supports.
   468  
   469  The following example shows how to create an instance with multiple ephemeral
   470  disks:
   471  
   472  ```
   473  resource "openstack_compute_instance_v2" "foo" {
   474    name = "terraform-test"
   475    security_groups = ["default"]
   476  
   477    block_device {
   478      boot_index = 0
   479      delete_on_termination = true
   480      destination_type = "local"
   481      source_type = "image"
   482      uuid = "<image uuid>"
   483    }
   484  
   485    block_device {
   486      boot_index = -1
   487      delete_on_termination = true
   488      destination_type = "local"
   489      source_type = "blank"
   490      volume_size = 1
   491    }
   492  
   493    block_device {
   494      boot_index = -1
   495      delete_on_termination = true
   496      destination_type = "local"
   497      source_type = "blank"
   498      volume_size = 1
   499    }
   500  }
   501  ```
   502  
   503  ### Instances and Ports
   504  
   505  Neutron Ports are a great feature and provide a lot of functionality. However,
   506  there are some notes to be aware of when mixing Instances and Ports:
   507  
   508  * When attaching an Instance to one or more networks using Ports, place the
   509  security groups on the Port and not the Instance. If you place the security
   510  groups on the Instance, the security groups will not be applied upon creation,
   511  but they will be applied upon a refresh. This is a known OpenStack bug.
   512  
   513  * Network IP information is not available within an instance for networks that
   514  are attached with Ports. This is mostly due to the flexibility Neutron Ports
   515  provide when it comes to IP addresses. For example, a Neutron Port can have
   516  multiple Fixed IP addresses associated with it. It's not possible to know which
   517  single IP address the user would want returned to the Instance's state
   518  information. Therefore, in order for a Provisioner to connect to an Instance
   519  via it's network Port, customize the `connection` information:
   520  
   521  ```
   522  resource "openstack_networking_port_v2" "port_1" {
   523    name = "port_1"
   524    admin_state_up = "true"
   525  
   526    network_id = "0a1d0a27-cffa-4de3-92c5-9d3fd3f2e74d"
   527    security_group_ids = [
   528      "2f02d20a-8dca-49b7-b26f-b6ce9fddaf4f",
   529      "ca1e5ed7-dae8-4605-987b-fadaeeb30461",
   530    ]
   531  
   532  }
   533  
   534  resource "openstack_compute_instance_v2" "instance_1" {
   535    name        = "instance_1"
   536  
   537    network {
   538      port = "${openstack_networking_port_v2.port_1.id}"
   539    }
   540  
   541    connection {
   542      user = "root"
   543      host = "${openstack_networking_port_v2.port_1.fixed_ip.0.ip_address}"
   544      private_key = "~/path/to/key"
   545    }
   546  
   547    provisioner "remote-exec" {
   548      inline = [
   549        "echo terraform executed > /tmp/foo"
   550      ]
   551    }
   552  }
   553  ```