Skip to content

feat(ECS): Synchronized ECS resources, unit test and document. #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 72 additions & 86 deletions docs/resources/compute_interface_attach_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,130 +6,115 @@ page_title: "flexibleengine_compute_interface_attach_v2"

# flexibleengine_compute_interface_attach_v2

Attaches a Network Interface (a Port) to an Instance using the FlexibleEngine
Compute (Nova) v2 API.
Attaches a Network Interface (a Port) to an Instance using the FlexibleEngine Compute (Nova) v2 API.

## Example Usage

### Basic Attachment
### Attach a port (under the specified network) to the ECS instance and generate a random IP address

```hcl
resource "flexibleengine_vpc_v1" "example_vpc" {
name = "example-vpc"
cidr = "192.168.0.0/16"
}

resource "flexibleengine_vpc_subnet_v1" "example_subnet" {
name = "example-vpc-subnet"
cidr = "192.168.0.0/24"
gateway_ip = "192.168.0.1"
vpc_id = flexibleengine_vpc_v1.example_vpc.id
}

resource "flexibleengine_compute_instance_v2" "example_instance" {
name = "example-instance"
security_groups = ["default"]
}
variable "instance_id" {}
variable "network_id" {}

resource "flexibleengine_compute_interface_attach_v2" "example_interface_attach" {
instance_id = flexibleengine_compute_instance_v2.example_instance.id
network_id = flexibleengine_vpc_subnet_v1.example_subnet.id
resource "flexibleengine_compute_interface_attach_v2" "test" {
instance_id = var.instance_id
network_id = var.network_id
}

```

### Attachment Specifying a Fixed IP

```hcl
resource "flexibleengine_compute_interface_attach_v2" "example_interface_attach" {
instance_id = flexibleengine_compute_instance_v2.example_instance.id
network_id = flexibleengine_vpc_subnet_v1.example_subnet.id
fixed_ip = "10.0.10.10"
}

```

### Attachment Using an Existing Port
### Attach a port (under the specified network) to the ECS instance and use the custom security groups

```hcl
resource "flexibleengine_networking_port_v2" "example_port" {
name = "port_1"
network_id = flexibleengine_vpc_subnet_v1.example_subnet.id
admin_state_up = "true"
variable "instance_id" {}
variable "network_id" {}
variable "security_group_ids" {
type = list(string)
}

resource "flexibleengine_compute_interface_attach_v2" "example_interface_attach" {
instance_id = flexibleengine_compute_instance_v2.example_instance.id
port_id = flexibleengine_networking_port_v2.example_port.id
resource "flexibleengine_compute_interface_attach_v2" "test" {
instance_id = var.instance_id
network_id = var.network_id
fixed_ip = "192.168.10.199"
security_group_ids = var.security_group_ids
}

```

### Attaching Multiple Interfaces
### Attach a custom port to the ECS instance

```hcl
resource "flexibleengine_networking_port_v2" "example_ports" {
count = 2
name = format("port-%02d", count.index + 1)
network_id = flexibleengine_vpc_subnet_v1.example_subnet.id
admin_state_up = "true"
}
variable "security_group_id" {}

resource "flexibleengine_compute_interface_attach_v2" "example_attachments" {
count = 2
instance_id = flexibleengine_compute_instance_v2.example_instance.id
port_id = flexibleengine_networking_port_v2.example_ports.*.id[count.index]
resource "flexibleengine_vpc_v1" "vpc_1" {
name = "test_vpc"
cidr = "192.168.0.0/16"
}
```

Note that the above example will not guarantee that the ports are attached in
a deterministic manner. The ports will be attached in a seemingly random
order.

If you want to ensure that the ports are attached in a given order, create
explicit dependencies between the ports, such as:
resource "flexibleengine_vpc_subnet_v1" "mynet" {
name = "test_subnet"
cidr = "192.168.0.0/24"
gateway_ip = "192.168.0.1"
vpc_id = flexibleengine_vpc_v1.vpc_1.id
}

