2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

「terraform apply」実行時の「invalidamiid.notfound」エラー

Posted at

概要

実践Terraformの第2章 基本操作を参考にEC2を作成しようとしたところエラー発生、、 
エラー解消方法の備忘録

エラー内容

terraform applyを打ち、Enter a value: yesまでは問題なく進み、その後以下のようなエラーが起きた

╷
│ Error: creating EC2 Instance: InvalidAMIID.NotFound: The image id '[ami-06ca3ca175f37dd66]' does not exist
│       status code: 400, request id: d50d2d34-5a79-45ab-beb9-95d0c11b1e40
│
│   with aws_instance.example,
│   on main.tf line 5, in resource "aws_instance" "example":
│    5: resource "aws_instance" "example" {
╵

その時のmain.tf。⇩⇩

main.tf
provider "aws" {
  region = "ap-northeast-1"
}

resource "aws_instance" "example" {
    ami = "ami-06ca3ca175f37dd66"
    instance_type = "t2.micro"
    tags = {
      Name = "example"
    }
}

コンソールを見るとちゃんとAMIは存在していて、IDも間違っていない。

原因

main.tfのproviderで東京リージョンを指定しているのに、バージニア北部のAMIを指定していたため、「そんなAMIないよー」と怒られていた、、

なので解決法としては、以下の2つかなと思う

  • providerで指定するリージョンをus-east-1にする
  • AMIを東京リージョンにあるAMI IDに変更する

改めて、東京リージョンにあるAMI IDを指定し、applyしたら無事EC2を作成できた!

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?