0

I want to create Tekton pipeline for Azure Landing Zone, I have my source code in the GitHub repo.

Here is my task.yaml

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: tektonpipeline
spec:
  params:
    - name: working-dir
      description: The directory containing the Terraform configuration
      type: string
    - name: backend-config
      description: The backend configuration for Terraform
      type: string
    - name: source-repo
      description: The Git repository for the Terraform source code
      type: string
      default: "myrepo"
  steps:
    - name: clean-directory
      image: alpine:latest
      workingDir: /workspace/source-code
      command: ["sh", "-c", "rm -rf *"]
    - name: clone-source-code
      image: alpine/git:latest
      workingDir: /workspace/source-code
      command:
        - git
        - clone
        - "$(params.source-repo)"
        - .
    - name: terraform-init
      image: hashicorp/terraform:latest
      workingDir: /workspace/source-code
      command:
        - sh
        - -c
        - "terraform init -input=false -backend-config=${inputs.params.backend-config}"


    # - name: terraform-plan
    #   image: hashicorp/terraform:latest
    #   workingDir: "/workspace/source-code/$(params.working-dir)"
    #   command:
    #     - sh
    #     - -c
    #     - |
    #       terraform plan
    # - name: terraform-apply
    #   image: hashicorp/terraform:latest
    #   workingDir: "/workspace/source-code/$(params.working-dir)"
    #   command:
    #     - sh
    #     - -c
    #     - |
    #       terraform apply -auto-approve



Here is my TaskRun.yaml

apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: tektonpipeline-run
  namespace: azure-landing-zone
spec:
  taskRef:
    name: tektonpipeline
  params:
    - name: working-dir
      value: "mycodeazure/tektonazurelz"
    - name: backend-config
      value: |
        bucket = "mybucket"
        key    = "mycodeazure/azure-enterprise-lz/azure-enterprise"
        region = "us-east-1"
        secret_key = ""
        secret_key = ""
    - name: source-repo
      value: "myrepo"

Error

"step-terraform-init" exited with code 2 (image: "docker-pullable://hashicorp/terraform@sha256:1ab70aa9b5dcc007d1d908c972405e2623490a51843a500682809013a4d21699"); for logs run: kubectl -n azure-landing-zone logs tektonpipeline-run-pod -c step-terraform-init



kubectl logs -n azure-landing-zone tektonpipeline-run-pod -c step-terraform-init
sh: syntax error: bad substitution


kubectl exec -it -n azure-landing-zone tektonpipeline-run-pod --container=step-terraform-init -- sh
error: cannot exec into a container in a completed pod; current phase is Failed

I tried to execute the Tekton pipeline, when I faced an error at init, then I tried to fix init first, updating task.yaml to fix the issue. Expecting My Tekton pipeline for init, plan, and apply should get fixed.

user190245
  • 1,027
  • 1
  • 15
  • 31

0 Answers0