From b1062b37ec3190ddbeca05bb87e96f81961cf30b Mon Sep 17 00:00:00 2001 From: Tamas Kiss Date: Thu, 26 May 2022 23:17:00 +0200 Subject: [PATCH] ci: added ci pipelines --- .drone.yml | 68 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 35 +++++++++++++++++++++ scripts/format.sh | 21 +++++++++++++ scripts/generate-docs.sh | 2 +- scripts/validate.sh | 22 +++++++++++++ 5 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 .drone.yml create mode 100644 .gitignore create mode 100755 scripts/format.sh create mode 100755 scripts/validate.sh diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..6370155 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,68 @@ +--- +kind: pipeline +type: kubernetes +name: Vet + +trigger: + event: + - push + - tag + +environment: + TF_IN_AUTOMATION: "1" + +steps: +- name: get terraform + image: hashicorp/terraform:1.1.8 + commands: + - mv /bin/terraform . + +- name: Generate docs + image: ubuntu:22.04 + commands: + - mv terraform /bin/terraform + - apt-get update && apt-get -y install git wget + - wget https://github.com/terraform-docs/terraform-docs/releases/download/v0.16.0/terraform-docs-v0.16.0-linux-amd64.tar.gz -O - | tar -xz terraform-docs -C /usr/local/bin + - scripts/format.sh + - scripts/generate-docs.sh + - git diff-index --name-status HEAD + +--- +kind: pipeline +type: kubernetes +name: Terraform validate + +trigger: + event: + - push + - tag + branch: + - main + +environment: + TF_IN_AUTOMATION: "1" + +steps: +- name: get terraform + image: hashicorp/terraform:1.1.8 + commands: + - mv /bin/terraform . + +- name: validate + image: ubuntu:22.04 + commands: + - mkdir -p ~/.ssh + - chmod 755 ~/.ssh + - echo "$${CI_SSH_KEY}" | base64 -d > ~/.ssh/id_rsa + - chmod 600 ~/.ssh/id_rsa + - mv terraform /bin/terraform + - scripts/validate.sh + environment: + GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no" + CI_SSH_KEY: + from_secret: ci-ssh-key +--- +kind: signature +hmac: fe3dd25a32f51ba75f0e1aac4e8d4708fdac266a06ec4b3dbb4b8656f42a84ec + +... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d4488d --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc + diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 0000000..be587b7 --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -euo pipefail + +for DIR in $(find . -type d); do + + if [[ "${DIR}" = "." ]] || [[ $(echo ${DIR} | cut -c1-5) = ".git/" ]]; then + continue; + fi + + pushd $DIR + terraform_files=$(find . -maxdepth 1 -type f -iname '*.tf') + if [[ ${#terraform_files} -eq 0 ]]; then + popd + continue + fi + + terraform fmt + + popd +done diff --git a/scripts/generate-docs.sh b/scripts/generate-docs.sh index 1acb0e2..ed4f3fb 100755 --- a/scripts/generate-docs.sh +++ b/scripts/generate-docs.sh @@ -15,4 +15,4 @@ for DIR in $(find . -type d); do terraform-docs markdown document . > README.md popd -done \ No newline at end of file +done diff --git a/scripts/validate.sh b/scripts/validate.sh new file mode 100755 index 0000000..7840d37 --- /dev/null +++ b/scripts/validate.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -euo pipefail + +for DIR in $(find . -type d); do + + if [[ "${DIR}" = "." ]] || [[ $(echo ${DIR} | cut -c1-5) = ".git/" ]]; then + continue; + fi + + pushd $DIR + terraform_files=$(find . -maxdepth 1 -type f -iname '*.tf') + if [[ ${#terraform_files} -eq 0 ]]; then + popd + continue + fi + + terraform init + terraform validate + + popd +done