使用 Terraform 为 AWS 配置 Windows 个 VM(包括 File Provisioner)导致超时

Provisioning Windows VM including File Provisioner for AWS using Terraform results in Timeout

我知道已经有几篇与这篇文章类似的文章 - 我已经浏览过它们并调整了我的 Terraform 配置文件,但这没有什么区别。

因此,我想发布我的配置文件和用例:我想使用 Terraform 在 AWS 上配置一个 (Windows) 虚拟机。它在没有文件配置部分的情况下工作——包括它们,配置会导致超时。

这包括对以前帖子的改编:

我在使用“winrm”而不是“ssh”时也会超时。

如果您能为以下配置文件提供任何提示,我将很高兴:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

# Configure the AWS Provider
provider "aws" {
  access_key = "<my access key>"
  secret_key = "<my secret key>"
  region = "eu-central-1"
}

resource "aws_instance" "webserver" {
    ami = "ami-07dfec7a6d529b77a"
    instance_type = "t2.micro"
    security_groups = [aws_security_group.sgwebserver.name]
    key_name = aws_key_pair.pubkey.key_name

    tags = {
        "Name" = "WebServer-Win"
    }
}

resource "null_resource" "deployBundle" {
    
    connection {
      type        = "ssh"
      user        = "Administrator"
      private_key = "${file("C:/Users/<my user name>/aws_keypair/aws_instance.pem")}"
      host        = aws_instance.webserver.public_ip
    }

    provisioner "file" {    
      source = "files/test.txt"    
      destination = "C:/test.txt"  
    }

    depends_on = [ aws_instance.webserver ]
} 

resource "aws_security_group" "sgwebserver" {
  name        = "sgwebserver"
  description = "Allow ssh inbound traffic"

  ingress {
    from_port        = 0
    to_port          = 6556
    protocol         = "tcp"
    cidr_blocks      = ["0.0.0.0/0"]
  }

  egress {
    from_port        = 0
    to_port          = 0
    protocol         = "-1"
    cidr_blocks      = ["0.0.0.0/0"]
  }

  tags = {
      Name = "sgwebserver"
  }

}

resource "aws_key_pair" "pubkey" {
    key_name = "aws-cloud"
    public_key = file("key/aws_instance.pub")
}

resource "aws_eip" "elasticip" {
    instance = aws_instance.webserver.id
}

output "eip" {
    value = aws_eip.elasticip.public_ip
}

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"

  name = "my-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["eu-central-1a", "eu-central-1b", "eu-central-1c"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

  enable_nat_gateway = true
  enable_vpn_gateway = true

  tags = {
    Terraform = "true"
    Environment = "dev"
  }
}

提前致谢!

Windows EC2 实例 ,它们支持 RDP。您必须先在实例上安装 SSH 服务器软件,然后才能通过 SSH 连接到实例。

我建议做类似 placing the file in S3, and using a user data script 的事情来触发 Windows EC2 实例在启动时下载文件。