【发布时间】:2020-01-31 23:54:44
【问题描述】:
Looooong 时间潜伏者和第一次在这里发布海报 o/
我目前正在尝试构建一个附加了 EBS 块设备的 AWS EC2 实例,然后需要安装 MongoDB。
所以我已经完成了构建 EC2 实例并附加 EBS 卷的路线,但是我需要在实例上运行的 remote-exec 需要一个主机 IP 来连接,以运行 MongoDB 安装命令。
无论我尝试什么,它都会在 SSH 上超时。现在我可能只是错过了一步或以错误的方式进行此操作,但希望您能提供帮助。
任何帮助将不胜感激。 :D
以下是我拼凑的代码示例:
provider "aws" {
region = "eu-west-1"
access_key = "xxxxxxx"
secret_key = "xxxxxxxx"
}
resource "tls_private_key" "mongo" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "generated_key" {
key_name = "MongoKey"
public_key = "${tls_private_key.mongo.public_key_openssh}"
}
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"]
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
}
resource "aws_instance" "web" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
key_name = "MongoKey"
monitoring = true
associate_public_ip_address = true
root_block_device {
volume_size = 40
}
ebs_block_device {
volume_size = 100
device_name = "xvda"
}
tags = {
Name = "MongoDB"
}
provisioner "remote-exec" {
connection {
type = "ssh"
user = "ubuntu"
host = "MongoDB"
}
inline = [
"sudo apt-get install gnupg",
"wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -",
"echo deb [ arch=amd64,arm64,s390x ] http://repo.mongodb.com/apt/ubuntu xenial/mongodb-enterprise/4.2 multiverse | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list",
"sudo apt-get update",
"sudo apt-get install -y mongodb-enterprise",
"sudo service mongod start",
"sudo service mongod status"
]
}
【问题讨论】:
标签: amazon-ec2 terraform