github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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. *Note*: When attaching the
   231      instance to networks using Ports, place the security groups on the Port
   232      and not the instance.
   233  
   234  * `availability_zone` - (Optional) The availability zone in which to create
   235      the server. Changing this creates a new server.
   236  
   237  * `network` - (Optional) An array of one or more networks to attach to the
   238      instance. The network object structure is documented below. Changing this
   239      creates a new server.
   240  
   241  * `metadata` - (Optional) Metadata key/value pairs to make available from
   242      within the instance. Changing this updates the existing server metadata.
   243  
   244  * `config_drive` - (Optional) Whether to use the config_drive feature to
   245      configure the instance. Changing this creates a new server.
   246  
   247  * `admin_pass` - (Optional) The administrative password to assign to the server.
   248      Changing this changes the root password on the existing server.
   249  
   250  * `key_pair` - (Optional) The name of a key pair to put on the server. The key
   251      pair must already be created and associated with the tenant's account.
   252      Changing this creates a new server.
   253  
   254  * `block_device` - (Optional) The object for booting by volume. The block_device
   255      object structure is documented below. Changing this creates a new server.
   256      You can specify multiple block devices which will create an instance with
   257      multiple ephemeral (local) disks.
   258  
   259  * `volume` - (Optional) Attach an existing volume to the instance. The volume
   260      structure is described below.
   261  
   262  * `scheduler_hints` - (Optional) Provide the Nova scheduler with hints on how
   263      the instance should be launched. The available hints are described below.
   264  
   265  * `personality` - (Optional) Customize the personality of an instance by
   266      defining one or more files and their contents. The personality structure
   267      is described below.
   268  
   269  * `stop_before_destroy` - (Optional) Whether to try stop instance gracefully
   270      before destroying it, thus giving chance for guest OS daemons to stop correctly.
   271      If instance doesn't stop within timeout, it will be destroyed anyway.
   272  
   273  
   274  The `network` block supports:
   275  
   276  * `uuid` - (Required unless `port`  or `name` is provided) The network UUID to
   277      attach to the server. Changing this creates a new server.
   278  
   279  * `name` - (Required unless `uuid` or `port` is provided) The human-readable
   280      name of the network. Changing this creates a new server.
   281  
   282  * `port` - (Required unless `uuid` or `name` is provided) The port UUID of a
   283      network to attach to the server. Changing this creates a new server.
   284  
   285  * `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this
   286      network. Changing this creates a new server.
   287  
   288  * `fixed_ip_v6` - (Optional) Specifies a fixed IPv6 address to be used on this
   289      network. Changing this creates a new server.
   290  
   291  * `floating_ip` - (Optional) Specifies a floating IP address to be associated
   292      with this network. Cannot be combined with a top-level floating IP. See
   293      *Notes* for more information about Floating IPs.
   294  
   295  * `access_network` - (Optional) Specifies if this network should be used for
   296      provisioning access. Accepts true or false. Defaults to false.
   297  
   298  The `block_device` block supports:
   299  
   300  * `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of
   301      the image, volume, or snapshot. Changing this creates a new server.
   302  
   303  * `source_type` - (Required) The source type of the device. Must be one of
   304      "blank", "image", "volume", or "snapshot". Changing this creates a new
   305      server.
   306  
   307  * `volume_size` - The size of the volume to create (in gigabytes). Required
   308      in the following combinations: source=image and destination=volume,
   309      source=blank and destination=local. Changing this creates a new server.
   310  
   311  * `boot_index` - (Optional) The boot index of the volume. It defaults to 0.
   312      Changing this creates a new server.
   313  
   314  * `destination_type` - (Optional) The type that gets created. Possible values
   315      are "volume" and "local". Changing this creates a new server.
   316  
   317  * `delete_on_termination` - (Optional) Delete the volume / block device upon
   318      termination of the instance. Defaults to false. Changing this creates a
   319      new server.
   320  
   321  The `volume` block supports:
   322  
   323  * `volume_id` - (Required) The UUID of the volume to attach.
   324  
   325  * `device` - (Optional) The device that the volume will be attached as. For
   326      example:  `/dev/vdc`. Omit this option to allow the volume to be
   327      auto-assigned a device.
   328  
   329  The `scheduler_hints` block supports:
   330  
   331  * `group` - (Optional) A UUID of a Server Group. The instance will be placed
   332      into that group.
   333  
   334  * `different_host` - (Optional) A list of instance UUIDs. The instance will
   335      be scheduled on a different host than all other instances.
   336  
   337  * `same_host` - (Optional) A list of instance UUIDs. The instance will be
   338      scheduled on the same host of those specified.
   339  
   340  * `query` - (Optional) A conditional query that a compute node must pass in
   341      order to host an instance.
   342  
   343  * `target_cell` - (Optional) The name of a cell to host the instance.
   344  
   345  * `build_near_host_ip` - (Optional) An IP Address in CIDR form. The instance
   346      will be placed on a compute node that is in the same subnet.
   347  
   348  The `personality` block supports:
   349  
   350  * `file` - (Required) The absolute path of the destination file.
   351  
   352  * `contents` - (Required) The contents of the file. Limited to 255 bytes.
   353  
   354  ## Attributes Reference
   355  
   356  The following attributes are exported:
   357  
   358  * `region` - See Argument Reference above.
   359  * `name` - See Argument Reference above.
   360  * `access_ip_v4` - The first detected Fixed IPv4 address _or_ the
   361      Floating IP.
   362  * `access_ip_v6` - The first detected Fixed IPv6 address.
   363  * `metadata` - See Argument Reference above.
   364  * `security_groups` - See Argument Reference above.
   365  * `flavor_id` - See Argument Reference above.
   366  * `flavor_name` - See Argument Reference above.
   367  * `network/uuid` - See Argument Reference above.
   368  * `network/name` - See Argument Reference above.
   369  * `network/port` - See Argument Reference above.
   370  * `network/fixed_ip_v4` - The Fixed IPv4 address of the Instance on that
   371      network.
   372  * `network/fixed_ip_v6` - The Fixed IPv6 address of the Instance on that
   373      network.
   374  * `network/floating_ip` - The Floating IP address of the Instance on that
   375      network.
   376  * `network/mac` - The MAC address of the NIC on that network.
   377  
   378  ## Notes
   379  
   380  ### Floating IPs
   381  
   382  Floating IPs can be associated in one of two ways:
   383  
   384  * You can specify a Floating IP address by using the top-level `floating_ip`
   385  attribute. This floating IP will be associated with either the network defined
   386  in the first `network` block or the default network if no `network` blocks are
   387  defined.
   388  
   389  * You can specify a Floating IP address by using the `floating_ip` attribute
   390  defined in the `network` block. Each `network` block can have its own floating
   391  IP address.
   392  
   393  Only one of the above methods can be used.
   394  
   395  ### Multiple Ephemeral Disks
   396  
   397  It's possible to specify multiple `block_device` entries to create an instance
   398  with multiple ephemeral (local) disks. In order to create multiple ephemeral
   399  disks, the sum of the total amount of ephemeral space must be less than or
   400  equal to what the chosen flavor supports.
   401  
   402  The following example shows how to create an instance with multiple ephemeral
   403  disks:
   404  
   405  ```
   406  resource "openstack_compute_instance_v2" "foo" {
   407    name = "terraform-test"
   408    security_groups = ["default"]
   409  
   410    block_device {
   411      boot_index = 0
   412      delete_on_termination = true
   413      destination_type = "local"
   414      source_type = "image"
   415      uuid = "<image uuid>"
   416    }
   417  
   418    block_device {
   419      boot_index = -1
   420      delete_on_termination = true
   421      destination_type = "local"
   422      source_type = "blank"
   423      volume_size = 1
   424    }
   425  
   426    block_device {
   427      boot_index = -1
   428      delete_on_termination = true
   429      destination_type = "local"
   430      source_type = "blank"
   431      volume_size = 1
   432    }
   433  }
   434  ```
   435  
   436  ### Instances and Ports
   437  
   438  Neutron Ports are a great feature and provide a lot of functionality. However,
   439  there are some notes to be aware of when mixing Instances and Ports:
   440  
   441  * When attaching an Instance to one or more networks using Ports, place the
   442  security groups on the Port and not the Instance. If you place the security
   443  groups on the Instance, the security groups will not be applied upon creation,
   444  but they will be applied upon a refresh. This is a known OpenStack bug.
   445  
   446  * Network IP information is not available within an instance for networks that
   447  are attached with Ports. This is mostly due to the flexibility Neutron Ports
   448  provide when it comes to IP addresses. For example, a Neutron Port can have
   449  multiple Fixed IP addresses associated with it. It's not possible to know which
   450  single IP address the user would want returned to the Instance's state
   451  information. Therefore, in order for a Provisioner to connect to an Instance
   452  via it's network Port, customize the `connection` information:
   453  
   454  ```
   455  resource "openstack_networking_port_v2" "port_1" {
   456    name = "port_1"
   457    admin_state_up = "true"
   458  
   459    network_id = "0a1d0a27-cffa-4de3-92c5-9d3fd3f2e74d"
   460    security_group_ids = [
   461      "2f02d20a-8dca-49b7-b26f-b6ce9fddaf4f",
   462      "ca1e5ed7-dae8-4605-987b-fadaeeb30461",
   463    ]
   464  
   465  }
   466  
   467  resource "openstack_compute_instance_v2" "instance_1" {
   468    name        = "instance_1"
   469  
   470    network {
   471      port = "${openstack_networking_port_v2.port_1.id}"
   472    }
   473  
   474    connection {
   475      user = "root"
   476      host = "${openstack_networking_port_v2.port_1.fixed_ip.0.ip_address}"
   477      private_key = "~/path/to/key"
   478    }
   479  
   480    provisioner "remote-exec" {
   481      inline = [
   482        "echo terraform executed > /tmp/foo"
   483      ]
   484    }
   485  }
   486  ```