1
votes

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

enter image description here

enter image description here

1
Just a stupid observation: Don't you need a space before { in "instance"{?Marcin
had tried with the space in aws_instance section, but the error is same.Aniket

1 Answers

2
votes

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.