【发布时间】:2018-08-01 09:46:30
【问题描述】:
我从 Udemy 课程中克隆了一个 git repo,更改了访问密钥和密钥,ami,但我仍然收到如下错误消息:dial tcp 35.158.225.227:5985: connect: resource暂时不可用。
ec2 实例状态正在运行,但 powershell 无法执行。你知道什么不能正常工作吗?
windows-instance.tf
resource "aws_key_pair" "mykey" {
key_name = "mykey"
public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
}
resource "aws_instance" "win-example" {
ami = "${lookup(var.WIN_AMIS, var.AWS_REGION)}"
instance_type = "t2.micro"
key_name = "${aws_key_pair.mykey.key_name}"
user_data = <<EOF
<powershell>
net user ${var.INSTANCE_USERNAME} '${var.INSTANCE_PASSWORD}' /add /y
net localgroup administrators ${var.INSTANCE_USERNAME} /add
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
net stop winrm
sc.exe config winrm start=auto
net start winrm
</powershell>
EOF
provisioner "file" {
source = "test.txt"
destination = "C:/test.txt"
}
connection {
type = "winrm"
timeout = "10m"
user = "${var.INSTANCE_USERNAME}"
password = "${var.INSTANCE_PASSWORD}"
}
}
vars.tf
variable "AWS_ACCESS_KEY" {}
variable "AWS_SECRET_KEY" {}
variable "AWS_REGION" {
default = "eu-central-1"
}
variable "WIN_AMIS" {
type = "map"
default = {
eu-central-1 = "ami-6af7f381"
eu-west-1 = "ami-96e1f27c"
}
}
variable "PATH_TO_PRIVATE_KEY" {
default = "mykey"
}
variable "PATH_TO_PUBLIC_KEY" {
default = "mykey.pub"
}
variable "INSTANCE_USERNAME" {
default = "Terraform"
}
variable "INSTANCE_PASSWORD" { }
provider.tf
provider "aws" {
access_key = "${var.AWS_ACCESS_KEY}"
secret_key = "${var.AWS_SECRET_KEY}"
region = "${var.AWS_REGION}"
}
文件夹中还有一个 terraform.tfvars、pub 和一个 pem 文件。我做错了什么?
最好的问候
【问题讨论】:
-
您的实例似乎没有定义安全组,因此它可能选择了 VPC 的默认安全组。相反,您应该向实例添加一个安全组,以允许 TCP/5985 和 TCP/5986 上的入站流量。
标签: amazon-web-services powershell terraform