All Products
Search
Document Center

:How to bind EIPs to the secondary network interface controller by using Terraform

Last Updated:Dec 30, 2020

Overview

This article describes how to bind EIPs to the secondary network interface controller by using Terraform.

Detail

Alibaba Cloud reminds you that:

  • Before you perform operations that may cause risks, such as modifying instance configurations or data, we recommend that you check the disaster recovery and fault tolerance capabilities of the instances to ensure data security.
  • You can modify the configurations and data of instances including but not limited to Elastic Compute Service (ECS) and Relational Database Service (RDS) instances. Before the modification, we recommend that you create snapshots or enable RDS log backup.
  • If you have authorized or submitted sensitive information such as the logon account and password in the Alibaba Cloud Management Console, we recommend that you modify such information in a timely manner.

To create an alicloud_eip_association in The Terraform template, specify both of the following parameters.

instance_type = "NetworkInterface"
instance_id = "[$ID]"

Note:[$ID] indicates the ID of the secondary network interface controller

The following is a specific example:

resource "alicloud_eip" "eip" {   name = "test_eip" }  resource "alicloud_vpc" "vpc" {   name       = "test_vpc"   cidr_block = "[$IP]" }  data "alicloud_zones" "default" {   available_resource_creation = "VSwitch" }  resource "alicloud_vswitch" "vswitch" {   name              = "test_vswitch"   cidr_block        = "[$IP]"   availability_zone = "${data.alicloud_zones.default.zones.0.id}"   vpc_id            = "${alicloud_vpc.vpc.id}" }  resource "alicloud_security_group" "group" {   name   = "test_sg"   vpc_id = "${alicloud_vpc.vpc.id}" }  resource "alicloud_network_interface" "default" {   name              = "test_eni"   vswitch_id        = "${alicloud_vswitch.vswitch.id}"   security_groups   = ["${alicloud_security_group.group.id}"]   private_ip        = "[$Private_IP]"   private_ips_count = 1 }  resource "alicloud_eip_association" "default" {   allocation_id = "${alicloud_eip.eip.id}"   instance_type = "NetworkInterface"   instance_id   = "${alicloud_network_interface.default.id}" }

Note:

  • [$IP] is the address of the cidr_block.
  • [$Private_IP] indicates the address of Private_ip.

Application scope

  • Elastic Compute Service
  • Elastic IP Address