打开星云和地形上下文块错误

Open nebula & terraform context block error

我能够使用 terraform 创建虚拟机,但是…… 当我使用上下文块时,我遇到了问题

错误:不支持的块类型

在 terraform.tf 第 34 行,在资源“opennebula_template”“mytemplate”中: 34:上下文{

这里不需要“上下文”类型的块。你的意思是定义 争论“上下文”?如果是,请使用等号为其赋值。

我完全按照此处正式 Terraform 文档中的指南所示添加它 https://registry.terraform.io/providers/OpenNebula/opennebula/latest/docs/resources/virtual_machine

variable "one_endpoint" {}
variable "one_username" {}
variable "one_password" {}
variable "one_flow_endpoint" {}

provider "opennebula" {
  endpoint      = var.one_endpoint
  flow_endpoint = var.one_flow_endpoint
  username      = var.one_username
  password      = var.one_password
}

#########################################################################

resource "opennebula_image" "CentOS7-clone" {
    clone_from_image = 35
    name             = "CentOS7-clone"
    datastore_id     = 1
    persistent       = false
    permissions      = "660"
    group            = "oneadmin"
}

#########################################################################

resource "opennebula_virtual_machine" "demo" {
  count       = 1
  name        = "centos7"
  cpu         = 2
  vcpu        = 2
  memory      = 4096
  group       = "oneadmin"
  permissions = "660"

  context {
    NETWORK      = "YES"
    HOSTNAME     = "$NAME"
    START_SCRIPT ="yum upgrade"
  }

  graphics {
    type   = "VNC"
    listen = "0.0.0.0"
    keymap = "fr"
  }

  os {
    arch = "x86_64"
    boot = "disk0"
  }

  disk {
    image_id = opennebula_image.CentOS7-clone.id
    size     = 10000
    target   = "vda"
    driver   = "qcow2"
  }

  nic {
    model           = "virtio"
    network_id      = 7
    security_groups = [0]
  }

  vmgroup {
    vmgroup_id = 2
    role       = "vm-group"
  }

  tags = {
    environment = "dev"
  }

  timeout = 5
}

您需要使用等号定义上下文块,如下所示:

context = {
    NETWORK      = "YES"
    HOSTNAME     = "$NAME"
    START_SCRIPT ="yum upgrade"
}

只有 Terraform <0.12 才支持省略等号来定义属性(Terraform 0.12 Compatibility for Providers - Terraform by HashiCorp)。我们在更新 GitHub 存储库中的文档时遇到问题。