zealvora / terraform-beginner-to-advanced-resource

1.93k stars 5.34k forks source link

aws_ami for ubuntu is not working #15

Open kumarrkslinux opened 2 years ago

kumarrkslinux commented 2 years ago

While running this code I am always getting this error, can you help for this.

provider "aws"{ region = "ap-south-1" access_key = "key" secret_key = "kay" }

data "aws_ami" "ubuntu"{ most_recent = true owners = ["099720109477"]

filter {
    name = "name"
    #values = ["amzn2-ami-hvm-*-x86_64-gp2"]
    values = ["ubuntu/images/ubuntu-*-*-amd64-server-*"]
        }

}

resource "aws_instance" "new_vm" { ami = "data.aws_ami.ubuntu.id" instance_type = "t2.micro" }

Error:

aws_instance.new_vm: Creating... ╷

  1. Sometime: │ Error: Error launching source instance: InvalidAMIID.Malformed: Invalid id: "aws_ami.ubuntu.id" (expecting "ami-...") │ status code: 400, request id: be8982b3-11c5-4159-9375-654814ba2b57 │ │ with aws_instance.new_vm, │ on data_source.tf line 28, in resource "aws_instance" "new_vm": │ 28: resource "aws_instance" "new_vm" {

ws_instance.new_vm: Creating...

  1. sometime │ Error: Error launching source instance: UnsupportedOperation: AMI 'ami-0011ac562eeee4a55' with an instance-store root device is not supported for the instance type 't2.medium'. │ status code: 400, request id: 328c37c1-848f-45ab-ae3f-3202a8fc899b │ │ with aws_instance.new_vm, │ on data_source.tf line 18, in resource "aws_instance" "new_vm": │ 18: resource "aws_instance" "new_vm" {

Thank you