Skip to content

Commit

Permalink
chore: tofu migration (#28)
Browse files Browse the repository at this point in the history
Signed-off-by: Zack A <24322023+zack-is-cool@users.noreply.github.com>
  • Loading branch information
zack-is-cool authored Jun 18, 2024
1 parent 300b9db commit 1d169b5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
22 changes: 14 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,35 @@ repos:
rev: v1.0.0-rc.1
hooks:
- id: go-fmt
args: [-s, -w, ./test]
- id: golangci-lint
args:
- "--timeout=10m"
- "--verbose"
- "--allow-parallel-runners"
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.89.1
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.3 # 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.356.1
rev: 37.411.0
hooks:
- id: renovate-config-validator
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -119,20 +119,20 @@ 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
$(MAKE) _runhooks HOOK="renovate-config-validator" SKIP=""

.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
docker run $(TTY_ARG) --rm -v "${PWD}:/app" --workdir "/app" -e "PRE_COMMIT_HOME=/app/.cache/pre-commit" ${BUILD_HARNESS_REPO}:${BUILD_HARNESS_VERSION} chmod -R a+rx .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"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# terraform-aws-transit-gateway
Repo provides module to create (or not, if already existing) transit gateway(s), handle attachments, and routes, and more
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- BEGINNING OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -80,4 +80,4 @@ Repo provides module to create (or not, if already existing) transit gateway(s),
| <a name="output_transit_gateway_route_ids"></a> [transit\_gateway\_route\_ids](#output\_transit\_gateway\_route\_ids) | Transit Gateway route identifiers combined with destinations |
| <a name="output_transit_gateway_route_table_id"></a> [transit\_gateway\_route\_table\_id](#output\_transit\_gateway\_route\_table\_id) | Transit Gateway route table ID |
| <a name="output_transit_gateway_vpc_attachment_ids"></a> [transit\_gateway\_vpc\_attachment\_ids](#output\_transit\_gateway\_vpc\_attachment\_ids) | Transit Gateway VPC attachment IDs |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
4 changes: 2 additions & 2 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# complete

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- BEGINNING OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -47,4 +47,4 @@
| <a name="output_debug"></a> [debug](#output\_debug) | n/a |
| <a name="output_new_transit_gateway"></a> [new\_transit\_gateway](#output\_new\_transit\_gateway) | n/a |
| <a name="output_new_transit_gateway_config"></a> [new\_transit\_gateway\_config](#output\_new\_transit\_gateway\_config) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
4 changes: 2 additions & 2 deletions modules/subnet_route/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# subnet_route

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- BEGINNING OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -42,4 +42,4 @@ No modules.
| <a name="output_route_config_list"></a> [route\_config\_list](#output\_route\_config\_list) | Route configuration list |
| <a name="output_route_config_map"></a> [route\_config\_map](#output\_route\_config\_map) | Route configuration map |
| <a name="output_subnet_route_ids"></a> [subnet\_route\_ids](#output\_subnet\_route\_ids) | Subnet route identifiers combined with destinations |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
4 changes: 2 additions & 2 deletions modules/transit_gateway_route/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# transit_gateway_route

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- BEGINNING OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
## Requirements

| Name | Version |
Expand Down Expand Up @@ -38,4 +38,4 @@ No modules.
|------|-------------|
| <a name="output_transit_gateway_route_config"></a> [transit\_gateway\_route\_config](#output\_transit\_gateway\_route\_config) | Transit Gateway route configuration |
| <a name="output_transit_gateway_route_ids"></a> [transit\_gateway\_route\_ids](#output\_transit\_gateway\_route\_ids) | Transit Gateway route identifiers combined with destinations |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
<!-- END OF PRE-COMMIT-OPENTOFU DOCS HOOK -->
8 changes: 5 additions & 3 deletions test/e2e/examples_complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -31,7 +32,8 @@ func TestExamplesCompleteCommon(t *testing.T) {
}

terraformOptionsWithVPCs := &terraform.Options{
TerraformDir: tempFolder,
TerraformBinary: "tofu",
TerraformDir: tempFolder,
Targets: []string{
"module.vpc_prod",
"module.vpc_dev",
Expand Down

0 comments on commit 1d169b5

Please sign in to comment.