[英]cannot ssh into instance created from sourceImage "google_compute_instance_from_machine_image"
I am creating an instance from a sourceImage, using this terraform template:我正在使用此 terraform 模板从 sourceImage 创建一个实例:
resource "tls_private_key" "sandbox_ssh" {
algorithm = "RSA"
rsa_bits = 4096
}
output "tls_private_key_sandbox" { value = "${tls_private_key.sandbox_ssh.private_key_pem}" }
locals {
custom_data1 = <<CUSTOM_DATA
#!/bin/bash
CUSTOM_DATA
}
resource "google_compute_instance_from_machine_image" "sandboxvm_test_fromimg" {
project = "<proj>"
provider = google-beta
name = "sandboxvm-test-fromimg"
zone = "us-central1-a"
tags = ["test"]
source_machine_image = "projects/<proj>/global/machineImages/sandboxvm-test-img-1"
can_ip_forward = false
labels = {
owner = "test"
purpose = "test"
ami = "sandboxvm-test-img-1"
}
metadata = {
ssh-keys = "${var.sshuser}:${tls_private_key.sandbox_ssh.public_key_openssh}"
}
network_interface {
network = "default"
access_config {
// Include this section to give the VM an external ip address
}
}
metadata_startup_script = local.custom_data1
}
output "instance_ip_sandbox" {
value = google_compute_instance_from_machine_image.sandboxvm_test_fromimg.network_interface.0.access_config.0.nat_ip
}
output "user_name" {
value = var.sshuser
}
I can't even ping / netcat, neither the private or public IP of the VM created.我什至无法 ping / netcat,无论是创建的 VM 的私有还是公共 IP。 Even the "serial port" ssh, passed inside custom script helps.
甚至在自定义脚本中传递的“串行端口”ssh 也有帮助。
I'm suspecting, that since it is a "google beta" capability, is it even working / reliable?我怀疑,既然它是“谷歌测试版”功能,它甚至可以工作/可靠吗? Maybe we just can't yet, create VMs ie GCEs from "SourceImages" in GCP, Unless proven otherwise, with a simple goof-up not very evident in my TF.
也许我们还不能,从 GCP 中的“SourceImages”创建 VM,即 GCE,除非另有证明,否则在我的 TF 中不太明显的简单错误。
I could solve it actually, and all this somewhere sounds very sick of GCE.我实际上可以解决它,而这一切在某处听起来很讨厌 GCE。 Problem was while creating the base image, the instance I had chosen has had the following:
问题是在创建基础映像时,我选择的实例具有以下内容:
#sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
#sudo update-alternatives --install /usr/bin/python3 python /usr/bin/python3.7 1
Maybe I should try with "python3" instead of "python", but when instantiating GCEs basis this MachineImage, it looks for a rather deprecated "python2.7" and not "python3" and complained of missing / unreadable packages like netiplan etc.也许我应该尝试使用“python3”而不是“python”,但是当基于这个 MachineImage 实例化 GCE 时,它会寻找一个相当过时的“python2.7”而不是“python3”,并抱怨缺少/不可读的包,如 netiplan 等。
Commenting the "update-alternatives" and installing python3.6 and python3.7 explicitly did the trick!评论“更新替代品”并明确安装 python3.6 和 python3.7 就可以了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.