tektoncd / triggers

Event triggering with Tekton!
Apache License 2.0
546 stars 416 forks source link

TriggerTemplate `.spec.resourcetemplates` capitalization breaks Terraform `kubernetes_manifest` #1648

Closed CameronHudson8 closed 10 months ago

CameronHudson8 commented 10 months ago

Expected Behavior

It should be possible to create a TriggerTemplate using the Terraform kubernetes_manifest resource, based on the examples from the Tekton documentation.

Actual Behavior

Creation fails due to a capitalization conflict in the field .spec.resourcetemplates.

Steps to Reproduce the Problem

  1. Create a Terraform module, and use the hashicorp/kubernetes provider version 2.23.0.
  2. Create a kubernetes_manifest for the TriggerTemplate, and specify the field .spec.resourcetemplates (example below).
  3. Run terraform plan or terraform apply and encounter an error (example below).
  4. Change the field .spec.resourcetemplates to .spec.resourceTemplates.
  5. Run terraform plan and terraform apply successfully.

Additional Info

PS: Thank you for creating and maintaining Tekton. It rocks! 🙂

CameronHudson8 commented 10 months ago

Unfortunately, while it is possible to terraform apply the TriggerTemplate after changing the capitalization, Terraform subsequently emits an error, and the resource is tainted. So there isn't a clean workaround at the moment.

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ module.tekton_pipelines.module.trigger_templates.kubernetes_manifest.trigger_template_github_image_pr,
│ provider "provider[\"registry.terraform.io/hashicorp/kubernetes\"]"
│ produced an unexpected new value: .object: wrong final value type:
│ attribute "spec": attribute "resourceTemplates" is required.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵

Performing terraform plan after this shows a persistent diff in the state.

 # module.tekton_pipelines.module.trigger_templates.kubernetes_manifest.trigger_template_github_image_pr is tainted, so must be replaced
-/+ resource "kubernetes_manifest" "trigger_template_github_image_pr" {
      ~ object   = {
          ~ spec       = {
              + resourceTemplates = [
                  + {
                      + apiVersion = "tekton.dev/v1"
                      + kind       = "PipelineRun"
                      + metadata   = {
                          + generateName = "github-image-pr-"
                        }
                      + spec       = {
                          + params          = [
                              + {
                                  + name  = "github-status-url"
                                  + value = "$(tt.params.github-status-url)"
                                },
                              + {
                                  + name  = "pr-number"
                                  + value = "$(tt.params.pr-number)"
                                },
                              + {
                                  + name  = "repo-name"
                                  + value = "$(tt.params.repo-name)"
                                },
                              + {
                                  + name  = "repo-url"
                                  + value = "$(tt.params.repo-url)"
                                },
                            ]
                          + pipelineRef     = {
                              + name = "github-image-pr"
                            }
                          + taskRunTemplate = {
                              + serviceAccountName = "cicd-bot"
                            }
                          + workspaces      = [
                              + {
                                  + name                = "default"
                                  + volumeClaimTemplate = {
                                      + spec = {
                                          + accessModes = [
                                              + "ReadWriteOnce",
                                            ]
                                          + resources   = {
                                              + requests = {
                                                  + storage = "512Mi"
                                                }
                                            }
                                        }
                                    }
                                },
                            ]
                        }
                    },
                ]
              - resourcetemplates = [
                  - {
                      - apiVersion = "tekton.dev/v1"
                      - kind       = "PipelineRun"
                      - metadata   = {
                          - generateName = "github-image-pr-"
                        }
                      - spec       = {
                          - params          = [
                              - {
                                  - name  = "github-status-url"
                                  - value = "$(tt.params.github-status-url)"
                                },
                              - {
                                  - name  = "pr-number"
                                  - value = "$(tt.params.pr-number)"
                                },
                              - {
                                  - name  = "repo-name"
                                  - value = "$(tt.params.repo-name)"
                                },
                              - {
                                  - name  = "repo-url"
                                  - value = "$(tt.params.repo-url)"
                                },
                            ]
                          - pipelineRef     = {
                              - name = "github-image-pr"
                            }
                          - taskRunTemplate = {
                              - serviceAccountName = "cicd-bot"
                            }
                          - workspaces      = [
                              - {
                                  - name                = "default"
                                  - volumeClaimTemplate = {
                                      - spec = {
                                          - accessModes = [
                                              - "ReadWriteOnce",
                                            ]
                                          - resources   = {
                                              - requests = {
                                                  - storage = "512Mi"
                                                }
                                            }
                                        }
                                    }
                                },
                            ]
                        }
                    },
                ]
                # (1 unchanged attribute hidden)
            }
            # (3 unchanged attributes hidden)
        }
        # (1 unchanged attribute hidden)
    }
savitaashture commented 10 months ago

Hi @CameronHudson8 :wave:

I followed the steps which you have provided but i did not see any issue

  1. Created terraform code which you have provided
  2. did terraform apply
  3. Below is the output of terraform apply
$ terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # kubernetes_manifest.trigger_template_github_image_pr will be created
  + resource "kubernetes_manifest" "trigger_template_github_image_pr" {
      + manifest = {
          + apiVersion = "triggers.tekton.dev/v1beta1"
          + kind       = "TriggerTemplate"
          + metadata   = {
              + name      = "github-image-pr"
              + namespace = "tekton-pipelines"
            }
          + spec       = {
              + params            = [
                  + {
                      + name = "github-status-url"
                    },
                  + {
                      + name = "pr-number"
                    },
                  + {
                      + name = "repo-name"
                    },
                  + {
                      + name = "repo-url"
                    },
                ]
              + resourcetemplates = [
                  + {
                      + apiVersion = "tekton.dev/v1"
                      + kind       = "PipelineRun"
                      + metadata   = {
                          + generateName = "github-image-pr-"
                        }
                      + spec       = {
                          + params          = [
                              + {
                                  + name  = "github-status-url"
                                  + value = "$(tt.params.github-status-url)"
                                },
                              + {
                                  + name  = "pr-number"
                                  + value = "$(tt.params.pr-number)"
                                },
                              + {
                                  + name  = "repo-name"
                                  + value = "$(tt.params.repo-name)"
                                },
                              + {
                                  + name  = "repo-url"
                                  + value = "$(tt.params.repo-url)"
                                },
                            ]
                          + pipelineRef     = {
                              + name = "github-image-pr"
                            }
                          + taskRunTemplate = {
                              + serviceAccountName = "tekton-triggers-example-sa"
                            }
                          + workspaces      = [
                              + {
                                  + name                = "default"
                                  + volumeClaimTemplate = {
                                      + spec = {
                                          + accessModes = [
                                              + "ReadWriteOnce",
                                            ]
                                          + resources   = {
                                              + requests = {
                                                  + storage = "512Mi"
                                                }
                                            }
                                        }
                                    }
                                },
                            ]
                        }
                    },
                ]
            }
        }
      + object   = {
          + apiVersion = "triggers.tekton.dev/v1beta1"
          + kind       = "TriggerTemplate"
          + metadata   = {
              + name      = "github-image-pr"
              + namespace = "tekton-pipelines"
            }
          + spec       = {
              + params            = [
                  + {
                      + name = "github-status-url"
                    },
                  + {
                      + name = "pr-number"
                    },
                  + {
                      + name = "repo-name"
                    },
                  + {
                      + name = "repo-url"
                    },
                ]
              + resourcetemplates = [
                  + {
                      + apiVersion = "tekton.dev/v1"
                      + kind       = "PipelineRun"
                      + metadata   = {
                          + generateName = "github-image-pr-"
                        }
                      + spec       = {
                          + params          = [
                              + {
                                  + name  = "github-status-url"
                                  + value = "$(tt.params.github-status-url)"
                                },
                              + {
                                  + name  = "pr-number"
                                  + value = "$(tt.params.pr-number)"
                                },
                              + {
                                  + name  = "repo-name"
                                  + value = "$(tt.params.repo-name)"
                                },
                              + {
                                  + name  = "repo-url"
                                  + value = "$(tt.params.repo-url)"
                                },
                            ]
                          + pipelineRef     = {
                              + name = "github-image-pr"
                            }
                          + taskRunTemplate = {
                              + serviceAccountName = "tekton-triggers-example-sa"
                            }
                          + workspaces      = [
                              + {
                                  + name                = "default"
                                  + volumeClaimTemplate = {
                                      + spec = {
                                          + accessModes = [
                                              + "ReadWriteOnce",
                                            ]
                                          + resources   = {
                                              + requests = {
                                                  + storage = "512Mi"
                                                }
                                            }
                                        }
                                    }
                                },
                            ]
                        }
                    },
                ]
            }
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Warning: This custom resource does not have an associated OpenAPI schema.
│ 
│   with kubernetes_manifest.trigger_template_github_image_pr,
│   on main.tf line 1, in resource "kubernetes_manifest" "trigger_template_github_image_pr":
│    1: resource "kubernetes_manifest" "trigger_template_github_image_pr" {
│ 
│ We could not find an OpenAPI schema for this custom resource. Updates to this resource will cause a forced replacement.
╵

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

kubernetes_manifest.trigger_template_github_image_pr: Creating...
kubernetes_manifest.trigger_template_github_image_pr: Creation complete after 0s
╷
│ Warning: This custom resource does not have an associated OpenAPI schema.
│ 
│   with kubernetes_manifest.trigger_template_github_image_pr,
│   on main.tf line 1, in resource "kubernetes_manifest" "trigger_template_github_image_pr":
│    1: resource "kubernetes_manifest" "trigger_template_github_image_pr" {
│ 
│ We could not find an OpenAPI schema for this custom resource. Updates to this resource will cause a forced replacement.
╵

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  1. `TriggerTemplate created successfully

    $ kubectl get tt -n tekton-pipelines
    NAME              AGE
    github-image-pr   7s
  2. Kubectl version

    $ kubectl version
    WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
    Client Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.6", GitCommit:"11902a838028edef305dfe2f96be929bc4d114d8", GitTreeState:"archive", BuildDate:"2023-06-15T00:00:00Z", GoVersion:"go1.20.4", Compiler:"gc", Platform:"linux/amd64"}
    Kustomize Version: v4.5.7
    Server Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.3", GitCommit:"9e644106593f3f4aa98f8a84b23db5fa378900bd", GitTreeState:"clean", BuildDate:"2023-03-15T13:33:12Z", GoVersion:"go1.19.7", Compiler:"gc", Platform:"linux/amd64"}
  3. Terraform version

    
    $ terraform  version
    Terraform v1.5.7
    on linux_amd64
    + provider registry.terraform.io/hashicorp/kubernetes v2.17.0


Let me know if i misunderstand your question
CameronHudson8 commented 10 months ago

I started from scratch, this time with a cluster of kubernetes version 1.27, and I'm no longer able to reproduce it. Weird, but works for me!