build: inject Terraform secrets to tekton-pipelines namespace

This commit is contained in:
Khue Doan 2021-12-25 03:03:46 +07:00
parent dd2bdff255
commit 27468592ce
3 changed files with 32 additions and 23 deletions

View File

@ -1,13 +1,3 @@
# TODO automate this
# kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/git-clone/0.5/git-clone.yaml
# kubectl create secret generic -n tekton-pipelines kube-config --from-file=$PWD/../metal/kubeconfig.yaml
# kubectl create secret generic -n tekton-pipelines terraform-env-vars \
# --from-literal=CLOUDFLARE_EMAIL=xxx@yyy.com \
# --from-literal=CLOUDFLARE_API_KEY=xxx \
# --from-literal=B2_APPLICATION_KEY_ID=xxx \
# --from-literal=B2_APPLICATION_KEY=xxx \
# --from-literal=TF_VAR_cloudflare_account_id=xxx
apiVersion: tekton.dev/v1beta1 apiVersion: tekton.dev/v1beta1
kind: Task kind: Task
metadata: metadata:
@ -18,18 +8,19 @@ spec:
stepTemplate: stepTemplate:
image: hashicorp/terraform:1.1.2 image: hashicorp/terraform:1.1.2
workingDir: /workspace/source/external workingDir: /workspace/source/external
envFrom:
- secretRef:
name: terraform-env-vars
volumeMounts: volumeMounts:
- name: terraform-credentials - name: terraform-secrets
mountPath: /root/.terraform.d/ mountPath: /root/.terraform.d/credentials.tfrc.json
subPath: credentials.tfrc.json
- name: terraform-secrets
mountPath: /workspace/source/external/terraform.tfvars
subPath: terraform.tfvars
command: command:
- terraform - terraform
volumes: volumes:
- name: terraform-credentials - name: terraform-secrets
secret: secret:
secretName: terraform-credentials secretName: terraform
steps: steps:
- name: lint - name: lint
args: args:

View File

@ -16,18 +16,30 @@
- name: b2_application_key - name: b2_application_key
prompt: Enter Backblaze application key (sensitive) prompt: Enter Backblaze application key (sensitive)
tasks: tasks:
- name: Render environment file
template:
src: ./terraform.tfvars.j2
dest: ./terraform.tfvars
- name: Ensure required namespaces exist - name: Ensure required namespaces exist
kubernetes.core.k8s: kubernetes.core.k8s:
name: "{{ item }}"
api_version: v1 api_version: v1
kind: Namespace kind: Namespace
name: "{{ item }}"
state: present state: present
loop: loop:
- tekton-pipelines - tekton-pipelines
- cert-manager - cert-manager
- external-dns - external-dns
- cloudflared - cloudflared
- name: Render environment file - name: Add Terraform secrets to Tekton namespace
template: kubernetes.core.k8s:
src: ./terraform.tfvars.j2 definition:
dest: ./terraform.tfvars apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: terraform
namespace: tekton-pipelines
data:
credentials.tfrc.json: "{{ lookup('file', '~/.terraform.d/credentials.tfrc.json') | b64encode }}"
terraform.tfvars: "{{ lookup('file', './terraform.tfvars') | b64encode }}"

View File

@ -2,10 +2,16 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
resources: resources:
# Pipeline
- https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml - https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
# Triggers
- https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml - https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
- https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml - https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml
# Dashboard
- https://storage.googleapis.com/tekton-releases/dashboard/latest/tekton-dashboard-release-readonly.yaml - https://storage.googleapis.com/tekton-releases/dashboard/latest/tekton-dashboard-release-readonly.yaml
# Additional
- ingress.yaml - ingress.yaml
- service-account.yaml
- cluster-role-binding.yaml - cluster-role-binding.yaml
- service-account.yaml
# Tasks
- https://raw.githubusercontent.com/tektoncd/catalog/main/task/git-clone/0.5/git-clone.yaml