Skip to content
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

Terraform k8sraw provider error: produced an unexpected new value for was present, but now absent while template is created #10

Open
xiangliang1 opened this issue Oct 22, 2021 · 2 comments

Comments

@xiangliang1
Copy link

Hi, there,

Our terraform deployment failed recently, with error:

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.

The k8sraw had been working fine for a long time until a week ago, we find it failed with above error from Oct 15, 2021.

The terraform version we used are 0.12.24

$ ../ht-traffic-signal/terraform -v
Terraform v0.12.24

Your version of Terraform is out of date! The latest version
is 1.0.9. You can update by downloading from https://www.terraform.io/downloads.html

Advanced thanks to any help.

I have example code that uses k8sraw:

  1. 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
}
  1. variables.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
}
  1. 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}}"
  1. templates/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
  1. vars/test.tfvars
k8s_namespace ="test-account"
service_account = "argo"
  1. backend/backend.tfvars
region = "us-east-1"
bucket = "test"
key = "test/terraform.tfstate"
dynamodb_table = "test"
acl = "private"
  1. Terraform Commands:
  $ 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"
@xiangliang1
Copy link
Author

Had anyone seen this post?

@TheDoubleJo
Copy link

I had the same issue and proceed to use this instead:
https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants