From 2687f676ab1dcdfe88be47b6b5f76bf6e5329139 Mon Sep 17 00:00:00 2001 From: Zack A <24322023+zack-is-cool@users.noreply.github.com> Date: Mon, 17 Jun 2024 11:16:35 -0700 Subject: [PATCH] chore: migrate to tofu (#139) --- .pre-commit-config.yaml | 17 +++++++++++------ Makefile | 8 ++++---- README.md | 4 ++-- examples/complete/README.md | 5 ++--- test/e2e/examples_complete_test.go | 5 +++-- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c6504a..2d50b36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -33,19 +33,24 @@ repos: rev: v1.91.0 hooks: - id: terraform_fmt - - id: terraform_docs + args: + - --hook-config=--tf-path=tofu + - id: terraform_tflint + args: + - --args=--config=__GIT_WORKING_DIR__/.tflint.hcl + - --hook-config=--tf-path=tofu + - repo: https://github.com/tofuutils/pre-commit-opentofu + rev: v1.0.2 # Get the latest from: https://github.com/tofuutils/pre-commit-opentofu/releases + hooks: + - id: tofu_docs args: - --args=--lockfile=false - --hook-config=--path-to-file=README.md # Valid UNIX path. I.e. ../TFDOC.md or docs/README.md etc. - --hook-config=--add-to-existing-file=true # Boolean. true or false - --hook-config=--create-file-if-not-exist=true # Boolean. true or false - - id: terraform_checkov - verbose: true + - id: tofu_checkov args: - --args=--config-file __GIT_WORKING_DIR__/.checkov.yml - - id: terraform_tflint - args: - - --args=--config=__GIT_WORKING_DIR__/.tflint.hcl - repo: https://github.com/renovatebot/pre-commit-hooks rev: 37.410.1 hooks: diff --git a/Makefile b/Makefile index 64524a7..2f93c21 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ _test-all: _create-folders -e SKIP_TEARDOWN \ $${TF_VARS} \ ${BUILD_HARNESS_REPO}:${BUILD_HARNESS_VERSION} \ - bash -c 'git config --global --add safe.directory /app && cd examples/complete && terraform init -upgrade=true && cd ../../test/e2e && go test -count 1 -v $(EXTRA_TEST_ARGS) .' + bash -c 'git config --global --add safe.directory /app && cd examples/complete && tofu init -upgrade=true && cd ../../test/e2e && go test -count 1 -v $(EXTRA_TEST_ARGS) .' .PHONY: test test: ## Run all automated tests. Requires access to an AWS account. Costs real money. @@ -119,7 +119,7 @@ pre-commit-terraform: ## Run the terraform pre-commit hooks. Returns nonzero exi .PHONY: pre-commit-golang pre-commit-golang: ## Run the golang pre-commit hooks. Returns nonzero exit code if any hooks fail. Uses Docker for maximum compatibility - $(MAKE) _runhooks HOOK="" SKIP="check-added-large-files,check-merge-conflict,detect-aws-credentials,detect-private-key,end-of-file-fixer,fix-byte-order-marker,trailing-whitespace,check-yaml,fix-smartquotes,terraform_fmt,terraform_docs,terraform_checkov,terraform_tflint,renovate-config-validator" + $(MAKE) _runhooks HOOK="" SKIP="check-added-large-files,check-merge-conflict,detect-aws-credentials,detect-private-key,end-of-file-fixer,fix-byte-order-marker,trailing-whitespace,check-yaml,fix-smartquotes,terraform_fmt,tofu_docs,tofu_checkov,terraform_tflint,renovate-config-validator" .PHONY: pre-commit-renovate pre-commit-renovate: ## Run the renovate pre-commit hooks. Returns nonzero exit code if any hooks fail. Uses Docker for maximum compatibility @@ -127,7 +127,7 @@ pre-commit-renovate: ## Run the renovate pre-commit hooks. Returns nonzero exit .PHONY: pre-commit-common pre-commit-common: ## Run the common pre-commit hooks. Returns nonzero exit code if any hooks fail. Uses Docker for maximum compatibility - $(MAKE) _runhooks HOOK="" SKIP="go-fmt,golangci-lint,terraform_fmt,terraform_docs,terraform_checkov,terraform_tflint,renovate-config-validator" + $(MAKE) _runhooks HOOK="" SKIP="go-fmt,golangci-lint,terraform_fmt,tofu_docs,tofu_checkov,terraform_tflint,renovate-config-validator" .PHONY: fix-cache-permissions fix-cache-permissions: ## Fixes the permissions on the pre-commit cache @@ -135,4 +135,4 @@ fix-cache-permissions: ## Fixes the permissions on the pre-commit cache .PHONY: autoformat autoformat: ## Update files with automatic formatting tools. Uses Docker for maximum compatibility. - $(MAKE) _runhooks HOOK="" SKIP="check-added-large-files,check-merge-conflict,detect-aws-credentials,detect-private-key,check-yaml,golangci-lint,terraform_checkov,terraform_tflint,renovate-config-validator" + $(MAKE) _runhooks HOOK="" SKIP="check-added-large-files,check-merge-conflict,detect-aws-credentials,detect-private-key,check-yaml,golangci-lint,tofu_checkov,terraform_tflint,renovate-config-validator" diff --git a/README.md b/README.md index 68937dd..4a1ccf0 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This repository contains Terraform configuration files that create an AWS Virtua To view examples for how you can leverage this VPC Module, please see the [examples](https://github.com/defenseunicorns/delivery-aws-iac/tree/main/examples) directory. - + ## Requirements | Name | Version | @@ -183,4 +183,4 @@ To view examples for how you can leverage this VPC Module, please see the [examp | [vpc\_main\_route\_table\_id](#output\_vpc\_main\_route\_table\_id) | The ID of the main route table associated with this VPC | | [vpc\_owner\_id](#output\_vpc\_owner\_id) | The ID of the AWS account that owns the VPC | | [vpc\_secondary\_cidr\_blocks](#output\_vpc\_secondary\_cidr\_blocks) | List of secondary CIDR blocks of the VPC | - + diff --git a/examples/complete/README.md b/examples/complete/README.md index f543e54..86aa9a6 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -1,12 +1,11 @@ # examples/complete - # examples/complete Example that uses the module with many of its configurations. Used in CI E2E tests. - + ## Requirements | Name | Version | @@ -52,4 +51,4 @@ Example that uses the module with many of its configurations. Used in CI E2E tes | Name | Description | |------|-------------| | [reserved\_ips\_per\_subnet](#output\_reserved\_ips\_per\_subnet) | n/a | - + diff --git a/test/e2e/examples_complete_test.go b/test/e2e/examples_complete_test.go index 85840c2..99b5fc7 100644 --- a/test/e2e/examples_complete_test.go +++ b/test/e2e/examples_complete_test.go @@ -18,8 +18,9 @@ func TestExamplesCompleteCommon(t *testing.T) { tempFolder := teststructure.CopyTerraformFolderToTemp(t, "../..", "examples/complete") terraformOptions := &terraform.Options{ - TerraformDir: tempFolder, - Upgrade: false, + TerraformBinary: "tofu", + TerraformDir: tempFolder, + Upgrade: false, EnvVars: map[string]string{ "TF_VAR_region": os.Getenv("TF_VAR_region"), // This will use the existing or newly set default value },