Binding an EIP to an RDS DB Instance
Application Scenario
After an RDS DB instance is created, you can bind an EIP to it so that you can access the DB instance through the public network. This section describes how to use the Terraform scripts to bind or unbind an EIP from an RDS DB instance.
An EIP cannot be bound to or unbound from a DB instance that is being created, modified, restored, frozen, or rebooted.
Related Resources
Procedure
- For details about how to create a MySQL database instance, see Creating an RDS MySQL DB Instance.
- Add a security group rule to allow the specified network to access the port of the RDS DB instance.
resource "huaweicloud_networking_secgroup_rule" "allow_rds" { direction = "ingress" ethertype = "IPv4" protocol = "tcp" port_range_min = 3306 port_range_max = 3306 remote_ip_prefix = var.allow_cidr security_group_id = huaweicloud_networking_secgroup.mysecgroup.id }
- Create an EIP and bind it to the private IP address of the RDS DB instance.
# Creating an EIP resource "huaweicloud_vpc_eip" "myeip" { publicip { type = "5_bgp" } bandwidth { name = "test" size = 5 share_type = "PER" charge_mode = "traffic" } } # Querying the private network port of the RDS DB instance data "huaweicloud_networking_port" "rds_port" { network_id = huaweicloud_vpc_subnet.mysubnet.id fixed_ip = huaweicloud_rds_instance.myinstance.private_ips[0] } # Binding an EIP resource "huaweicloud_vpc_eip_associate" "associated" { public_ip = huaweicloud_vpc_eip.myeip.address port_id = data.huaweicloud_networking_port.rds_port.id }
- Run terraform plan to view resources.
- After you confirm that the resource information is correct, run terraform apply to start resource creation.
- Run terraform show to view binding information about the created EIP.
Resource Name |
Parameter |
Description |
|
---|---|---|---|
huaweicloud_vpc_eip |
publicip |
type |
(Mandatory) IP address type. Currently, only 5_bgp is supported. |
bandwidth |
name |
(Optional) Bandwidth configuration name. |
|
size |
(Optional) IP bandwidth. The value ranges from 1 to 300 Mbit/s. |
||
share_type |
(Mandatory) Add the IP address to a shared bandwidth or an exclusive bandwidth. |
||
huaweicloud_networking_port |
fixed_ip |
(Mandatory) Private IP address of the RDS DB instance. |
|
network_id |
(Mandatory) Network ID of the subnet to which the RDS instance belongs. |
||
huaweicloud_vpc_eip_associate |
public_ip |
(Mandatory) EIP. |
|
port_id |
(Mandatory) ID of the port corresponding to the RDS DB instance. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot