-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent inconsistent planning #46
Conversation
source: zenobios:fix/162-inconsistent_planning Signed-off-by: Adphi <[email protected]>
@Adphi thanks for raising a pr, however I cannot reproduce the original issue with the latest tip of terraform {
required_version = ">= 0.13"
required_providers {
kubectl = {
source = "alekc/kubectl"
}
}
}
provider "kubectl" {
load_config_file = true
}
locals {
date = tonumber(formatdate("YYYYM", timestamp()))
is_even = local.date % 2 == 0
}
resource "kubectl_manifest" "test" {
yaml_body = <<YAML
terraform {
required_version = ">= 0.13"
required_providers {
kubectl = {
source = "alekc/kubectl"
version = "2.0.2"
}
}
}
provider "kubectl" {
load_config_file = true
}
locals {
date = tonumber(formatdate("YYYYM", timestamp()))
is_even = local.date % 2 == 0
}
resource "kubectl_manifest" "test" {
yaml_body = <<YAML
apiVersion: v1
kind: ConfigMap
metadata:
name: test-cm
namespace: default
data:
test: "static"
month_parity: "${local.is_even ? "even" : "odd"}"
YAML
} Do you have an example of reproduction of the error on |
@alekc here is what I used to test: main.tf: provider "kubectl" {}
provider "kubernetes" {
config_path = "~/.kube/config"
}
locals {
var = formatdate("YYYYMMDDhhmmss", timestamp())
}
resource "kubernetes_namespace" "test" {
metadata {
name = "terraform-test"
labels = {
"test" = local.var
}
}
}
resource "kubectl_manifest" "secret" {
yaml_body = data.template_file.secret.rendered
override_namespace = kubernetes_namespace.test.metadata.0.name
}
data template_file "secret" {
template = file("${path.module}/secret.yaml")
vars = {
var = kubernetes_namespace.test.metadata.0.resource_version
}
} secret.yaml: apiVersion: v1
kind: Secret
metadata:
name: test-secret
namespace: test
stringData:
var: "${var}" If you run it, it will succeed the first time, but fail every time after that because "var" is updated. |
Brilliant, thank you. I've been able to reproduce it with stripped down version
|
For some reason, the fix is not working with this version: terraform {
required_version = ">= 0.13"
required_providers {
kubectl = {
source = "alekc/kubectl"
version = ">= 2.0.0"
}
}
}
provider "kubectl" {}
provider "kubernetes" {
config_path = "~/.kube/config"
}
resource "kubernetes_namespace" "test" {
metadata {
name = "terraform-test"
labels = {
"test" = formatdate("YYYYMMDDhhmmss", timestamp())
}
}
}
resource "kubectl_manifest" "secret" {
yaml_body = <<-EOT
apiVersion: v1
kind: Secret
metadata:
name: test-secret
stringData:
var: "${kubernetes_namespace.test.metadata.0.resource_version}"
EOT
override_namespace = kubernetes_namespace.test.metadata.0.name
} |
@Adphi you are right. Raised a new issue to track and fix it. |
source: zenobios:fix/162-inconsistent_planning