From 347f62d8d2a04c5d2ac8870941d6f9aeb0a01c47 Mon Sep 17 00:00:00 2001 From: Karri Balk Date: Wed, 21 Jul 2021 18:25:37 -0400 Subject: [PATCH] chore: Update travis workflow and other CI/CD files --- .editorconfig | 11 ----- .gitignore | 12 ++---- .travis.yml | 28 +++++++++--- Dockerfile | 5 +-- Makefile | 2 +- main.tf | 9 +--- tests/create_ebs_encryption/main.tf | 6 --- tests/key_policy/main.tf | 5 --- tests/module_test.go | 66 ----------------------------- tests/no_kms_key/main.tf | 9 ---- 10 files changed, 30 insertions(+), 123 deletions(-) delete mode 100644 tests/module_test.go delete mode 100644 tests/no_kms_key/main.tf diff --git a/.editorconfig b/.editorconfig index 2e514aa..74f4dbf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,17 +13,6 @@ tab_width = 4 [*.md] trim_trailing_whitespace = false -[*.py] -indent_size = 4 - -[go.mod] -indent_style = tab -indent_size = 1 - -[*.go] -indent_style = tab -indent_size = 1 - [Makefile] indent_style = tab indent_size = 1 diff --git a/.gitignore b/.gitignore index f4f771c..5b251a8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,16 +8,12 @@ # .tfvars files *.tfvars -# ignore this file -!tfmodule-template.tf - # tardigrade-ci tardigrade-ci/ .tardigrade-ci -# eclint - -.git/ +# terraform lock file +.terraform.lock.hcl -# terratest -tests/git.* +# Cache created by pytest +tests/__pycache__/ diff --git a/.travis.yml b/.travis.yml index 7a67a21..ea1c83b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,35 @@ -dist: bionic +dist: focal -language: node_js - -node_js: - - "12" +language: minimal stages: - lint + - test - deploy +if: branch = master OR type = pull_request + +before_install: + - tmpdaemon=$(mktemp) + - sudo jq '."registry-mirrors" += ["https://mirror.gcr.io"]' /etc/docker/daemon.json > "$tmpdaemon" + - sudo mv "$tmpdaemon" /etc/docker/daemon.json + - sudo systemctl daemon-reload + - sudo systemctl restart docker + - docker system info + jobs: include: - stage: lint name: Project Syntax Verification - script: make && make docker/run target=lint + script: make docker/run target=lint + - stage: test + name: Apply Terraform test configs in mockstack + install: + - make docker-compose/install + - make mockstack/up + script: make mockstack/pytest + after_script: + - make mockstack/clean - stage: deploy if: branch = master AND type = push AND repo = plus3it/terraform-aws-tardigrade-ebs-encryption before_script: diff --git a/Dockerfile b/Dockerfile index c90f9d5..9ede817 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1 @@ -FROM plus3it/tardigrade-ci:0.14.0 - -WORKDIR /ci-harness -ENTRYPOINT ["make"] +FROM plus3it/tardigrade-ci:0.15.0 diff --git a/Makefile b/Makefile index 97bbf3e..64ad505 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ SHELL := /bin/bash --include $(shell curl -sSL -o .tardigrade-ci "https://raw.githubusercontent.com/plus3it/tardigrade-ci/master/bootstrap/Makefile.bootstrap"; echo .tardigrade-ci) +include $(shell test -f .tardigrade-ci || curl -sSL -o .tardigrade-ci "https://raw.githubusercontent.com/plus3it/tardigrade-ci/master/bootstrap/Makefile.bootstrap"; echo .tardigrade-ci) diff --git a/main.tf b/main.tf index 7d8a004..62131c5 100644 --- a/main.tf +++ b/main.tf @@ -1,8 +1,8 @@ ##### LOCALS ##### locals { # kms integration - kms_key_id = var.create_kms_key ? module.kms.keys[var.kms_key_alias].arn : "" - kms_key_policy = var.create_kms_key && var.kms_key_policy == null ? join("", data.aws_iam_policy_document.this.*.json) : var.kms_key_policy + kms_key_id = module.kms.keys[var.kms_key_alias].arn + kms_key_policy = var.kms_key_policy == null ? join("", data.aws_iam_policy_document.this.*.json) : var.kms_key_policy keys = [ { @@ -18,7 +18,6 @@ locals { module "kms" { source = "git::https://github.com/plus3it/terraform-aws-tardigrade-kms.git?ref=2.0.0" - create_keys = var.create_kms_key keys = local.keys } @@ -27,8 +26,6 @@ resource "aws_ebs_encryption_by_default" "this" { } resource "aws_ebs_default_kms_key" "this" { - count = var.create_kms_key ? 1 : 0 - key_arn = local.kms_key_id } @@ -40,8 +37,6 @@ data "aws_caller_identity" "this" {} data "aws_partition" "this" {} data "aws_iam_policy_document" "this" { - count = var.create_kms_key ? 1 : 0 - statement { sid = "Allow access through EBS for all principals in the account that are authorized to use EBS" actions = [ diff --git a/tests/create_ebs_encryption/main.tf b/tests/create_ebs_encryption/main.tf index 0aa9b26..ace20c7 100644 --- a/tests/create_ebs_encryption/main.tf +++ b/tests/create_ebs_encryption/main.tf @@ -1,9 +1,3 @@ -provider "aws" { - region = "us-east-1" -} - module "create_ebs_encryption" { source = "../../" - - create_kms_key = true } diff --git a/tests/key_policy/main.tf b/tests/key_policy/main.tf index e5a0d3b..978bfb2 100644 --- a/tests/key_policy/main.tf +++ b/tests/key_policy/main.tf @@ -1,11 +1,6 @@ -provider "aws" { - region = "us-east-1" -} - module "create_ebs_encryption" { source = "../../" - create_kms_key = true kms_key_policy = data.aws_iam_policy_document.this.json } diff --git a/tests/module_test.go b/tests/module_test.go deleted file mode 100644 index 0943587..0000000 --- a/tests/module_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package testing - -import ( - "io/ioutil" - "log" - "os" - "strings" - "testing" - - "github.com/gruntwork-io/terratest/modules/terraform" -) - -func TestModule(t *testing.T) { - files, err := ioutil.ReadDir("./") - - if err != nil { - log.Fatal(err) - } - - for _, f := range files { - // look for directories with test cases in it - if f.IsDir() && f.Name() != "vendor" { - tfFiles, tfErr := ioutil.ReadDir(f.Name()) - - if tfErr != nil { - log.Fatal(tfErr) - } - - // check if directory contains terraform files - terraformDir := false - for _, tf := range tfFiles { - if strings.HasSuffix(tf.Name(), ".tf") { - terraformDir = true - break - } - } - - // create a test for each directory with terraform files in it - if terraformDir { - t.Run(f.Name(), func(t *testing.T) { - // check if a prereq directory exists - prereqDir := f.Name() + "/prereq/" - if _, err := os.Stat(prereqDir); err == nil { - prereqOptions := createTerraformOptions(prereqDir) - defer terraform.Destroy(t, prereqOptions) - terraform.InitAndApply(t, prereqOptions) - } - - // run terraform code for test case - terraformOptions := createTerraformOptions(f.Name()) - defer terraform.Destroy(t, terraformOptions) - terraform.InitAndApply(t, terraformOptions) - }) - } - } - } -} - -func createTerraformOptions(directory string) *terraform.Options { - terraformOptions := &terraform.Options{ - TerraformDir: directory, - NoColor: true, - } - - return terraformOptions -} diff --git a/tests/no_kms_key/main.tf b/tests/no_kms_key/main.tf deleted file mode 100644 index 33744fd..0000000 --- a/tests/no_kms_key/main.tf +++ /dev/null @@ -1,9 +0,0 @@ -provider "aws" { - region = "us-east-1" -} - -module "create_ebs_encryption" { - source = "../../" - - create_kms_key = false -}