Skip to content

Commit 71d42fe

Browse files
feat(tf): default to tofu and allow switching back to terraform (#38)
## what - enanble users to easily switch between Terraform and Tofu ## why ## references - [INT-132](https://www.notion.so/masterpoint/Update-Taskit-Terraform-tasks-to-support-OpenTofu-and-Terraform-623c4b9433474021ad28d0c53d579f93) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Chores** * Updated dependencies to latest versions, including go-task, dasel, jq, and GitHub CLI * Updated registry reference to v4.433.0 * **New Features** * Added support for using OpenTofu as an alternative to Terraform through configuration <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent ac8f80c commit 71d42fe

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

Taskfile.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ includes:
44
aqua: lib/aqua
55
aws: lib/aws
66
components: lib/components
7-
cursor: lib/cursor
87
mixins: lib/mixins
98
os: lib/os-modules
109
snaplet: lib/snaplet
11-
terraform:
12-
taskfile: lib/terraform
13-
aliases: [tf]
10+
tf:
11+
taskfile: lib/tf
1412
toolbox: lib/toolbox
1513

1614
tasks: {}

aqua.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
registries:
33
- type: standard
4-
ref: v4.78.0 # renovate: depName=aquaproj/aqua-registry
4+
ref: v4.433.0 # renovate: depName=aquaproj/aqua-registry
55
packages:
6-
- name: go-task/task@v3.31.0
7-
- name: TomWright/dasel@v2.4.1
8-
- name: stedolan/jq@jq-1.7.1
6+
- name: go-task/task@v3.45.4
7+
- name: TomWright/dasel@v2.8.1
8+
- name: stedolan/jq@jq-1.8.1
99
tags: [cursor]
10-
- name: cli/cli@v2.74.2
10+
- name: cli/cli@v2.83.0
1111
tags: [gh]
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ tasks:
2424
sh: echo "{{.BACKEND_CONFIG_PATH}}/{{.WORKSPACE}}.backend.tf"
2525
TFVARS_FILE:
2626
sh: echo "{{.TFVARS_PATH}}/{{.WORKSPACE}}.tfvars"
27+
TF_CMD:
28+
sh: '[ "${USE_TERRAFORM}" = "true" ] && echo "terraform" || echo "tofu"'
2729

2830
init:
2931
desc: Initialize Terraform working directory with a backend configuration file.
@@ -39,7 +41,7 @@ tasks:
3941
- sh: test -f {{.BACKEND_CONFIG_FILE}}
4042
msg: "Backend configuration file does not exist: {{.BACKEND_CONFIG_FILE}}"
4143
cmds:
42-
- terraform init -backend-config {{.BACKEND_CONFIG_FILE}} {{.TF_ARGS}}
44+
- "{{.TF_CMD}} init -backend-config {{.BACKEND_CONFIG_FILE}} {{.TF_ARGS}}"
4345

4446
plan:
4547
desc: Generate a Terraform execution plan Terraform loading variable values from the given file.
@@ -56,8 +58,8 @@ tasks:
5658
- sh: test -f {{.TFVARS_FILE}}
5759
msg: "Variables file does not exist: {{.TFVARS_FILE}}"
5860
cmds:
59-
- terraform workspace select -or-create {{.WORKSPACE}}
60-
- terraform plan -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}
61+
- "{{.TF_CMD}} workspace select -or-create {{.WORKSPACE}}"
62+
- "{{.TF_CMD}} plan -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}"
6163

6264
apply:
6365
desc: Create or update infrastructure according to Terraform configuration files in the current directory.
@@ -74,8 +76,8 @@ tasks:
7476
- sh: test -f {{.TFVARS_FILE}}
7577
msg: "Variables file does not exist: {{.TFVARS_FILE}}"
7678
cmds:
77-
- terraform workspace select -or-create {{.WORKSPACE}}
78-
- terraform apply -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}
79+
- "{{.TF_CMD}} workspace select -or-create {{.WORKSPACE}}"
80+
- "{{.TF_CMD}} apply -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}"
7981

8082
refresh:
8183
desc: Refresh the Terraform state to match the real-world infrastructure (safer via apply -refresh-only).
@@ -92,5 +94,5 @@ tasks:
9294
- sh: test -f {{.TFVARS_FILE}}
9395
msg: "Variables file does not exist: {{.TFVARS_FILE}}"
9496
cmds:
95-
- terraform workspace select -or-create {{.WORKSPACE}}
96-
- terraform apply -refresh-only -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}
97+
- "{{.TF_CMD}} workspace select -or-create {{.WORKSPACE}}"
98+
- "{{.TF_CMD}} apply -refresh-only -var-file {{.TFVARS_FILE}} {{.TF_ARGS}}"

0 commit comments

Comments
 (0)