github.com/sixgill/terraform@v0.9.0-beta2.0.20170316214032-033f6226ae50/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  * `force_delete` - (Optional) Whether to force the OpenStack instance to be
   341      forcefully deleted. This is useful for environments that have reclaim / soft
   342      deletion enabled.
   343  
   344  
   345  The `network` block supports:
   346  
   347  * `uuid` - (Required unless `port`  or `name` is provided) The network UUID to
   348      attach to the server. Changing this creates a new server.
   349  
   350  * `name` - (Required unless `uuid` or `port` is provided) The human-readable
   351      name of the network. Changing this creates a new server.
   352  
   353  * `port` - (Required unless `uuid` or `name` is provided) The port UUID of a
   354      network to attach to the server. Changing this creates a new server.
   355  
   356  * `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this
   357      network. Changing this creates a new server.
   358  
   359  * `fixed_ip_v6` - (Optional) Specifies a fixed IPv6 address to be used on this
   360      network. Changing this creates a new server.
   361  
   362  * `floating_ip` - (Optional) Specifies a floating IP address to be associated
   363      with this network. Cannot be combined with a top-level floating IP. See
   364      *Notes* for more information about Floating IPs.
   365  
   366  * `access_network` - (Optional) Specifies if this network should be used for
   367      provisioning access. Accepts true or false. Defaults to false.
   368  
   369  The `block_device` block supports:
   370  
   371  * `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of
   372      the image, volume, or snapshot. Changing this creates a new server.
   373  
   374  * `source_type` - (Required) The source type of the device. Must be one of
   375      "blank", "image", "volume", or "snapshot". Changing this creates a new
   376      server.
   377  
   378  * `volume_size` - The size of the volume to create (in gigabytes). Required
   379      in the following combinations: source=image and destination=volume,
   380      source=blank and destination=local, and source=blank and destination=volume.
   381      Changing this creates a new server.
   382  
   383  * `boot_index` - (Optional) The boot index of the volume. It defaults to 0.
   384      Changing this creates a new server.
   385  
   386  * `destination_type` - (Optional) The type that gets created. Possible values
   387      are "volume" and "local". Changing this creates a new server.
   388  
   389  * `delete_on_termination` - (Optional) Delete the volume / block device upon
   390      termination of the instance. Defaults to false. Changing this creates a
   391      new server.
   392  
   393  The `volume` block supports:
   394  
   395  * `volume_id` - (Required) The UUID of the volume to attach.
   396  
   397  * `device` - (Optional) The device that the volume will be attached as. For
   398      example:  `/dev/vdc`. Omit this option to allow the volume to be
   399      auto-assigned a device.
   400  
   401  The `scheduler_hints` block supports:
   402  
   403  * `group` - (Optional) A UUID of a Server Group. The instance will be placed
   404      into that group.
   405  
   406  * `different_host` - (Optional) A list of instance UUIDs. The instance will
   407      be scheduled on a different host than all other instances.
   408  
   409  * `same_host` - (Optional) A list of instance UUIDs. The instance will be
   410      scheduled on the same host of those specified.
   411  
   412  * `query` - (Optional) A conditional query that a compute node must pass in
   413      order to host an instance.
   414  
   415  * `target_cell` - (Optional) The name of a cell to host the instance.
   416  
   417  * `build_near_host_ip` - (Optional) An IP Address in CIDR form. The instance
   418      will be placed on a compute node that is in the same subnet.
   419  
   420  The `personality` block supports:
   421  
   422  * `file` - (Required) The absolute path of the destination file.
   423  
   424  * `contents` - (Required) The contents of the file. Limited to 255 bytes.
   425  
   426  ## Attributes Reference
   427  
   428  The following attributes are exported:
   429  
   430  * `region` - See Argument Reference above.
   431  * `name` - See Argument Reference above.
   432  * `access_ip_v4` - The first detected Fixed IPv4 address _or_ the
   433      Floating IP.
   434  * `access_ip_v6` - The first detected Fixed IPv6 address.
   435  * `metadata` - See Argument Reference above.
   436  * `security_groups` - See Argument Reference above.
   437  * `flavor_id` - See Argument Reference above.
   438  * `flavor_name` - See Argument Reference above.
   439  * `network/uuid` - See Argument Reference above.
   440  * `network/name` - See Argument Reference above.
   441  * `network/port` - See Argument Reference above.
   442  * `network/fixed_ip_v4` - The Fixed IPv4 address of the Instance on that
   443      network.
   444  * `network/fixed_ip_v6` - The Fixed IPv6 address of the Instance on that
   445      network.
   446  * `network/floating_ip` - The Floating IP address of the Instance on that
   447      network.
   448  * `network/mac` - The MAC address of the NIC on that network.
   449  
   450  ## Notes
   451  
   452  ### Floating IPs
   453  
   454  Floating IPs can be associated in one of two ways:
   455  
   456  * You can specify a Floating IP address by using the top-level `floating_ip`
   457  attribute. This floating IP will be associated with either the network defined
   458  in the first `network` block or the default network if no `network` blocks are
   459  defined.
   460  
   461  * You can specify a Floating IP address by using the `floating_ip` attribute
   462  defined in the `network` block. Each `network` block can have its own floating
   463  IP address.
   464  
   465  Only one of the above methods can be used.
   466  
   467  ### Multiple Ephemeral Disks
   468  
   469  It's possible to specify multiple `block_device` entries to create an instance
   470  with multiple ephemeral (local) disks. In order to create multiple ephemeral
   471  disks, the sum of the total amount of ephemeral space must be less than or
   472  equal to what the chosen flavor supports.
   473  
   474  The following example shows how to create an instance with multiple ephemeral
   475  disks:
   476  
   477  ```
   478  resource "openstack_compute_instance_v2" "foo" {
   479    name            = "terraform-test"
   480    security_groups = ["default"]
   481  
   482    block_device {
   483      boot_index            = 0
   484      delete_on_termination = true
   485      destination_type      = "local"
   486      source_type           = "image"
   487      uuid                  = "<image uuid>"
   488    }
   489  
   490    block_device {
   491      boot_index            = -1
   492      delete_on_termination = true
   493      destination_type      = "local"
   494      source_type           = "blank"
   495      volume_size           = 1
   496    }
   497  
   498    block_device {
   499      boot_index            = -1
   500      delete_on_termination = true
   501      destination_type      = "local"
   502      source_type           = "blank"
   503      volume_size           = 1
   504    }
   505  }
   506  ```
   507  
   508  ### Instances and Ports
   509  
   510  Neutron Ports are a great feature and provide a lot of functionality. However,
   511  there are some notes to be aware of when mixing Instances and Ports:
   512  
   513  * When attaching an Instance to one or more networks using Ports, place the
   514  security groups on the Port and not the Instance. If you place the security
   515  groups on the Instance, the security groups will not be applied upon creation,
   516  but they will be applied upon a refresh. This is a known OpenStack bug.
   517  
   518  * Network IP information is not available within an instance for networks that
   519  are attached with Ports. This is mostly due to the flexibility Neutron Ports
   520  provide when it comes to IP addresses. For example, a Neutron Port can have
   521  multiple Fixed IP addresses associated with it. It's not possible to know which
   522  single IP address the user would want returned to the Instance's state
   523  information. Therefore, in order for a Provisioner to connect to an Instance
   524  via it's network Port, customize the `connection` information:
   525  
   526  ```
   527  resource "openstack_networking_port_v2" "port_1" {
   528    name           = "port_1"
   529    admin_state_up = "true"
   530  
   531    network_id = "0a1d0a27-cffa-4de3-92c5-9d3fd3f2e74d"
   532  
   533    security_group_ids = [
   534      "2f02d20a-8dca-49b7-b26f-b6ce9fddaf4f",
   535      "ca1e5ed7-dae8-4605-987b-fadaeeb30461",
   536    ]
   537  }
   538  
   539  resource "openstack_compute_instance_v2" "instance_1" {
   540    name = "instance_1"
   541  
   542    network {
   543      port = "${openstack_networking_port_v2.port_1.id}"
   544    }
   545  
   546    connection {
   547      user        = "root"
   548      host        = "${openstack_networking_port_v2.port_1.fixed_ip.0.ip_address}"
   549      private_key = "~/path/to/key"
   550    }
   551  
   552    provisioner "remote-exec" {
   553      inline = [
   554        "echo terraform executed > /tmp/foo",
   555      ]
   556    }
   557  }
   558  ```