Skip to content
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

resource/alicloud_ecs_network_interface: Added the field instance_type, network_interface_traffic_mode #7181

Merged
merged 1 commit into from
Apr 26, 2024
Merged
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
4 changes: 2 additions & 2 deletions alicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ func Provider() terraform.ResourceProvider {
"alicloud_ram_role_attachment": resourceAlicloudRamRoleAttachment(),
"alicloud_disk": resourceAlicloudEcsDisk(),
"alicloud_disk_attachment": resourceAlicloudEcsDiskAttachment(),
"alicloud_network_interface": resourceAlicloudEcsNetworkInterface(),
"alicloud_network_interface": resourceAliCloudEcsNetworkInterface(),
"alicloud_network_interface_attachment": resourceAlicloudEcsNetworkInterfaceAttachment(),
"alicloud_snapshot": resourceAlicloudEcsSnapshot(),
"alicloud_snapshot_policy": resourceAlicloudEcsAutoSnapshotPolicy(),
Expand Down Expand Up @@ -1305,7 +1305,7 @@ func Provider() terraform.ResourceProvider {
"alicloud_ddoscoo_domain_resource": resourceAlicloudDdoscooDomainResource(),
"alicloud_ddoscoo_port": resourceAlicloudDdoscooPort(),
"alicloud_slb_load_balancer": resourceAlicloudSlbLoadBalancer(),
"alicloud_ecs_network_interface": resourceAlicloudEcsNetworkInterface(),
"alicloud_ecs_network_interface": resourceAliCloudEcsNetworkInterface(),
"alicloud_ecs_network_interface_attachment": resourceAlicloudEcsNetworkInterfaceAttachment(),
"alicloud_config_aggregator": resourceAlicloudConfigAggregator(),
"alicloud_config_aggregate_config_rule": resourceAlicloudConfigAggregateConfigRule(),
Expand Down
51 changes: 39 additions & 12 deletions alicloud/resource_alicloud_ecs_network_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

func resourceAlicloudEcsNetworkInterface() *schema.Resource {
func resourceAliCloudEcsNetworkInterface() *schema.Resource {
return &schema.Resource{
Create: resourceAlicloudEcsNetworkInterfaceCreate,
Read: resourceAlicloudEcsNetworkInterfaceRead,
Update: resourceAlicloudEcsNetworkInterfaceUpdate,
Delete: resourceAlicloudEcsNetworkInterfaceDelete,
Create: resourceAliCloudEcsNetworkInterfaceCreate,
Read: resourceAliCloudEcsNetworkInterfaceRead,
Update: resourceAliCloudEcsNetworkInterfaceUpdate,
Delete: resourceAliCloudEcsNetworkInterfaceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(2 * time.Minute),
Delete: schema.DefaultTimeout(1 * time.Minute),
Update: schema.DefaultTimeout(1 * time.Minute),
Delete: schema.DefaultTimeout(1 * time.Minute),
},
Schema: map[string]*schema.Schema{
"description": {
Expand Down Expand Up @@ -167,11 +167,23 @@ func resourceAlicloudEcsNetworkInterface() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
ConflictsWith: []string{"ipv4_prefix_count", "private_ip_addresses", "secondary_private_ip_address_count", "private_ip_addresses", "private_ips_count"},
},
"instance_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"network_interface_traffic_mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
},
}
}

func resourceAlicloudEcsNetworkInterfaceCreate(d *schema.ResourceData, meta interface{}) error {
func resourceAliCloudEcsNetworkInterfaceCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
ecsService := EcsService{client}
var response map[string]interface{}
Expand Down Expand Up @@ -246,6 +258,15 @@ func resourceAlicloudEcsNetworkInterfaceCreate(d *schema.ResourceData, meta inte
if v, ok := d.GetOkExists("ipv4_prefix_count"); ok {
request["Ipv4PrefixCount"] = v
}

if v, ok := d.GetOk("instance_type"); ok {
request["InstanceType"] = v
}

if v, ok := d.GetOk("network_interface_traffic_mode"); ok {
request["NetworkInterfaceTrafficMode"] = v
}

wait := incrementalWait(3*time.Second, 3*time.Second)
err = resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
response, err = conn.DoRequest(StringPointer(action), nil, StringPointer("POST"), StringPointer("2014-05-26"), StringPointer("AK"), nil, request, &util.RuntimeOptions{})
Expand All @@ -269,9 +290,10 @@ func resourceAlicloudEcsNetworkInterfaceCreate(d *schema.ResourceData, meta inte
return WrapErrorf(err, IdMsg, d.Id())
}

return resourceAlicloudEcsNetworkInterfaceRead(d, meta)
return resourceAliCloudEcsNetworkInterfaceRead(d, meta)
}
func resourceAlicloudEcsNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) error {

func resourceAliCloudEcsNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
ecsService := EcsService{client}
object, err := ecsService.DescribeEcsNetworkInterface(d.Id())
Expand Down Expand Up @@ -327,9 +349,13 @@ func resourceAlicloudEcsNetworkInterfaceRead(d *schema.ResourceData, meta interf
}

d.Set("vswitch_id", object["VSwitchId"])
d.Set("instance_type", object["Type"])
d.Set("network_interface_traffic_mode", object["NetworkInterfaceTrafficMode"])

return nil
}
func resourceAlicloudEcsNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{}) error {

func resourceAliCloudEcsNetworkInterfaceUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
conn, err := client.NewEcsClient()
if err != nil {
Expand Down Expand Up @@ -924,9 +950,10 @@ func resourceAlicloudEcsNetworkInterfaceUpdate(d *schema.ResourceData, meta inte
d.SetPartial("ipv4_prefix_count")
d.SetPartial("ipv4_prefixes")
}
return resourceAlicloudEcsNetworkInterfaceRead(d, meta)
return resourceAliCloudEcsNetworkInterfaceRead(d, meta)
}
func resourceAlicloudEcsNetworkInterfaceDelete(d *schema.ResourceData, meta interface{}) error {

func resourceAliCloudEcsNetworkInterfaceDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*connectivity.AliyunClient)
ecsService := EcsService{client}
action := "DeleteNetworkInterface"
Expand Down
24 changes: 12 additions & 12 deletions alicloud/resource_alicloud_ecs_network_interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func TestAccAliCloudECSNetworkInterface_basic(t *testing.T) {
PreCheck: func() {
testAccPreCheck(t)
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Expand Down Expand Up @@ -463,7 +462,6 @@ func TestAccAliCloudECSNetworkInterface_ipv4_prefix_address(t *testing.T) {
PreCheck: func() {
testAccPreCheck(t)
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Expand Down Expand Up @@ -540,24 +538,25 @@ func TestAccAliCloudECSNetworkInterface_ipv4_prefix_count(t *testing.T) {
PreCheck: func() {
testAccPreCheck(t)
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testAccConfig(map[string]interface{}{
"network_interface_name": name,
"vswitch_id": "${alicloud_vswitch.default.id}",
"security_group_ids": []string{"${alicloud_security_group.default.id}"},
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}",
"network_interface_name": name,
"vswitch_id": "${alicloud_vswitch.default.id}",
"security_group_ids": []string{"${alicloud_security_group.default.id}"},
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}",
"network_interface_traffic_mode": "HighPerformance",
}),
Check: resource.ComposeTestCheckFunc(
testAccCheck(map[string]string{
"network_interface_name": CHECKSET,
"vswitch_id": CHECKSET,
"security_group_ids.#": "1",
"resource_group_id": CHECKSET,
"network_interface_name": CHECKSET,
"vswitch_id": CHECKSET,
"security_group_ids.#": "1",
"resource_group_id": CHECKSET,
"network_interface_traffic_mode": "HighPerformance",
}),
),
},
Expand Down Expand Up @@ -755,6 +754,7 @@ func TestAccAliCloudECSNetworkInterface_basic3(t *testing.T) {
"security_groups": []string{"${alicloud_security_group.default.id}"},
"resource_group_id": "${data.alicloud_resource_manager_resource_groups.default.ids.0}",
"description": name,
"instance_type": "Trunk",
"private_ip_addresses": []string{fmt.Sprintf("${cidrhost(alicloud_vswitch.default.cidr_block, %d)}", rand), fmt.Sprintf("${cidrhost(alicloud_vswitch.default.cidr_block, %d)}", rand+1)},
"tags": map[string]string{
"Created": "TF-update",
Expand All @@ -768,6 +768,7 @@ func TestAccAliCloudECSNetworkInterface_basic3(t *testing.T) {
"security_groups.#": "1",
"resource_group_id": CHECKSET,
"description": name,
"instance_type": "Trunk",
"private_ip_addresses.#": "2",
"tags.%": "2",
"tags.Created": "TF-update",
Expand Down Expand Up @@ -800,7 +801,6 @@ func TestAccAliCloudECSNetworkInterface_basic4(t *testing.T) {
PreCheck: func() {
testAccPreCheck(t)
},

IDRefreshName: resourceId,
Providers: testAccProviders,
CheckDestroy: rac.checkResourceDestroy(),
Expand Down
37 changes: 19 additions & 18 deletions website/docs/r/ecs_network_interface.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
Provides a Alicloud ECS Network Interface resource.
---

# alicloud\_ecs\_network\_interface
# alicloud_ecs_network_interface

Provides a ECS Network Interface resource.

Expand Down Expand Up @@ -63,32 +63,33 @@ resource "alicloud_ecs_network_interface" "default" {
}
resource_group_id = data.alicloud_resource_manager_resource_groups.default.ids.0
}

```

## Argument Reference

The following arguments are supported:

* `description` - (Optional) The description of the ENI. The description must be 2 to 256 characters in length and cannot start with http:// or https://.
* `name` - (Optional, Computed, Deprecated from v1.123.1+) Field `name` has been deprecated from provider version 1.123.1. New field `network_interface_name` instead
* `network_interface_name` - (Optional, Computed) The name of the ENI. The name must be 2 to 128 characters in length, and can contain letters, digits, colons (:), underscores (_), and hyphens (-). It must start with a letter and cannot start with http:// or https://.
* `primary_ip_address` - (Optional, Computed, ForceNew) The primary private IP address of the ENI. The specified IP address must be available within the CIDR block of the VSwitch. If this parameter is not specified, an available IP address is assigned from the VSwitch CIDR block at random.
* `private_ip` - (Optional, Computed, ForceNew, Deprecated from v1.123.1+) Field `private_ip` has been deprecated from provider version 1.123.1. New field `primary_ip_address` instead
* `private_ip_addresses` - (Optional, Computed) Specifies secondary private IP address N of the ENI. This IP address must be an available IP address within the CIDR block of the VSwitch to which the ENI belongs.
* `private_ips` - (Optional, Computed, Deprecated from v1.123.1+) Field `private_ips` has been deprecated from provider version 1.123.1. New field `private_ip_addresses` instead
* `private_ips_count` - (Optional, Computed, Deprecated from v1.123.1+) Field `private_ips_count` has been deprecated from provider version 1.123.1. New field `secondary_private_ip_address_count` instead
* `queue_number` - (Optional, Computed) The queue number of the ENI.
* `network_interface_name` - (Optional) The name of the ENI. The name must be 2 to 128 characters in length, and can contain letters, digits, colons (:), underscores (_), and hyphens (-). It must start with a letter and cannot start with http:// or https://.
* `primary_ip_address` - (Optional, ForceNew) The primary private IP address of the ENI. The specified IP address must be available within the CIDR block of the VSwitch. If this parameter is not specified, an available IP address is assigned from the VSwitch CIDR block at random.
* `private_ip_addresses` - (Optional, List) Specifies secondary private IP address N of the ENI. This IP address must be an available IP address within the CIDR block of the VSwitch to which the ENI belongs.
* `queue_number` - (Optional, Int) The queue number of the ENI.
* `resource_group_id` - (Optional, ForceNew) The resource group id.
* `secondary_private_ip_address_count` - (Optional, Computed) The number of private IP addresses that can be automatically created by ECS.
* `security_group_ids` - (Optional, Computed) The ID of security group N. The security groups and the ENI must belong to the same VPC. The valid values of N are based on the maximum number of security groups to which an ENI can be added.
* `security_groups` - (Optional, Computed, Deprecated from v1.123.1+) Field `security_groups` has been deprecated from provider version 1.123.1. New field `security_group_ids` instead
* `secondary_private_ip_address_count` - (Optional, Int) The number of private IP addresses that can be automatically created by ECS.
* `security_group_ids` - (Optional, List) The ID of security group N. The security groups and the ENI must belong to the same VPC. The valid values of N are based on the maximum number of security groups to which an ENI can be added.
* `vswitch_id` - (Required, ForceNew) The ID of the VSwitch in the specified VPC. The private IP addresses assigned to the ENI must be available IP addresses within the CIDR block of the VSwitch.
* `tags` - (Optional) A mapping of tags to assign to the resource.
* `ipv6_address_count` - (Optional, Computed, Available in 1.193.0+) The number of IPv6 addresses to randomly generate for the primary ENI. Valid values: 1 to 10. **NOTE:** You cannot specify both the `ipv6_addresses` and `ipv6_address_count` parameters.
* `ipv6_addresses` - (Optional, Computed, Available in 1.193.0+) A list of IPv6 address to be assigned to the primary ENI. Support up to 10.
* `ipv4_prefix_count` - (Optional, Computed, Available in 1.213.0+) The number of IPv4 prefixes that can be automatically created by ECS. Valid values: 1 to 10. **NOTE:** You cannot specify both the `ipv4_prefixes` and `ipv4_prefix_count` parameters.
* `ipv4_prefixes` - (Optional, Computed, Available in 1.213.0+) A list of IPv4 prefixes to be assigned to the ENI. Support up to 10.
* `ipv6_address_count` - (Optional, Int, Available since v1.193.0) The number of IPv6 addresses to randomly generate for the primary ENI. Valid values: 1 to 10. **NOTE:** You cannot specify both the `ipv6_addresses` and `ipv6_address_count` parameters.
* `ipv6_addresses` - (Optional, List, Available since v1.193.0) A list of IPv6 address to be assigned to the primary ENI. Support up to 10.
* `ipv4_prefix_count` - (Optional, Int, Available since v1.213.0) The number of IPv4 prefixes that can be automatically created by ECS. Valid values: 1 to 10. **NOTE:** You cannot specify both the `ipv4_prefixes` and `ipv4_prefix_count` parameters.
* `ipv4_prefixes` - (Optional, List, Available since v1.213.0) A list of IPv4 prefixes to be assigned to the ENI. Support up to 10.
* `instance_type` - (Optional, ForceNew, Available since v1.222.1) The type of the ENI. Default value: `Secondary`. Valid values: `Secondary`, `Trunk`.
* `network_interface_traffic_mode` - (Optional, ForceNew, Available since v1.222.1) The communication mode of the ENI. Default value: `Standard`. Valid values: `Standard`, `HighPerformance`.
* `name` - (Optional, Deprecated since v1.123.1) Field `name` has been deprecated from provider version 1.123.1. New field `network_interface_name` instead
* `private_ip` - (Optional, ForceNew, Deprecated since v1.123.1) Field `private_ip` has been deprecated from provider version 1.123.1. New field `primary_ip_address` instead
* `private_ips` - (Optional, List, Deprecated since v1.123.1) Field `private_ips` has been deprecated from provider version 1.123.1. New field `private_ip_addresses` instead
* `private_ips_count` - (Optional, Int, Deprecated since v1.123.1) Field `private_ips_count` has been deprecated from provider version 1.123.1. New field `secondary_private_ip_address_count` instead
* `security_groups` - (Optional, List, Deprecated since v1.123.1) Field `security_groups` has been deprecated from provider version 1.123.1. New field `security_group_ids` instead

## Attributes Reference

Expand All @@ -103,8 +104,8 @@ The following attributes are exported:
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration-0-11/resources.html#timeouts) for certain actions:

* `create` - (Defaults to 2 mins) Used when create the Network Interface.
* `delete` - (Defaults to 1 mins) Used when delete the Network Interface.
* `update` - (Defaults to 1 mins) Used when update the Network Interface.
* `delete` - (Defaults to 1 mins) Used when delete the Network Interface.

## Import

Expand Down
Loading