简体   繁体   中英

Error when creating multiple instances and one network interface using terraform

My task is to create two instances, and attach one.network address with two private IP. Unfortunately, when creating instances, the IP for the first instance is attached, and the second instance simply dies. The error says that the IP is being used. Conclusion, as far as I understand, when creating a second instance, it refers to the first IP, which is already assigned to the first instance. I will be grateful for the answer. Below I have attached the implementation code. My error I got looks like this:

aws_instance.dev-elasticsearch[0]: Creating...

 Error: Error launching source instance: InvalidNetworkInterface.InUse: Interface: [eni-0072af3215e4d6943] in use.
 status code: 400, request id: 639b2e67-2539-426c-9f8d-17d0c6f8a0c5

My code:

resource "aws_network_interface" "private_elasticsearch" {
  subnet_id       = aws_subnet.private_subnets.id
  private_ips = ["10.245.10.6", "10.245.10.7"]
  security_groups = [aws_security_group.elastic_traffic.id, aws_security_group.general.id]
  tags = {
    Environment = "Test"
    Project = "test"
    Name = "elasticsearch-interface"
  }
}

resource "aws_instance" "dev-elasticsearch" {
  count = 2
  ami = "ami-08bdc08970fcbd34a"
  availability_zone = "eu-north-1a"
  instance_type = "t3.micro"
  network_interface {
     device_index=0
     network_interface_id = aws_network_interface.private_elasticsearch.id
  }
  tags = {
    Environment = "Test"
    Project = "test"
    Name = "elasticsearch-instance-dev"
  }
}

You need two interfaces , since single interface can be attached to only a single instance. So if you have two instances, you need two separate interfaces, not a single interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM