想要使用 terraform 在 vpc 下创建两个 ec2 实例
Want to create two ec2 instance under a vpc using terraform
我想通过terraform 在一个vpc 下创建两个ec2 实例。使用我的代码,我可以轻松部署 vpc、安全组和子网,但在实例部分发现一些错误。你能帮我解决这个问题吗?但是 'terraform plan' 命令会成功执行。
provider "aws" {
region = "us-west-2"
access_key = "xxxxxxxx"
secret_key = "xxxxxxxxxxxxx"
}
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
}
resource "aws_subnet" "public" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.0.1.0/24"
}
resource "aws_security_group" "allow_ssh" {
name = "allow_ssh"
description = "Allow ssh inbound traffic"
vpc_id = "${aws_vpc.main.id}"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "instance"{
ami = "ami-0fc025e3171c5a1bf"
instance_type = "t2.micro"
vpc_security_group_ids = ["${aws_security_group.allow_ssh.id}"]
subnet_id = "${aws_subnet.public.id}"
}
output "vpc_id" {
value = "${aws_vpc.main.id}"
}
output "subnet_id" {
value = "${aws_subnet.public.id}"
}
output "vpc_security_group_id" {
value = "${aws_security_group.allow_ssh.id}"
}
错误
ami-0fc025e3171c5a1bf 适用于 arm64 架构,不适用于 t2.micro。如果需要arm平台,需要使用a1家族的实例类型。
否则,您可以使用 Ubuntu 服务器 18.04 LTS (HVM) 的 x86-64 等价物,SSD 卷 使用 ami-0d1cd67c26f5fca19。
我想通过terraform 在一个vpc 下创建两个ec2 实例。使用我的代码,我可以轻松部署 vpc、安全组和子网,但在实例部分发现一些错误。你能帮我解决这个问题吗?但是 'terraform plan' 命令会成功执行。
provider "aws" {
region = "us-west-2"
access_key = "xxxxxxxx"
secret_key = "xxxxxxxxxxxxx"
}
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
}
resource "aws_subnet" "public" {
vpc_id = "${aws_vpc.main.id}"
cidr_block = "10.0.1.0/24"
}
resource "aws_security_group" "allow_ssh" {
name = "allow_ssh"
description = "Allow ssh inbound traffic"
vpc_id = "${aws_vpc.main.id}"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "instance"{
ami = "ami-0fc025e3171c5a1bf"
instance_type = "t2.micro"
vpc_security_group_ids = ["${aws_security_group.allow_ssh.id}"]
subnet_id = "${aws_subnet.public.id}"
}
output "vpc_id" {
value = "${aws_vpc.main.id}"
}
output "subnet_id" {
value = "${aws_subnet.public.id}"
}
output "vpc_security_group_id" {
value = "${aws_security_group.allow_ssh.id}"
}
错误
ami-0fc025e3171c5a1bf 适用于 arm64 架构,不适用于 t2.micro。如果需要arm平台,需要使用a1家族的实例类型。
否则,您可以使用 Ubuntu 服务器 18.04 LTS (HVM) 的 x86-64 等价物,SSD 卷 使用 ami-0d1cd67c26f5fca19。