내용으로 건너뛰기

Terraform The availability Zone issue

0

Hello Team, So I try to launch my Ec2 instance with terraform but I have the issue of Availability Zone. I try to change the zone and the region, but I have always the issue of Invalid availability zone: [us-east-2].

So here the error message:

│ Error: creating EC2 Instance: operation error EC2: RunInstances, https response error StatusCode: 400, RequestID: 706b1ac5-9587-4e18-b7ec-fb281ce7a1b4, api error InvalidParameterValue: Invalid availability zone: [us-east-2]

│ with aws_instance.web,

│ on first_instance.tf line 7, in resource "aws_instance" "web":

│ 7: resource "aws_instance" "web" {

This my file.tf:

provider "aws" { region = "us-east-2" }

resource "aws_instance" "web" { ami = "ami-0b0a32ffc011bf8c2" instance_type = "t2.micro" availability_zone = "us-east-2a" key_name = "love-sg" vpc_security_group_ids = ["sg-067a6076c9de32a39"] tags = { Name = "love-Instance" }

}

질문됨 2년 전766회 조회
2개 답변
2

I see you've already accepted A_J's answer, and if that works for you then that's great. But there appears to be a mismatch between the error message and the Terraform code.

The error message InvalidParameterValue: Invalid availability zone: [us-east-2] is correct, because us-east-2 is a region, not an AZ.

The Terraform code clearly shows the AZ is us-east-2a (note the 'a' on the end):

availability_zone = "us-east-2a"

I'm confused at how that error message is generated by the given Terraform code.

전문가
답변함 2년 전
전문가
검토됨 2년 전
전문가
검토됨 2년 전
1
수락된 답변

Here is a corrected version of your Terraform file without specifying the availability_zone:

provider "aws" {
  region = "us-east-2"
}

resource "aws_instance" "web" {
  ami                    = "ami-0b0a32ffc011bf8c2"
  instance_type          = "t2.micro"
  key_name               = "love-sg"
  vpc_security_group_ids = ["sg-067a6076c9de32a39"]
  tags = {
    Name = "love-Instance"
  }
}

전문가
답변함 2년 전
전문가
검토됨 2년 전
전문가
검토됨 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.