gpt4 book ai didi

docker - Terraform docker_container标签不起作用?

转载 作者:行者123 更新时间:2023-12-02 21:05:42 25 4
gpt4 key购买 nike

我正在尝试使用terraform将标签添加到docker容器中。 terraform documentation说使用“标签”。我试过了:

resource "docker_container" "my_test" {
image = "ubuntu:latest"
name = "my_test"
labels {
first = "label 1"
another = "label 2"
}
}

但是我明白了
Error: Unsupported block type

on dock.tf line 4, in resource "docker_container" "my_test":
4: labels {

Blocks of type "labels" are not expected here. Did you mean to define argument
"labels"? If so, use the equals sign to assign it a value.

我正在使用Terraform v0.12.9 + provider.docker v2.3.0。

知道我在做什么错吗?

最佳答案

看来labels是此实例中的一个属性。设置这些块的语法在Terraform 0.12.x中已更改。

您链接的资源引用仍显示pre 0.12.x方法。您可以通过image属性引用docker_image资源的方式来判断:image = "${docker_image.ubuntu.latest}"
注意labels = {:

resource "docker_container" "my_test" {
image = "ubuntu:latest"
name = "my_test"
labels = {
first = "label 1"
another = "label 2"
}
}

引用: https://www.terraform.io/upgrade-guides/0-12.html#attributes-vs-blocks

关于docker - Terraform docker_container标签不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58209072/

25 4 0