简体   繁体   中英

Want to create two ec2 instance under a vpc using terraform

I want to create two ec2 instance under a vpc via terraform. With my code I can easily deploy the vpc, security group & subnet but when in instance section found some error. Can you help me to resolve this issue. But 'terraform plan' command will execute successfully.

  provider "aws" {
  region = "us-west-2" 
  access_key = "xxxxxxxx"
  secret_key = "xxxxxxxxxxxxx"
}

resource "aws_vpc" "main" { 
  cidr_block = "10.0.0.0/16" 
  instance_tenancy = "default" 
  
  
}
resource "aws_subnet" "public" { 
    vpc_id = "${aws_vpc.main.id}" 
    cidr_block = "10.0.1.0/24" 
 
}

resource "aws_security_group" "allow_ssh" {
  name        = "allow_ssh"
  description = "Allow ssh inbound traffic"
  vpc_id      = "${aws_vpc.main.id}"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port       = 0
    to_port         = 0
    protocol        = "-1"
    cidr_blocks     = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "instance"{
 ami = "ami-0fc025e3171c5a1bf"
 instance_type = "t2.micro"
 vpc_security_group_ids = ["${aws_security_group.allow_ssh.id}"]
 subnet_id = "${aws_subnet.public.id}"
 
}

output "vpc_id" {
  value = "${aws_vpc.main.id}"
}

output "subnet_id" {
  value = "${aws_subnet.public.id}"
}

output "vpc_security_group_id" {
  value = "${aws_security_group.allow_ssh.id}"
}

Error

在此处输入图片说明

在此处输入图片说明

ami-0fc025e3171c5a1bf is for the arm64 architecture and will not work with a t2.micro. If you need an arm platform, you will need to use an instance type in the a1 family.

Otherwise, you can use the x86-64 equivalent of Ubuntu Server 18.04 LTS (HVM), SSD Volume using ami-0d1cd67c26f5fca19.

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