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