<commit_before>---
layout: "openstack"
page_title: "OpenStack: openstack_compute_instance_v2"
sidebar_current: "docs-openstack-resource-compute-instance-v2"
description: |-
  Manages a V2 VM instance resource within OpenStack.
---

# openstack\_compute\_instance_v2

Manages a V2 VM instance resource within OpenStack.

## Example Usage

```
resource "openstack_compute_instance_v2" "test-server" {
  name = "tf-test"
  image_ref = "ad091b52-742f-469e-8f3c-fd81cadf0743"
  flavor_ref = "3"
  metadata {
    this = "that"
  }
  key_pair = "my_key_pair_name"
  security_groups = ["test-group-1"]
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Required) The region in which to create the server instance. If
    omitted, the `OS_REGION_NAME` environment variable is used. Changing this
    creates a new server.

* `name` - (Required) A unique name for the resource.

* `image_ref` - (Required) The image reference (ID) for the desired image for
    the server. Changing this creates a new server.

* `flavor_ref` - (Required) The flavor reference (ID) for the desired flavor
    for the server. Changing this resizes the existing server.

* `security_groups` - (Optional) An array of one or more security group names
    to associate with the server. Changing this results in adding/removing
    security groups from the existing server.

* `availability_zone` - (Optional) The availability zone in which to create
    the server. Changing this creates a new server.

* `network` - (Optional) An array of one or more networks to attach to the
    instance. The network object structure is documented below. Changing this<commit_msg>Updated documentation to reflect the image_ref / image_id change.<commit_after>---
layout: "openstack"
page_title: "OpenStack: openstack_compute_instance_v2"
sidebar_current: "docs-openstack-resource-compute-instance-v2"
description: |-
  Manages a V2 VM instance resource within OpenStack.
---

# openstack\_compute\_instance_v2

Manages a V2 VM instance resource within OpenStack.

## Example Usage

```
resource "openstack_compute_instance_v2" "test-server" {
  name = "tf-test"
  image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743"
  flavor_ref = "3"
  metadata {
    this = "that"
  }
  key_pair = "my_key_pair_name"
  security_groups = ["test-group-1"]
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Required) The region in which to create the server instance. If
    omitted, the `OS_REGION_NAME` environment variable is used. Changing this
    creates a new server.

* `name` - (Required) A unique name for the resource.

* `image_id` - (Required) The image reference (ID) for the desired image for
    the server. Changing this creates a new server. Note that `image_id` and
    `image_name` are mutually exclusive.

* `image_name` - (Required) The image name for the server. Changing this
   creates a new server. Note that `image_id` and `image_name` are mutually
   exclusive.

* `flavor_ref` - (Required) The flavor reference (ID) for the desired flavor
    for the server. Changing this resizes the existing server.

* `security_groups` - (Optional) An array of one or more security group names
    to associate with the server. Changing this results in adding/removing
    security groups from the existing server.

* `availability_zone` - (Optional) The availability zone in which to create
    the server. Changing this creates a new server.

* `network` - (Optional) An array of one or more networks to attach to the
    instance. The network object structure is documented below. Changing this
{'fraction_non_alphanumeric': 0.08467072495849474, 'fraction_numerical': 0.014941892639734366, 'mean_word_length': 4.027816411682893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6037489', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1058, 'n_words': 414}