```hcl
resource "flexibleengine_networking_port_v2" "example_ports" {
count = 2
name = format("port-%02d", count.index + 1)
network_id = flexibleengine_vpc_subnet_v1.example_subnet.id
admin_state_up = "true"
data "flexibleengine_networking_port" "myport" {
network_id = flexibleengine_vpc_subnet_v1.mynet.id
fixed_ip = "192.168.0.100"
}

resource "flexibleengine_compute_interface_attach_v2" "example_interface_attach_1" {
instance_id = flexibleengine_compute_instance_v2.instance_1.id
port_id = flexibleengine_networking_port_v2.example_ports.*.id[0]
resource "flexibleengine_compute_instance_v2" "myinstance" {
name = "instance"
image_id = "ad091b52-742f-469e-8f3c-fd81cadf0743"
flavor_id = "s3.large.2"
key_pair = "my_key_pair_name"
security_groups = [flexibleengine_networking_secgroup_v2.test.name]
availability_zone = "eu-west-0a"

network {
uuid = flexibleengine_vpc_subnet_v1.mynet.id
}
}

resource "flexibleengine_compute_interface_attach_v2" "example_interface_attach_2" {
instance_id = flexibleengine_compute_instance_v2.instance_1.id
port_id = flexibleengine_networking_port_v2.example_ports.*.id[1]
resource "flexibleengine_compute_interface_attach_v2" "attached" {
instance_id = flexibleengine_compute_instance_v2.myinstance.id
port_id = data.flexibleengine_networking_port.myport.id
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) The region in which to create the interface attachment.
If omitted, the `region` argument of the provider is used. Changing this creates a new attachment.
* `region` - (Optional, String, ForceNew) The region in which to create the network interface attache resource. If
omitted, the provider-level region will be used. Changing this creates a new network interface attache resource.

* `instance_id` - (Required, String, ForceNew) The ID of the Instance to attach the Port or Network to. Changing this
will create a new resource.

* `port_id` - (Optional, String, ForceNew) The ID of the Port to attach to an Instance. This option and `network_id` are
mutually exclusive. Changing this will create a new resource.

* `network_id` - (Optional, String, ForceNew) The ID of the Network to attach to an Instance. A port will be created
automatically. This option and `port_id` are mutually exclusive. Changing this creates a new resource.

* `instance_id` - (Required, String, ForceNew) The ID of the Instance to attach the Port or Network to.
* `fixed_ip` - (Optional, String, ForceNew) An IP address to associate with the port. Changing this creates a new resource.

* `port_id` - (Optional, String, ForceNew) The ID of the Port to attach to an Instance.
This option and `network_id` are mutually exclusive.
->This option cannot be used with port_id. You must specify a network_id. The IP address must lie in a range on the
supplied network.

* `network_id` - (Optional, String, ForceNew) The ID of the Network to attach to an Instance.
A port will be created automatically. This option and `port_id` are mutually exclusive.
* `source_dest_check` - (Optional, Bool) Specifies whether the ECS processes only traffic that is destined specifically
for it. This function is enabled by default but should be disabled if the ECS functions as a SNAT server or has a
virtual IP address bound to it.

* `fixed_ip` - (Optional, String, ForceNew) An IP address to associate with the port.
This option cannot be used with port_id. You must specify a network_id.
The IP address must lie in a range on the supplied network.
* `security_group_ids` - (Optional, List) Specifies the list of security group IDs bound to the specified port.
Defaults to the default security group.

## Attribute Reference

All the arguments above can also be exported attributes.
In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID in format of ECS instance ID and port ID separated by a slash.
* `mac` - The MAC address of the NIC.

## Timeouts

Expand All @@ -140,9 +125,10 @@ This resource provides the following timeouts configuration options:

## Import

Interface Attachments can be imported using the Instance ID and Port ID
separated by a slash, e.g.
Interface Attachments can be imported using the Instance ID and Port ID separated by a slash, e.g.

```shell
terraform import flexibleengine_compute_interface_attach_v2.ai_1 89c60255-9bd6-460c-822a-e2b959ede9d2/45670584-225f-46c3-b33e-6707b589b666
$ terraform import flexibleengine_compute_interface_attach_v2.ai_1 89c60255-9bd6-460c-822a-e2b959ede9d2/45670584-225f-46c3-b33e-6707b589b666
```

```
Loading