【发布时间】:2020-11-29 11:01:33
【问题描述】:
我正在尝试使用 Terraform 在 Amazon Web Services 上部署 EC2 实例。我安装了 AWS CLI 并在 linux 机器上工作。使用 terraform 我想模仿下面命令行指令的操作(尽管希望有一点改进):
aws ec2 run-instances --image-id ami-0127d62154efde733 --count 1 --instance-type t3a.nano --key-name aws-key --security-group-ids launch-wizard-13 --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=test}]'
这将在 eu-west-1c 中创建一个实例(虽然这没有定义,并且我的帐户被选择为在 eu-west-1 中),我可以毫无问题地进行 ssh。
- 我想要一个简单的 .tf 文件来模拟 上面的命令行。
- 我想定义 正在部署服务器,例如能够在 美国会很好。
- 我要使用的图像是最新的 ubuntu 服务器,所以图像类型的通配符是 比使用 id 更可取(我相信不同地区可能有不同的 id,但我不确定)。
- 安全组 (launch-wizard-13) 在我的 帐户,在网络和安全设置中。
我已尝试查看官方文档、博客和 github 存储库,但无法获得适用于上述情况的简单 .tf 文件。通常问题出在安全组上,但如果我从上面的命令行中忽略了该部分,则无法 ssh 进入。请帮忙。
编辑:
回复@Marcin,我目前正在运行的完整.tf(terraform apply)是
provider "aws" {
region = "eu-west-2"
}
resource "aws_instance" "myEc2" {
ami = "ami-0127d62154efde733"
instance_type = "t3a.nano"
key_name = "aws-key"
security_groups = [
"launch-wizard-13"
]
tags = {
Name = "test"
}
}
导致错误,
aws_instance.myEc2: Creating...
Error: Error launching instance, possible mismatch of Security Group IDs and Names. See AWS Instance docs here: https://terraform.io/docs/providers/aws/r/instance.html.
AWS Error: InvalidParameterValue: Value () for parameter groupId is invalid. The value cannot be empty
status code: 400, request id: 22b572d8-d0d3-4e2e-ba1b-3db91d2e05f6
on terraform-ec2.tf line 5, in resource "aws_instance" "myEc2":
5: resource "aws_instance" "myEc2" {
【问题讨论】:
标签: amazon-web-services amazon-ec2 terraform