github.com/ottenhoff/terraform@v0.7.0-rc1.0.20160607213102-ac2d195cc560/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.
   231  
   232  * `availability_zone` - (Optional) The availability zone in which to create
   233      the server. Changing this creates a new server.
   234  
   235  * `network` - (Optional) An array of one or more networks to attach to the
   236      instance. The network object structure is documented below. Changing this
   237      creates a new server.
   238  
   239  * `metadata` - (Optional) Metadata key/value pairs to make available from
   240      within the instance. Changing this updates the existing server metadata.
   241  
   242  * `config_drive` - (Optional) Whether to use the config_drive feature to
   243      configure the instance. Changing this creates a new server.
   244  
   245  * `admin_pass` - (Optional) The administrative password to assign to the server.
   246      Changing this changes the root password on the existing server.
   247  
   248  * `key_pair` - (Optional) The name of a key pair to put on the server. The key
   249      pair must already be created and associated with the tenant's account.
   250      Changing this creates a new server.
   251  
   252  * `block_device` - (Optional) The object for booting by volume. The block_device
   253      object structure is documented below. Changing this creates a new server.
   254      You can specify multiple block devices which will create an instance with
   255      multiple ephemeral (local) disks.
   256  
   257  * `volume` - (Optional) Attach an existing volume to the instance. The volume
   258      structure is described below.
   259  
   260  * `scheduler_hints` - (Optional) Provide the Nova scheduler with hints on how
   261      the instance should be launched. The available hints are described below.
   262  
   263  * `personality` - (Optional) Customize the personality of an instance by
   264      defining one or more files and their contents. The personality structure
   265      is described below.
   266  
   267  The `network` block supports:
   268  
   269  * `uuid` - (Required unless `port`  or `name` is provided) The network UUID to
   270      attach to the server. Changing this creates a new server.
   271  
   272  * `name` - (Required unless `uuid` or `port` is provided) The human-readable
   273      name of the network. Changing this creates a new server.
   274  
   275  * `port` - (Required unless `uuid` or `name` is provided) The port UUID of a
   276      network to attach to the server. Changing this creates a new server.
   277  
   278  * `fixed_ip_v4` - (Optional) Specifies a fixed IPv4 address to be used on this
   279      network. Changing this creates a new server.
   280  
   281  * `fixed_ip_v6` - (Optional) Specifies a fixed IPv6 address to be used on this
   282      network. Changing this creates a new server.
   283  
   284  * `floating_ip` - (Optional) Specifies a floating IP address to be associated
   285      with this network. Cannot be combined with a top-level floating IP. See
   286      *Notes* for more information about Floating IPs.
   287  
   288  * `access_network` - (Optional) Specifies if this network should be used for
   289      provisioning access. Accepts true or false. Defaults to false.
   290  
   291  The `block_device` block supports:
   292  
   293  * `uuid` - (Required unless `source_type` is set to `"blank"` ) The UUID of
   294      the image, volume, or snapshot. Changing this creates a new server.
   295  
   296  * `source_type` - (Required) The source type of the device. Must be one of
   297      "blank", "image", "volume", or "snapshot". Changing this creates a new
   298      server.
   299  
   300  * `volume_size` - The size of the volume to create (in gigabytes). Required
   301      in the following combinations: source=image and destination=volume,
   302      source=blank and destination=local. Changing this creates a new server.
   303  
   304  * `boot_index` - (Optional) The boot index of the volume. It defaults to 0.
   305      Changing this creates a new server.
   306  
   307  * `destination_type` - (Optional) The type that gets created. Possible values
   308      are "volume" and "local". Changing this creates a new server.
   309  
   310  * `delete_on_termination` - (Optional) Delete the volume / block device upon
   311      termination of the instance. Defaults to false. Changing this creates a
   312      new server.
   313  
   314  The `volume` block supports:
   315  
   316  * `volume_id` - (Required) The UUID of the volume to attach.
   317  
   318  * `device` - (Optional) The device that the volume will be attached as. For
   319      example:  `/dev/vdc`. Omit this option to allow the volume to be
   320      auto-assigned a device.
   321  
   322  The `scheduler_hints` block supports:
   323  
   324  * `group` - (Optional) A UUID of a Server Group. The instance will be placed
   325      into that group.
   326  
   327  * `different_host` - (Optional) A list of instance UUIDs. The instance will
   328      be scheduled on a different host than all other instances.
   329  
   330  * `same_host` - (Optional) A list of instance UUIDs. The instance will be
   331      scheduled on the same host of those specified.
   332  
   333  * `query` - (Optional) A conditional query that a compute node must pass in
   334      order to host an instance.
   335  
   336  * `target_cell` - (Optional) The name of a cell to host the instance.
   337  
   338  * `build_near_host_ip` - (Optional) An IP Address in CIDR form. The instance
   339      will be placed on a compute node that is in the same subnet.
   340  
   341  The `personality` block supports:
   342  
   343  * `file` - (Required) The absolute path of the destination file.
   344  
   345  * `contents` - (Required) The contents of the file. Limited to 255 bytes.
   346  
   347  ## Attributes Reference
   348  
   349  The following attributes are exported:
   350  
   351  * `region` - See Argument Reference above.
   352  * `name` - See Argument Reference above.
   353  * `access_ip_v4` - The first detected Fixed IPv4 address _or_ the
   354      Floating IP.
   355  * `access_ip_v6` - The first detected Fixed IPv6 address.
   356  * `metadata` - See Argument Reference above.
   357  * `security_groups` - See Argument Reference above.
   358  * `flavor_id` - See Argument Reference above.
   359  * `flavor_name` - See Argument Reference above.
   360  * `network/uuid` - See Argument Reference above.
   361  * `network/name` - See Argument Reference above.
   362  * `network/port` - See Argument Reference above.
   363  * `network/fixed_ip_v4` - The Fixed IPv4 address of the Instance on that
   364      network.
   365  * `network/fixed_ip_v6` - The Fixed IPv6 address of the Instance on that
   366      network.
   367  * `network/floating_ip` - The Floating IP address of the Instance on that
   368      network.
   369  * `network/mac` - The MAC address of the NIC on that network.
   370  
   371  ## Notes
   372  
   373  ### Floating IPs
   374  
   375  Floating IPs can be associated in one of two ways:
   376  
   377  * You can specify a Floating IP address by using the top-level `floating_ip`
   378  attribute. This floating IP will be associated with either the network defined
   379  in the first `network` block or the default network if no `network` blocks are
   380  defined.
   381  
   382  * You can specify a Floating IP address by using the `floating_ip` attribute
   383  defined in the `network` block. Each `network` block can have its own floating
   384  IP address.
   385  
   386  Only one of the above methods can be used.
   387  
   388  ### Multiple Ephemeral Disks
   389  
   390  It's possible to specify multiple `block_device` entries to create an instance
   391  with multiple ephemeral (local) disks. In order to create multiple ephemeral
   392  disks, the sum of the total amount of ephemeral space must be less than or
   393  equal to what the chosen flavor supports.
   394  
   395  The following example shows how to create an instance with multiple ephemeral
   396  disks:
   397  
   398  ```
   399  resource "openstack_compute_instance_v2" "foo" {
   400    name = "terraform-test"
   401    security_groups = ["default"]
   402  
   403    block_device {
   404      boot_index = 0
   405      delete_on_termination = true
   406      destination_type = "local"
   407      source_type = "image"
   408      uuid = "<image uuid>"
   409    }
   410  
   411    block_device {
   412      boot_index = -1
   413      delete_on_termination = true
   414      destination_type = "local"
   415      source_type = "blank"
   416      volume_size = 1
   417    }
   418  
   419    block_device {
   420      boot_index = -1
   421      delete_on_termination = true
   422      destination_type = "local"
   423      source_type = "blank"
   424      volume_size = 1
   425    }
   426  }
   427  ```