如何设置厨师节点"正常" Terraform中的属性

时间:2017-07-23 16:50:26

标签: chef terraform

我有以下terraform文件:

resource "aws_instance" "hazelcast" {
ami           = "ami-11aa8c74"
instance_type = "t2.micro"
key_name      = "demo_terraform"
security_groups = ["ssh"]
tags {
      Name = "chef node - hazelcast"
}
provisioner "chef" {
  environment     = "${var.chef_environment}"
  run_list        = "${var.chef_run_list_hazelcast}"
  node_name       = "hazelcast_node"
  server_url      = "https://${var.chef_server}/organizations/${var.chef_organization}"
  secret_key      = "${file("~/terraform/chef-repo/encrypted_data_bag_secret")}"
  recreate_client = true
  ssl_verify_mode = ":verify_none"
  user_name       = "${var.chef_username}"
  user_key        = "${file("~/terraform/chef-repo/.chef/${var.chef_username}.pem")}"
  version         = "${var.chef_client_version}"
  attributes_json = <<-EOF
  {
    "team": "Cloud",
    "install_mancenter": false,
    "hazelcast_version": "3.6.2-2",
    "max_heap_size": "1G",
    "min_heap_size": "1G"      }
}
connection {
  type     = "ssh"
  user = "ec2-user"
  private_key = "${file("/temp/basics/demo_terraform.pem")}"
  agent = false
}
}
resource "aws_eip" "hazelcast" {
  instance   = "${aws_instance.hazelcast.id}"
  depends_on = ["aws_instance.hazelcast"]
}
output "address_hazelcast" {
    value = "${aws_instance.hazelcast.public_ip}"
}

在hazelcast配方中,我使用上面定义的常规属性来搜索具有相同特征的节点:

nodes = search(:node, "role:lc_hazelcast AND chef_environment:#{node.chef_environment} AND team:#{node.team}")

我还将常规属性存储在一些变量中:

hazelcast_version=node.hazelcast_version
min_heap_size=node.min_heap_size
max_heap_size=node.max_heap_size

问题在于,当我运行terraform apply时,我收到此错误:

aws_instance.hazelcast (chef): NoMethodError
aws_instance.hazelcast (chef): -------------
aws_instance.hazelcast (chef): undefined method `team' for #
<Chef::Node::Attribute:0x00000003752350>

说它找不到我在tf文件中定义的任何属性。

我应该如何定义普通属性,以便在节点被引导并运行运行列表时可以看到这些属性?

我错过了什么? 谢谢, 加布里埃尔

1 个答案:

答案 0 :(得分:1)

那应该是node["team"]。我们很久以前就弃用了方法语法,并在Chef 13中删除了它。