按照事实上的标准方法有条件地添加和删除块(1,2,3),当必须删除块时,我面临着生成计划的困难
我有以下tf配置。请注意dynamic
块:
provider "kubernetes" {}
variable secret {
type = string
}
resource "kubernetes_deployment" "sample-deployment" {
metadata {
name = "sample-deployment"
labels = {
app = "api"
}
}
spec {
selector {
match_labels = {
app = "sample"
}
}
template {
metadata {
labels = {
app = "sample"
}
}
spec {
dynamic image_pull_secrets {
for_each = compact([var.secret])
content {
name = var.secret
}
}
container {
name = "httpenv"
image = "jpetazzo/httpenv:latest"
}
}
}
}
}
然后我运行3个命令,一个接一个:
最初创建资源:
terraform apply -var secret=
已创建部署,并且image_pull_secret
不在差异中。
设置机密并更新资源:
terraform apply -var secret=my-secret
更新差异包含:
+ image_pull_secrets {
+ name = "my-secret"
}
删除机密并再次更新资源:
terraform apply -var secret=
输出为空白:
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
很明显,我缺少了一些东西,否则我会以为现在会出现这个问题。 我想念什么?
我使用的terraform版本是v0.12.16
。
更新。
运行后:
env TF_LOG=TRACE TF_LOG_PATH=logs.txt terraform apply -var secret=
我在logs.txt
中注意到了这一点:
2019/12/01 12:17:34 [WARN] Provider "kubernetes" produced an invalid plan for kubernetes_deployment.sample-deployment, but we are tolerating it because it is using the legacy plugin SDK.
The following problems may be the cause of any confusing errors from downstream operations:
- .spec[0].template[0].spec[0].image_pull_secrets: block count in plan (1) disagrees with count in config (0)
- .spec[0].template[0].spec[0].container[0].resources: block count in plan (1) disagrees with count in config (0)
- .spec[0].strategy: block count in plan (1) disagrees with count in config (0)
这与我面临的问题有关吗?
看起来像消息中提到block
的部分来自terraform代码。因此,我看到的问题一定不能与kubernetes提供者严格相关。是吗?