我想在aws上部署一个ec2实例。
这是我的资源代码
data "aws_ami_ids" "ubuntu" {
owners = ["099720109477"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
}
output "test" {
value = data.aws_ami_ids.ubuntu
}
resource "aws_instance" "myec2" {
ami = "${data.aws_ami_ids.ubuntu.id}"
instance_type = var.instancetype
key_name = "devops-era"`
security_groups = ["${aws_security_group.allow_http_https.name}"]
tags = {
Name = "var.aws_common_tag"
}
}
但是当我运行terraform apply:
时,我一直得到下面的错误Error: creating EC2 Instance: InvalidAMIID.Malformed: Invalid id: "203304658" (expecting "ami-...")
│ status code: 400, request id: 35b803fd-a6c8-4632-82ee-2936c9cbf062
│
│ with aws_instance.myec2,
│ on mini-projet.tf line 28, in resource "aws_instance" "myec2":
│ 28: resource "aws_instance" "myec2" {
我不明白为什么
如有任何建议,我将不胜感激
您的数据源查询返回多个AMI id。你必须明确地选择你想要的,例如,使用第一个:
ami = data.aws_ami_ids.ubuntu.ids[0]