hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

Using market place AMI from another region for aws_instance #12142

Open sydneywu opened 4 years ago

sydneywu commented 4 years ago

Community Note

Description

I need to create a EC2 instance usinga AMI from the AWS maketplace. The AMI is ami-004116ba09b8e3e81( VM-Series Next-Generation Firewall Bundle 1) from Alto Pato. Apparently this ami is from us-east-1 and my VPC is in ap-southeast-1. I am able to do this using the AWS console because it indicate ([Copied ami-004116ba09b8e3e81 from us-east-1] PA-VM-AWS-9.1.0-h3). However if i use terraform, it will throw the following error: The image id '[ami-004116ba09b8e3e81]' does not exist.

New or Affected Resource(s)

ljluestc commented 1 year ago

To address this issue, you need to ensure that you are using the correct AMI ID for the VM-Series Next-Generation Firewall Bundle 1 from Alto Pato in the us-east-1 region, even though your VPC is in the ap-southeast-1 region.

provider "aws" {
  region = "ap-southeast-1"
}

resource "aws_instance" "example" {
  ami           = "ami-004116ba09b8e3e81"
  instance_type = "t2.micro"
  subnet_id     = "your-subnet-id"  # Replace with your subnet ID in ap-southeast-1
  key_name      = "your-key-name"   # Replace with your key pair name
}

# Define any other required resources or configurations as needed.

Make sure to replace "your-subnet-id" with the appropriate subnet ID from your ap-southeast-1 region, and "your-key-name" with the name of your key pair.