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" }

}

asked 10 months ago428 views
2 Answers
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.

EXPERT
answered 10 months ago
EXPERT
reviewed 10 months ago
EXPERT
reviewed 10 months ago
1
Accepted Answer

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"
  }
}

EXPERT
answered 10 months ago
EXPERT
reviewed 10 months ago
EXPERT
reviewed 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions