0
votes

I was launching the AWS EC2 from custom AMI named as 'test-ami' using terraform .But i was getting below error for the same .As in the main.tf file first custom ami would be created from known server passing source_instance_id , and then ec2 would be created from this custom AMI .Error is

Error: Error launching source instance: InvalidAMIID.Malformed: Invalid id: "test-ami.id" (expecting "ami-...") status code: 400, request id: 1afd98e1-9d5a-4b1e-b81b-beb24c3da789

on main.tf line 31, in resource "aws_instance" "test-server3": 31: resource "aws_instance" "test-server3" {

Can we created ec2 via custom AMI name as AMI ID is not known to me ?

1
Can you show the actual code?Marcin
resource "aws_ami_from_instance" "test-ami" { name = "test-ami" source_instance_id = "i-00f72c2be85b6c450" } resource "aws_instance" "test-server3" { ami = "test-ami.id" instance_type = "t2.micro" subnet_id = "subnet-0ab209a91658784cc" key_name = "terraform" tags = { Name = "test-server3" } }AnkitK
Edit question with correctly formatted code, please.Marcin

1 Answers

0
votes

Your test-server3 should be:

resource "aws_instance" "test-server3" { 

    ami = aws_ami_from_instance.test-ami.id
     
    instance_type = "t2.micro" 
    subnet_id = "subnet-0ab209a91658784cc" 
    key_name = "terraform" 
    tags = { 
        Name = "test-server3" 
    } 
}