Terraform:使用封闭的网络连接
Posted
技术标签:
【中文标题】Terraform:使用封闭的网络连接【英文标题】:Terraform: use of closed network connection 【发布时间】:2019-01-15 00:26:45 【问题描述】:我正在为 terraform 使用这个插件:https://github.com/terra-farm/terraform-provider-virtualbox
我只是尝试在 virtualbox 中安装一个 ubuntu 18.04 的盒子。
这是我的main.tf
resource "virtualbox_vm" "node"
count = 2
name = "$format("node-%02d", count.index+1)"
url = "https://vagrantcloud.com/ubuntu/boxes/bionic64/versions/20180802.0.0/providers/virtualbox.box"
image = "./virtualbox-ubuntu.box"
cpus = 2
memory = "512 mib",
network_adapter
type = "bridged",
host_interface = "en0",
output "IPAddr"
value = "$element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 1)"
output "IPAddr_2"
value = "$element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 2)"
当我执行terraform apply
时失败:
2018-08-07T22:17:41.256+0200 [DEBUG] plugin.terraform-provider-virtualbox: pid-3041-vbm.go:75: executing: VBoxManage showvminfo node-02 --machinereadable
2018-08-07T22:17:41.346+0200 [DEBUG] plugin.terraform-provider-virtualbox: pid-3041-vbm.go:75: executing: VBoxManage showvminfo node-01 --machinereadable
2018-08-07T22:17:41.352+0200 [DEBUG] plugin.terraform-provider-virtualbox: pid-3041-vbm.go:45: executing: VBoxManage clonehd /Users/name/.terraform/virtualbox/gold/virtualbox-ubuntu/ubuntu-xenial-16.04-cloudimg-configdrive.vmdk /Users/name/.terraform/virtualbox/machine/node-02/ubuntu-xenial-16.04-cloudimg-configdrive.vmdk
2018-08-07T22:17:41.412+0200 [DEBUG] plugin.terraform-provider-virtualbox: pid-3041-resource_vm.go:247: [ERROR] Clone *.vdi and *.vmdk to VM folder: exit status 1
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalWriteState
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalApplyProvisioners
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalIf
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalWriteState
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalWriteDiff
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalApplyPost
2018/08/07 22:17:41 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:
* virtualbox_vm.node.1: exit status 1
2018/08/07 22:17:41 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
* virtualbox_vm.node.1: exit status 1
2018/08/07 22:17:41 [TRACE] [walkApply] Exiting eval tree: virtualbox_vm.node[1]
2018-08-07T22:17:41.454+0200 [DEBUG] plugin.terraform-provider-virtualbox: pid-3041-vbm.go:45: executing: VBoxManage clonehd /Users/name/.terraform/virtualbox/gold/virtualbox-ubuntu/ubuntu-xenial-16.04-cloudimg-configdrive.vmdk /Users/name/.terraform/virtualbox/machine/node-01/ubuntu-xenial-16.04-cloudimg-configdrive.vmdk
2018-08-07T22:17:41.516+0200 [DEBUG] plugin.terraform-provider-virtualbox: pid-3041-resource_vm.go:247: [ERROR] Clone *.vdi and *.vmdk to VM folder: exit status 1
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalWriteState
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalApplyProvisioners
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalIf
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalWriteState
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalWriteDiff
2018/08/07 22:17:41 [TRACE] root: eval: *terraform.EvalApplyPost
2018/08/07 22:17:41 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:
* virtualbox_vm.node.0: exit status 1
2018/08/07 22:17:41 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
* virtualbox_vm.node.0: exit status 1
2018/08/07 22:17:41 [TRACE] [walkApply] Exiting eval tree: virtualbox_vm.node[0]
2018/08/07 22:17:41 [TRACE] dag/walk: upstream errored, not walking "output.IPAddr_2"
2018/08/07 22:17:41 [TRACE] dag/walk: upstream errored, not walking "provider.virtualbox (close)"
2018/08/07 22:17:41 [TRACE] dag/walk: upstream errored, not walking "output.IPAddr"
2018/08/07 22:17:41 [TRACE] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
2018/08/07 22:17:41 [TRACE] dag/walk: upstream errored, not walking "root"
2018/08/07 22:17:41 [TRACE] Preserving existing state lineage "782abaa9-e567-10d4-1902-6d1223713e6a"
2018/08/07 22:17:41 [TRACE] Preserving existing state lineage "782abaa9-e567-10d4-1902-6d1223713e6a"
2018/08/07 22:17:41 [TRACE] Preserving existing state lineage "782abaa9-e567-10d4-1902-6d1223713e6a"
2018/08/07 22:17:41 [TRACE] Preserving existing state lineage "782abaa9-e567-10d4-1902-6d1223713e6a"
2018/08/07 22:17:41 [DEBUG] plugin: waiting for all plugin processes to complete...
Error: Error applying plan:
2 error(s) occurred:
* virtualbox_vm.node[1]: 1 error(s) occurred:
* virtualbox_vm.node.1: exit status 1
* virtualbox_vm.node[0]: 1 error(s) occurred:
* virtualbox_vm.node.0: exit status 1
Terraform does not automatically rollback in the face of errors.
2018-08-07T22:17:41.522+0200 [DEBUG] plugin.terraform-provider-virtualbox: pid-3041-rpc_server.go:48: [ERR] plugin: plugin server: accept unix /var/folders/y4/v8w900l115lbtzylp143pxfr0000gn/T/plugin055999022: use of closed network connection
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
我做错了什么?旧图像的示例似乎有效?
【问题讨论】:
第一个错误是...pid-3041-resource_vm.go:247: [ERROR] Clone *.vdi and *.vmdk to VM folder: exit status 1
是不是源可用性或目标可用空间的问题?
@Tuckbros 这就是我正在寻找的信息。用答案更新问题,赏金就是你的了。
【参考方案1】:
这是因为这些盒子包含两个硬盘,而不是一个。 https://vagrantcloud.com/geerlingguy/boxes/ubuntu1804/versions/1.0.4/providers/virtualbox.box 框似乎效果更好。
我尝试使用这个官方的 xenial64 盒子,它就像一个魅力。
https://app.vagrantup.com/ubuntu/boxes/xenial64/versions/20190507.0.0/providers/virtualbox.box
试试这些图片。
【讨论】:
以上是关于Terraform:使用封闭的网络连接的主要内容,如果未能解决你的问题,请参考以下文章
在没有运行explorer.exe的情况下显示网络弹出窗口(“连接到网络”的东西)
使用 Terraform 和启动脚本创建专用网络 - Google Cloud Platform