Terraform k8sraw 提供程序错误:产生了一个意外的新值,但在创建模板时现在不存在
Posted
技术标签:
【中文标题】Terraform k8sraw 提供程序错误:产生了一个意外的新值,但在创建模板时现在不存在【英文标题】:Terraform k8sraw provider error: produced an unexpected new value for was present, but now absent while template is created 【发布时间】:2021-12-09 07:46:28 【问题描述】:我们的 terraform 部署最近失败,出现错误:
Error: Provider produced inconsistent result after apply
When applying changes to k8sraw_yaml.test-template, provider
"registry.terraform.io/-/k8sraw" produced an unexpected new value for was
present, but now absent.
This is a bug in the provider, which should be reported in the provider's own
issue tracker.
k8sraw 提供者不是 terraform 官方提供者,它是从 github 获得的,该项目的 url 位于: https://github.com/nabancard/terraform-provider-kubernetes-yaml
提供程序在很长一段时间内都可以正常工作,直到一周前,我们发现它从 2021 年 10 月 15 日开始出现上述错误。
我们使用的 terraform 版本是 0.12.24
感谢帮助。
我有使用 k8sraw 的示例代码:
-
main.tf
terraform
required_version = ">= 0.12.0"
backend "s3"
provider "local"
version = "~> 1.4"
provider "template"
version = "~> 2.1"
provider "kubernetes"
version = ">=1.6.2"
config_path = "~/.kube/kube.conf"
provider "k8sraw"
data "template_file" "test-template"
template = "$file("$path.module/templates/test-template.yml.tpl")"
vars =
workflow_template_name = var.template_ref_name,
k8s_namespace = var.k8s_namespace,
resource "k8sraw_yaml" "test-template"
yaml_body = data.template_file.test-template.rendered
data "template_file" "workflow"
template = "$file("$path.module/templates/test-workflow.yml.tpl")"
vars =
test_template_ref = var.template_ref_name
service_account = "$var.service_account",
resource "local_file" "test-template-file"
filename = "$path.module/workflow/$var.test_template_file_name.yaml"
content = "$data.template_file.test-template.rendered"
resource "local_file" "workflow"
filename = "$path.module/workflow/$var.test_workflow_file_name.yaml"
content = data.template_file.workflow.rendered
-
变量.tf
variable "template_ref_name"
description = "workflow template name for detector pipeline"
type = string
default = "test-test-deploy-try-template"
variable "k8s_namespace"
description = "kubernetes namespace name"
type = string
default = "default"
variable "test_template_name"
description = "test workflow template name"
type = string
default = "test-template"
variable "test_workflow_file_name"
description = "filename for populated test workflow"
default = "test-workflow"
type = string
variable "test_template_file_name"
description = "filename for populated test template"
default = "test-template"
type = string
variable "service_account"
description = "workflow service account"
type = string
default = "default"
variable "env"
description = "deployment environment: test, dev, sit. and cit"
type = string
-
templates/test-workflow.yml.tpl
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: test-
spec:
entrypoint: hellomessage
serviceAccountName: "$service_account"
arguments:
parameters:
- name: message
templates:
# pipeline steps
- name: hellomessage
steps:
- - name: test-pipeline
templateRef:
name: $test_template_ref
template: test-pipeline
arguments:
parameters:
- name: message
value: "workflow.parameters.message"
-
模板/test-template.yml.tpl
---
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: $workflow_template_name
namespace: $k8s_namespace
spec:
templates:
- name: test-pipeline
inputs:
parameters:
- name: message
steps:
- - name: print-message
template: messageout
arguments:
parameters:
- name: message
value: "inputs.parameters.message"
# individual templates for each step
- name: messageout
retryStrategy:
limit: 3
backoff:
duration: "10" # Must be a string. Default unit is seconds. Could also be a Duration, e.g.: "2m", "6h", "1d"
factor: 2
maxDuration: "60m" # Must be a string. Default unit is seconds. Could also be a Duration, e.g.: "2m", "6h", "1d"
retryPolicy: "Always" # Retry on errors AND failures. Also available: "OnFailure" (default), "OnError"
resubmitPendingPods: true
inputs:
parameters:
- name: message
container:
image: 'docker/whalesay:latest'
command: [sh, -c]
args:
- >-
echo -n inputs.parameters.message > /tmp/hello_world.txt;
cat /tmp/hello_world.txt
-
vars/test.tfvars
k8s_namespace ="test-account"
service_account = "argo"
-
后端/后端.tfvars
region = "us-east-1"
bucket = "test"
key = "test/terraform.tfstate"
dynamodb_table = "test"
acl = "private"
-
地形命令:
$ terraform init -force-copy -upgrade -backend-config="backends/backend.tfvars"
$ terraform workspace select testdeployment || terraform workspace new testdeployment
$ terraform plan -var-file="vars/test.tfvars"
$ terraform apply -auto-approve -var-file="vars/test.tfvars"
【问题讨论】:
【参考方案1】:我在其他网站上找到了答案,所以答案是将terraform升级到0.14.9或更高,然后将k8sraw替换为kubernetes_manifest。
具体如何更改,请参考以下链接: https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest 和 https://www.terraform.io/docs/language/functions/yamldecode.html
干杯!
【讨论】:
虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。以上是关于Terraform k8sraw 提供程序错误:产生了一个意外的新值,但在创建模板时现在不存在的主要内容,如果未能解决你的问题,请参考以下文章
Terraform azurerm 提供程序尝试使用错误的凭据进行注册