【发布时间】:2019-11-09 02:25:37
【问题描述】:
最近使用 GCP 开始使用 Terraform,我想完成一个练习:
- 使用单个子网创建新的 VPC 网络。
- 创建允许外部 RDP 流量到堡垒主机系统的防火墙规则。
- 部署两个连接到 VPC 网络和默认网络的 Windows 服务器。
- 创建一个指向启动脚本的虚拟机。
- 配置防火墙规则以允许 HTTP 访问虚拟机。
这是我的解决方案:
- 创建一个名为securenetwork 的新VPC 网络,然后在securenetwork 中创建一个新的VPC 子网。配置网络和子网后,配置防火墙规则,允许从 Internet 到堡垒主机的入站 RDP 流量(TCP 端口 3389)。
# Create the securenetwork network
resource "google_compute_network" "securenetwork" {
name = "securenetwork"
auto_create_subnetworks = false
}
# Create securesubnet-us subnetwork
resource "google_compute_subnetwork" "securesubnet-eu" {
name = "securesubnet-eu"
region = "europe-west1"
network = "${google_compute_network.securenetwork.self_link}"
ip_cidr_range = "10.130.0.0/20"
}
# Create a firewall rule to allow HTTP, SSH, RDP and ICMP traffic on securenetwork
resource "google_compute_firewall" "securenetwork-allow-http-ssh-rdp-icmp" {
name = "securenetwork-allow-http-ssh-rdp-icmp"
network = "${google_compute_network.securenetwork.self_link}"
allow {
protocol = "tcp"
ports = ["3389"]
}
allow {
protocol = "icmp"
}
}
# Create the vm-securehost instance
module "vm-securehost" {
source = "./instance/securehost"
instance_name = "vm-securehost"
instance_zone = "europe-west1-d"
instance_subnetwork = "${google_compute_subnetwork.securesubnet-eu.self_link}"
instance_network = "${google_compute_network.securenetwork.self_link}"
}
# Create the vm-bastionhost instance
module "vm-bastionhost" {
source = "./instance/bastionhost"
instance_name = "vm-bastionhost"
instance_zone = "europe-west1-d"
instance_subnetwork = "${google_compute_subnetwork.securesubnet-eu.self_link}"
instance_network = "${google_compute_network.securenetwork.self_link}"
}
-
部署 Windows 实例
- 一个名为 vm-securehost 的 Windows 2016 服务器实例,具有两个网络接口。将第一个网络接口配置为与新 VPC 子网的仅内部连接,并将第二个网络接口配置为与默认 VPC 网络的仅内部连接。这是安全服务器。
variable "instance_name" {}
variable "instance_zone" {}
variable "instance_type" {
default = "n1-standard-1"
}
variable "instance_subnetwork" {}
variable "instance_network" {}
resource "google_compute_instance" "vm_instance" {
name = "${var.instance_name}"
zone = "${var.instance_zone}"
machine_type = "${var.instance_type}"
boot_disk {
initialize_params {
image = "windows-cloud/windows-2016"
}
}
network_interface {
subnetwork = "${var.instance_subnetwork}"
access_config {
# Allocate a one-to-one NAT IP to the instance
}
}
}
- 另一个名为 vm-bastionhost 的 Windows 2016 服务器实例具有两个网络接口。将第一个网络接口配置为使用临时公共(外部 NAT)地址连接到新的 VPC 子网,并将第二个网络接口配置为与默认 VPC 网络的仅内部连接。这是跳转框或堡垒主机。
variable "instance_name" {}
variable "instance_zone" {}
variable "instance_type" {
default = "n1-standard-1"
}
variable "instance_subnetwork" {}
variable "instance_network" {}
resource "google_compute_address" "default" {
name = "default"
region = "europe-west1"
}
resource "google_compute_instance" "vm_instance" {
name = "${var.instance_name}"
zone = "${var.instance_zone}"
machine_type = "${var.instance_type}"
boot_disk {
initialize_params {
image = "windows-cloud/windows-2016"
}
}
network_interface {
subnetwork = "${var.instance_subnetwork}"
network = "${var.instance_network}"
access_config {
# Allocate a one-to-one NAT IP to the instance
nat_ip = "${google_compute_address.default.address}"
}
}
}
我的问题:
- 如何配置没有公共 IP 地址的名为 vm-securehost 的 Windows 计算实例?
- 如何配置名为 vm-securehost 的 Windows 计算实例在启动时运行 Microsoft IIS Web 服务器软件?
- 感谢您对解决方案的任何评论
【问题讨论】:
标签: windows google-cloud-platform terraform vpc startupscript