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