From 361f00d873f298d2716cd9bb0c1ccc91719e0197 Mon Sep 17 00:00:00 2001 From: Christophe Chaudier <devops@cchaudier.fr> Date: Sun, 10 Mar 2019 09:24:13 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8(terraform)=20add=20check=20syntax?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 5 +++++ gci-templates/job/terraform/lint.yml | 26 ++++++++++++++++++++++++++ test/terraform/output.tf | 3 +++ test/terraform/terraform.tfstate | 22 ++++++++++++++++++++++ test/terraform/variables.tf | 3 +++ 5 files changed, 59 insertions(+) create mode 100644 gci-templates/job/terraform/lint.yml create mode 100644 test/terraform/output.tf create mode 100644 test/terraform/terraform.tfstate create mode 100644 test/terraform/variables.tf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3004579..5da5aae 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,6 +12,7 @@ include: - '/gci-templates/job/bats.yml' - '/gci-templates/job/bash-lint.yml' - '/gci-templates/job/docker-lint.yml' + - '/gci-templates/job/terraform/lint.yml' ansible-syntax-check: variables: @@ -32,3 +33,7 @@ bash-lint: docker-lint: variables: working_directory: "test/docker" + +terraform:syntax-check: + variables: + working_directory: "test/terraform" diff --git a/gci-templates/job/terraform/lint.yml b/gci-templates/job/terraform/lint.yml new file mode 100644 index 0000000..3457e15 --- /dev/null +++ b/gci-templates/job/terraform/lint.yml @@ -0,0 +1,26 @@ +--- +# -*- coding: utf-8 -*- + +terraform:syntax-check: + extends: .base_tpl + # https://hub.docker.com/r/hashicorp/terraform/tags + image: + name: hashicorp/terraform + entrypoint: ["/bin/sh", "-c"] + stage: lint + script: | + cd $working_directory + terraform validate + +terraform:lint: + extends: .base_tpl + # https://hub.docker.com/r/hashicorp/terraform/tags + image: + name: wata727/tflint + entrypoint: ["/bin/sh", "-c"] + stage: lint + dependencies: + - terraform:syntax-check + script: | + cd $working_directory + tflint diff --git a/test/terraform/output.tf b/test/terraform/output.tf new file mode 100644 index 0000000..1baf346 --- /dev/null +++ b/test/terraform/output.tf @@ -0,0 +1,3 @@ +output "foo" { + value = "${var.foo}" +} diff --git a/test/terraform/terraform.tfstate b/test/terraform/terraform.tfstate new file mode 100644 index 0000000..5f82ece --- /dev/null +++ b/test/terraform/terraform.tfstate @@ -0,0 +1,22 @@ +{ + "version": 3, + "terraform_version": "0.11.10", + "serial": 1, + "lineage": "4e27243c-7796-41fc-5b63-a4b8a4e92cee", + "modules": [ + { + "path": [ + "root" + ], + "outputs": { + "foo": { + "sensitive": false, + "type": "string", + "value": "bar" + } + }, + "resources": {}, + "depends_on": [] + } + ] +} diff --git a/test/terraform/variables.tf b/test/terraform/variables.tf new file mode 100644 index 0000000..8ea7201 --- /dev/null +++ b/test/terraform/variables.tf @@ -0,0 +1,3 @@ +variable "foo" { + default = "bar" +} -- GitLab From e32e9b068f9908c025e88dc5ee30e54c19b8cdba Mon Sep 17 00:00:00 2001 From: Christophe Chaudier <devops@cchaudier.fr> Date: Sun, 10 Mar 2019 10:20:18 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8(terraform)=20add=20linter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitlab-ci.yml | 6 +++++- gci-templates/job/terraform/lint.yml | 6 ++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5da5aae..231d057 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,6 +34,10 @@ docker-lint: variables: working_directory: "test/docker" -terraform:syntax-check: +terraform-syntax-check: + variables: + working_directory: "test/terraform" + +terraform-lint: variables: working_directory: "test/terraform" diff --git a/gci-templates/job/terraform/lint.yml b/gci-templates/job/terraform/lint.yml index 3457e15..8255d98 100644 --- a/gci-templates/job/terraform/lint.yml +++ b/gci-templates/job/terraform/lint.yml @@ -1,7 +1,7 @@ --- # -*- coding: utf-8 -*- -terraform:syntax-check: +terraform-syntax-check: extends: .base_tpl # https://hub.docker.com/r/hashicorp/terraform/tags image: @@ -12,15 +12,13 @@ terraform:syntax-check: cd $working_directory terraform validate -terraform:lint: +terraform-lint: extends: .base_tpl # https://hub.docker.com/r/hashicorp/terraform/tags image: name: wata727/tflint entrypoint: ["/bin/sh", "-c"] stage: lint - dependencies: - - terraform:syntax-check script: | cd $working_directory tflint -- GitLab