Skip to content

Commit

Permalink
GCLOUD2-11797 security group management updated (#133)
Browse files Browse the repository at this point in the history
GCLOUD2-11417 - some fix in documentations, dual-stack public interface example added to gcore_instancev2
  • Loading branch information
alexk53 authored Sep 17, 2024
1 parent 0d5c4dd commit 16d57fc
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 149 deletions.
4 changes: 2 additions & 2 deletions docs/resources/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "gcore_instance Resource - terraform-provider-gcore"
subcategory: ""
description: |-
Represent instance
Represent instance. WARNING: This resource is deprecated, please use 'gcore_instancev2' instead
---

# gcore_instance (Resource)

Represent instance
Represent instance. **WARNING: This resource is deprecated, please use 'gcore_instancev2' instead**

## Example Usage

Expand Down
128 changes: 85 additions & 43 deletions docs/resources/instancev2.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ resource "gcore_keypair" "my_keypair" {
sshkey_name = "my-keypair"
public_key = "ssh-ed25519 ...your public key... [email protected]"
}
data "gcore_securitygroup" "default" {
name = "default"
project_id = data.gcore_project.project.id
region_id = data.gcore_region.region.id
}
```

### Basic example

#### Creating instance with one public interface

```terraform
resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-with-one-interface" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
Expand All @@ -88,6 +94,7 @@ resource "gcore_instancev2" "instance" {
interface {
type = "external"
name = "my-external-interface"
security_groups = [gcore_securitygroup.default.id]
}
project_id = data.gcore_project.project.id
Expand All @@ -100,7 +107,7 @@ resource "gcore_instancev2" "instance" {
This example demonstrates how to create an instance with two network interfaces: one public and one private.

```terraform
resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-with-two-interface" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
Expand All @@ -113,11 +120,13 @@ resource "gcore_instancev2" "instance" {
interface {
type = "external"
name = "my-external-interface"
security_groups = [gcore_securitygroup.default.id]
}
interface {
type = "subnet"
name = "my-private-interface"
security_groups = [gcore_securitygroup.default.id]
network_id = gcore_network.network.id
subnet_id = gcore_subnet.subnet.id
Expand Down Expand Up @@ -145,7 +154,7 @@ resource "gcore_volume" "boot_volume_windows" {
region_id = data.gcore_region.region.id
}
resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "windows-instance" {
flavor_id = "g1w-standard-4-8"
name = "my-windows-instance"
password = "my-s3cR3tP@ssw0rd"
Expand All @@ -158,6 +167,7 @@ resource "gcore_instancev2" "instance" {
interface {
type = "external"
name = "my-external-interface"
security_groups = [gcore_securitygroup.default.id]
}
project_id = data.gcore_project.project.id
Expand All @@ -167,6 +177,39 @@ resource "gcore_instancev2" "instance" {

### Advanced examples


#### Creating instance with a dual-stack public interface

This example demonstrates how to create an instance with a dual-stack public interface.
The instance has both an IPv4 and an IPv6 address.

```terraform
resource "gcore_instancev2" "instance-with-dualstack" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
volume {
volume_id = gcore_volume.boot_volume.id
boot_index = 0
}
interface {
type = "external"
ip_family = "dual"
name = "my-external-interface"
security_groups = [gcore_securitygroup.default.id]
}
project_id = data.gcore_project.project.id
region_id = data.gcore_region.region.id
}
output "addresses" {
value = gcore_instancev2.instance.addresses
}
```

#### Creating instance with floating ip

```terraform
Expand All @@ -185,7 +228,7 @@ resource "gcore_floatingip" "floating_ip" {
port_id = gcore_reservedfixedip.fixed_ip.port_id
}
resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-with-floating-ip" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
Expand All @@ -201,6 +244,7 @@ resource "gcore_instancev2" "instance" {
port_id = gcore_reservedfixedip.fixed_ip.port_id
existing_fip_id = gcore_floatingip.floating_ip.id
security_groups = [gcore_securitygroup.default.id]
}
project_id = data.gcore_project.project.id
Expand All @@ -217,7 +261,7 @@ resource "gcore_reservedfixedip" "fixed_ip" {
type = "external"
}
resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-with-reserved-address" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
Expand All @@ -231,6 +275,7 @@ resource "gcore_instancev2" "instance" {
type = "reserved_fixed_ip"
name = "my-reserved-public-interface"
port_id = gcore_reservedfixedip.fixed_ip.port_id
security_groups = [gcore_securitygroup.default.id]
}
project_id = data.gcore_project.project.id
Expand Down Expand Up @@ -293,7 +338,7 @@ resource "gcore_securitygroup" "web_server_security_group" {
}
resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-with-custom-security-group" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
Expand Down Expand Up @@ -354,7 +399,7 @@ resource "gcore_volume" "boot_volume_windows" {
region_id = data.gcore_region.region.id
}
resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-windows-with-userdata" {
flavor_id = "g1w-standard-4-8"
name = "my-windows-instance"
password = "my-s3cR3tP@ssw0rd"
Expand All @@ -368,6 +413,7 @@ resource "gcore_instancev2" "instance" {
interface {
type = "external"
name = "my-external-interface"
security_groups = [gcore_securitygroup.default.id]
}
project_id = data.gcore_project.project.id
Expand All @@ -385,14 +431,16 @@ resource "gcore_instancev2" "instance" {
- `interface` (Block Set, Min: 1) List of interfaces for the instance. You can detach the interface from the instance by removing the
interface from the instance resource and attach the interface by adding the interface resource
inside an instance resource. (see [below for nested schema](#nestedblock--interface))
- `volume` (Block Set, Min: 1) List of volumes for the instance. You can detach the volume from the instance by removing the
volume from the instance resource. You cannot detach the boot volume. You can attach a data volume
by adding the volume resource inside an instance resource. (see [below for nested schema](#nestedblock--volume))

### Optional

- `allow_app_ports` (Boolean) If true, application ports will be allowed in the security group for instances created
from the marketplace application template
- `configuration` (Block List) Parameters for the application template from the marketplace (see [below for nested schema](#nestedblock--configuration))
- `keypair_name` (String) Name of the keypair to use for the instance
- `last_updated` (String)
- `metadata_map` (Map of String) Create one or more metadata items for the instance
- `name` (String) Name of the instance.
- `name_template` (String) Instance name template. You can use forms 'ip_octets', 'two_ip_octets', 'one_ip_octet'
Expand All @@ -401,26 +449,23 @@ When only 'password' is provided, it is set as the password for the default user
when 'password' is specified. For Windows instances, 'username' cannot be specified. Use the 'password' field to set
the password for the 'Admin' user on Windows. Use the 'user_data' field to provide a script to create new users
on Windows. The password of the Admin user cannot be updated via 'user_data'
- `project_id` (Number)
- `project_name` (String)
- `region_id` (Number)
- `region_name` (String)
- `project_id` (Number) Project ID, only one of project_id or project_name should be set
- `project_name` (String) Project name, only one of project_id or project_name should be set
- `region_id` (Number) Region ID, only one of region_id or region_name should be set
- `region_name` (String) Region name, only one of region_id or region_name should be set
- `server_group` (String) ID of the server group to use for the instance
- `user_data` (String) String in base64 format. For Linux instances, 'user_data' is ignored when 'password' field is provided.
For Windows instances, Admin user password is set by 'password' field and cannot be updated via 'user_data'
- `username` (String) For Linux instances, 'username' and 'password' are used to create a new user. For Windows
instances, 'username' cannot be specified. Use 'password' field to set the password for the 'Admin' user on Windows.
- `vm_state` (String) Current vm state, use stopped to stop vm and active to start
- `volume` (Block Set) List of volumes for the instance. You can detach the volume from the instance by removing the
volume from the instance resource. You cannot detach the boot volume. You can attach a data volume
by adding the volume resource inside an instance resource. (see [below for nested schema](#nestedblock--volume))

### Read-Only

- `addresses` (List of Object) List of instance addresses (see [below for nested schema](#nestedatt--addresses))
- `flavor` (Map of String) Flavor details, RAM, vCPU, etc.
- `id` (String) The ID of this resource.
- `security_group` (List of Object) Firewalls list, they will be attached globally on all instance's interfaces (see [below for nested schema](#nestedatt--security_group))
- `last_updated` (String)
- `status` (String) Status of the instance

<a id="nestedblock--interface"></a>
Expand All @@ -429,43 +474,49 @@ by adding the volume resource inside an instance resource. (see [below for neste
Required:

- `name` (String) Name of interface, should be unique for the instance
- `security_groups` (List of String) list of security group IDs, they will be attached to exact interface

Optional:

- `existing_fip_id` (String)
- `ip_address` (String)
- `existing_fip_id` (String) The id of the existing floating IP that will be attached to the interface
- `ip_address` (String) IP address for the interface.
- `ip_family` (String) IP family for the interface, available values are 'dual', 'ipv4' and 'ipv6'
- `network_id` (String) required if type is 'subnet' or 'any_subnet'
- `order` (Number) Order of attaching interface
- `port_id` (String) required if type is 'reserved_fixed_ip'
- `security_groups` (List of String) list of security group IDs, they will be attached to exact interface
- `subnet_id` (String) required if type is 'subnet'
- `type` (String) Available value is 'subnet', 'any_subnet', 'external', 'reserved_fixed_ip'


<a id="nestedblock--configuration"></a>
### Nested Schema for `configuration`
<a id="nestedblock--volume"></a>
### Nested Schema for `volume`

Required:

- `key` (String)
- `value` (String)


<a id="nestedblock--volume"></a>
### Nested Schema for `volume`
- `volume_id` (String)

Optional:

- `attachment_tag` (String)
- `boot_index` (Number) If boot_index==0 volumes can not detached
- `delete_on_termination` (Boolean)

Read-Only:

- `attachment_tag` (String) Tag for the volume attachment
- `delete_on_termination` (Boolean) Delete volume on termination
- `id` (String)
- `image_id` (String)
- `name` (String)
- `size` (Number)
- `type_name` (String)
- `volume_id` (String)
- `image_id` (String) Image ID for the volume
- `name` (String) Name of the volume
- `size` (Number) Size of the volume in GiB
- `type_name` (String) Volume type name


<a id="nestedblock--configuration"></a>
### Nested Schema for `configuration`

Required:

- `key` (String)
- `value` (String)


<a id="nestedatt--addresses"></a>
Expand All @@ -485,15 +536,6 @@ Read-Only:



<a id="nestedatt--security_group"></a>
### Nested Schema for `security_group`

Read-Only:

- `id` (String)
- `name` (String)





Expand Down
2 changes: 1 addition & 1 deletion examples/resources/gcore_instancev2/custom-sg.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ resource "gcore_securitygroup" "web_server_security_group" {

}

resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-with-custom-security-group" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
Expand Down
24 changes: 24 additions & 0 deletions examples/resources/gcore_instancev2/dualstack-interface.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
resource "gcore_instancev2" "instance-with-dualstack" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"

volume {
volume_id = gcore_volume.boot_volume.id
boot_index = 0
}

interface {
type = "external"
ip_family = "dual"
name = "my-external-interface"
security_groups = [gcore_securitygroup.default.id]
}

project_id = data.gcore_project.project.id
region_id = data.gcore_region.region.id
}

output "addresses" {
value = gcore_instancev2.instance.addresses
}
3 changes: 2 additions & 1 deletion examples/resources/gcore_instancev2/fip.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resource "gcore_floatingip" "floating_ip" {
port_id = gcore_reservedfixedip.fixed_ip.port_id
}

resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "instance-with-floating-ip" {
flavor_id = "g1-standard-2-4"
name = "my-instance"
keypair_name = "my-keypair"
Expand All @@ -29,6 +29,7 @@ resource "gcore_instancev2" "instance" {
port_id = gcore_reservedfixedip.fixed_ip.port_id

existing_fip_id = gcore_floatingip.floating_ip.id
security_groups = [gcore_securitygroup.default.id]
}

project_id = data.gcore_project.project.id
Expand Down
5 changes: 5 additions & 0 deletions examples/resources/gcore_instancev2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ resource "gcore_keypair" "my_keypair" {
public_key = "ssh-ed25519 ...your public key... [email protected]"
}

data "gcore_securitygroup" "default" {
name = "default"
project_id = data.gcore_project.project.id
region_id = data.gcore_region.region.id
}
3 changes: 2 additions & 1 deletion examples/resources/gcore_instancev2/one-interface-windows.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resource "gcore_volume" "boot_volume_windows" {
region_id = data.gcore_region.region.id
}

resource "gcore_instancev2" "instance" {
resource "gcore_instancev2" "windows-instance" {
flavor_id = "g1w-standard-4-8"
name = "my-windows-instance"
password = "my-s3cR3tP@ssw0rd"
Expand All @@ -26,6 +26,7 @@ resource "gcore_instancev2" "instance" {
interface {
type = "external"
name = "my-external-interface"
security_groups = [gcore_securitygroup.default.id]
}

project_id = data.gcore_project.project.id
Expand Down
Loading

0 comments on commit 16d57fc

Please sign in to comment.