我想在gcp中创建一个脚本,并在完成后运行一些命令
我创建了一个Terraform脚本来启动GCP中的Windows实例, 实例创建成功完成,但在inline命令中失败,也尝试使用INVOKE-Commands运行命令,但也失败。
Terraform script:
// Configure the Google Cloud provider
provider "google" {
credentials = "${file(*******.json")}"
project = "**********"
region = "${var.region_name}"
zone = "${var.zone_name}"
}
resource "google_compute_instance" "vm_instance" {
name = "${var.instance_name}"
machine_type = "${var.machine_type}"
tags = "${var.network_tags}"
boot_disk {
initialize_params {
image = "${var.boot_disk_image}"
size = "100"
type = "pd-standard"
}
}
network_interface {
# A default network is created for all GCP projects
# name = "${var.instance_name}"
network = "${var.instance_network}"
subnetwork = "${var.instance_subnetwork}"
access_config {
}
}
provisioner "remote-exec" {
connection {
type = "winrm"
user = "administrator"
password = "***********"
host = "${google_compute_instance.vm_instance.network_interface.0.access_config.0.nat_ip}"
timeout = "1m"
}
inline = [
"powershell -ExecutionPolicy Unrestricted New-Item -ItemType 'file' -Path 'c:\\test.txt'"
]
}
}
Error:
google_compute_instance.vm_instance (remote-exec): Connecting to remote host via WinRM...
google_compute_instance.vm_instance (remote-exec): Host: ip
google_compute_instance.vm_instance (remote-exec): Port: 5985
google_compute_instance.vm_instance (remote-exec): User: administrator
google_compute_instance.vm_instance (remote-exec): Password: true
google_compute_instance.vm_instance (remote-exec): HTTPS: false
google_compute_instance.vm_instance (remote-exec): Insecure: false
google_compute_instance.vm_instance (remote-exec): NTLM: false
google_compute_instance.vm_instance (remote-exec): CACert: false
Getting below error, For invoke command,
PS C:\Users\smp0619\Desktop\MyFolder\Terraform\TerraformScripts\gcp_instance> Invoke-Command -ComputerName $private_ip -
ScriptBlock { param($variable) Rename-NetAdapter -Name "Ethernet" -NewName $variable } -ArgumentList $private_ip -creden
tial $VMCredentials
[ip] Connecting to remote server ip failed with the following error message : WinRM cannot
complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the
network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By
default, the WinRM firewall exception for public profiles limits access to remote computers within the same local
subnet. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (ip:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken