如何指定openstack_blockstorage_volume_attach_v2.host_name?

时间:2018-07-04 21:37:14

标签: terraform

我定义了一个没有自定义卷附件的实例。这是别人成功创建的。现在,我尝试添加另一个实例,除了

  • 资源ID
  • openstack_compute_instance_v2.name
  • 它具有附加的卷。

.tf文件的相关位:

resource "openstack_compute_instance_v2" "foo_1" {
  name            = "foo_1"
  image_name      = "…"
  flavor_name     = "…"
  key_pair        = "${var.key_pair}"
  security_groups = […]
}

resource "openstack_blockstorage_volume_v2" "foo_volume_1" {
  name = "foo_volume_1"
  size = 100
}

resource "openstack_blockstorage_volume_attach_v2" "foo_volume_1_attachment" {
  volume_id = "${openstack_blockstorage_volume_v2.foo_volume_1.id}"
  host_name = "${openstack_compute_instance_v2.foo_1.name}"
}

当我尝试TF_LOG=TRACE terraform apply -target=openstack_compute_instance_v2.foo_1时,得到以下相关输出:

[TRACE] root: eval: *terraform.EvalWriteState
[TRACE] root: eval: *terraform.EvalApplyProvisioners
[TRACE] root: eval: *terraform.EvalIf
[TRACE] root: eval: *terraform.EvalWriteState
[TRACE] root: eval: *terraform.EvalWriteDiff
[TRACE] root: eval: *terraform.EvalApplyPost
[ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* openstack_compute_instance_v2.foo_1: Error creating OpenStack server: Invalid request due to incorrect syntax or missing required parameters.
[ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* openstack_compute_instance_v2.foo_1: Error creating OpenStack server: Invalid request due to incorrect syntax or missing required parameters.
[TRACE] [walkApply] Exiting eval tree: openstack_compute_instance_v2.foo_1
[TRACE] dag/walk: upstream errored, not walking "openstack_blockstorage_volume_attach_v2.foo_volume_1_attachment"
[TRACE] dag/walk: upstream errored, not walking "provider.openstack (close)"
[TRACE] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
[TRACE] dag/walk: upstream errored, not walking "root"
[…]
[DEBUG] plugin: waiting for all plugin processes to complete...
Error: Error applying plan:

1 error(s) occurred:

* openstack_compute_instance_v2.foo_1: 1 error(s) occurred:

* openstack_compute_instance_v2.foo_1: Error creating OpenStack server: Invalid request due to incorrect syntax or missing required parameters.

由于使用几乎相同的openstack_compute_instance_v2声明成功创建了另一个实例,因此我怀疑问题实际上出在文档host_name的确不正确的地方。在这种情况下是否应该指向实例的名称?如果没有,那应该指向什么?

1 个答案:

答案 0 :(得分:0)

错误消息原来是红色鲱鱼-我已使用相关信息更新了问题。问题在于,当指定依赖于密钥对的目标实例时,依赖关系无法解决,因此不会创建密钥对。由于密钥对是特定于帐户而不是租户的,因此terraform尝试创建一个引用不存在的密钥对的实例。

有趣的是,此命令对已经应用了其余架构的人员有效,因为他们的密钥对已经创建。