From 424e29bcac4d150c2e6aca1f4e687b44262b31cc Mon Sep 17 00:00:00 2001 From: David Bloss Date: Fri, 19 Jan 2024 10:39:37 -0600 Subject: [PATCH 1/6] update submodule hash, make tasks work the same in any dir --- Taskfile.yml | 113 ++++++++++++++++++++++++++++++++++++----- go.mod | 6 --- go.sum | 23 --------- opslevel/Taskfile.yml | 20 ++++---- submodules/opslevel-go | 2 +- workspace/Taskfile.yml | 104 ------------------------------------- 6 files changed, 112 insertions(+), 156 deletions(-) delete mode 100644 workspace/Taskfile.yml diff --git a/Taskfile.yml b/Taskfile.yml index 54496ae6..71d6d159 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -6,17 +6,21 @@ vars: # 'VERSION_DYNAMIC' needs to run in this scope before 'task build' begins VERSION_DYNAMIC: sh: echo "$(date +%s).0.0" + WORKSPACE_DIR: "workspace" includes: go: + internal: true taskfile: "./opslevel/Taskfile.yml" - terraform: - taskfile: "./workspace/Taskfile.yml" - dir: ./workspace - aliases: [tf] tasks: + apply: + desc: Run "terraform apply" + cmds: + - task: terraform-command + vars: { TF_COMMAND: "apply", TF_CMD_DIR: "{{.WORKSPACE_DIR}}" } + build: desc: Build local opslevel terraform provider platforms: [darwin] @@ -29,27 +33,58 @@ tasks: - mkdir -p {{.LOCATION}} - mv {{.BINARY}} {{.LOCATION}}/{{.BINARY}} + clean: + desc: Clean up terraform files from "{{.WORKSPACE_DIR}}" + dir: "{{.WORKSPACE_DIR}}" + prompt: Remove '*.tfstate .terraform.lock.hcl ./terraform.* .terraform/**' from '{{.WORKSPACE_DIR}}' directory? + cmds: + - cmd: rm -rf *.tfstate .terraform.lock.hcl ./terraform.* .terraform/ + ignore_error: true + + destroy: + desc: Run "terraform destroy" in "{{.WORKSPACE_DIR}}" + cmds: + - task: terraform-command + vars: { TF_COMMAND: "destroy", TF_CMD_DIR: "{{.WORKSPACE_DIR}}" } + + fix: + desc: Fix formatting and linting + cmds: + - task: go:fix + - task: format-fix + + init: + desc: Initialize terraform workspace + dir: "{{.WORKSPACE_DIR}}" + cmds: + - task: install-terraform + - './make_backend_tf.sh' + - touch main.tf + - task: terraform-command + vars: { TF_COMMAND: "init -upgrade", TF_CMD_DIR: "{{.WORKSPACE_DIR}}" } + install-changie: desc: Install changie aliases: [get-changie] cmds: - cmd: echo "Installing changie..." silent: true - - go install github.com/miniscruff/changie@latest - - cmd: echo -e "\nSuccess! 'changie' installed." + - which changie > /dev/null || go install github.com/miniscruff/changie@latest + - cmd: echo -e "Success! 'changie' installed." silent: true lint: desc: Check formatting and linting cmds: - task: go:lint - - task: terraform:lint + - task: validate + - task: format-check - lintfix: - desc: Fix formatting and linting + plan: + desc: Run "terraform plan" in "{{.WORKSPACE_DIR}}" cmds: - - task: go:lintfix - - task: terraform:lintfix + - task: terraform-command + vars: { TF_COMMAND: "plan", TF_CMD_DIR: "{{.WORKSPACE_DIR}}" } setup: desc: Setup env and tools @@ -57,7 +92,7 @@ tasks: - task: install-changie - task: go:setup - task: build - - task: terraform:init + - task: init test: desc: Run tests @@ -65,3 +100,57 @@ tasks: TF_ACC: true cmds: - task: go:test + + ######################################## + # internal (not directly called) tasks # + ######################################## + + format-check: + internal: true + desc: Run terraform format + cmds: + - cmd: echo "Listing all terraform files that need formatting..." + - task: terraform-command + vars: { TF_COMMAND: "fmt -recursive -check", TF_CMD_DIR: "{{.ROOT_DIR}}" } + + format-fix: + internal: true + desc: Run terraform format + cmds: + - task: terraform-command + vars: { TF_COMMAND: "fmt -recursive -write=true", TF_CMD_DIR: "{{.ROOT_DIR}}" } + + install-terraform: + internal: true + aliases: [get] + cmds: + - echo "Installing terraform..." + - task: install-terraform-mac-os + - echo -e "\nSuccess! 'terraform' installed." + + install-terraform-mac-os: + internal: true + platforms: [darwin] + cmds: + - brew tap hashicorp/tap + - brew install hashicorp/tap/terraform + preconditions: + - sh: 'which brew' + msg: '"brew" needed to install terraform - see https://brew.sh' + + terraform-command: + internal: true + cmds: ["terraform -chdir={{.TF_CMD_DIR}} {{.TF_COMMAND}} {{.CLI_ARGS}}"] + requires: + vars: [TF_COMMAND, TF_CMD_DIR] + preconditions: + - sh: 'which terraform' + msg: '"terraform" needed - run "brew install terraform"' + + validate: + internal: true + desc: Run "terraform validate" in current directory + dir: '{{.ROOT_DIR}}' + cmds: + - task: terraform-command + vars: { TF_COMMAND: "validate", TF_CMD_DIR: "{{.ROOT_DIR}}" } diff --git a/go.mod b/go.mod index 0b8d1c53..1f3dec20 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,6 @@ require ( github.com/gosimple/slug v1.13.1 // indirect github.com/gosimple/unidecode v1.0.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/go-checkpoint v0.5.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-getter v1.7.3 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect @@ -50,11 +49,7 @@ require ( github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/go-version v1.6.0 // indirect - github.com/hashicorp/hc-install v0.4.0 // indirect github.com/hashicorp/hcl/v2 v2.19.1 // indirect - github.com/hashicorp/terraform-exec v0.17.2 // indirect - github.com/hashicorp/terraform-json v0.14.0 // indirect - github.com/hashicorp/terraform-plugin-docs v0.13.0 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect github.com/hasura/go-graphql-client v0.10.2 // indirect @@ -76,7 +71,6 @@ require ( github.com/opslevel/moredefaults v0.0.0-20240112142637-078c8ff8ba9c // indirect github.com/posener/complete v1.2.3 // indirect github.com/relvacode/iso8601 v1.3.0 // indirect - github.com/russross/blackfriday v1.6.0 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/spf13/afero v1.10.0 // indirect github.com/spf13/cast v1.5.1 // indirect diff --git a/go.sum b/go.sum index 1bb42a91..6b5509e9 100644 --- a/go.sum +++ b/go.sum @@ -205,8 +205,6 @@ github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBa github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= -github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= @@ -288,12 +286,8 @@ github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aev github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= github.com/go-git/go-billy/v5 v5.1.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= -github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw= -github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0= github.com/go-git/go-git/v5 v5.3.0/go.mod h1:xdX4bWJ48aOrdhnl2XqHYstHbbp6+LFS4r4X+lNVprw= -github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -429,7 +423,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU= github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= @@ -459,13 +452,10 @@ github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.3.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/hc-install v0.4.0 h1:cZkRFr1WVa0Ty6x5fTvL1TuO1flul231rWkGH92oYYk= -github.com/hashicorp/hc-install v0.4.0/go.mod h1:5d155H8EC5ewegao9A4PUTMNPZaq+TbOzkJJZ4vrXeI= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws= github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= github.com/hashicorp/hcl/v2 v2.0.0/go.mod h1:oVVDG71tEinNGYCxinCYadcmKU9bglqW9pV3txagJ90= @@ -477,13 +467,7 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 h1:Pc5TCv9mbxFN6UVX0LH6CpQrdTM5YjbVI2w15237Pjk= github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A= github.com/hashicorp/terraform-exec v0.13.3/go.mod h1:SSg6lbUsVB3DmFyCPjBPklqf6EYGX0TlQ6QTxOlikDU= -github.com/hashicorp/terraform-exec v0.17.2 h1:EU7i3Fh7vDUI9nNRdMATCEfnm9axzTnad8zszYZ73Go= -github.com/hashicorp/terraform-exec v0.17.2/go.mod h1:tuIbsL2l4MlwwIZx9HPM+LOV9vVyEfBYu2GsO1uH3/8= github.com/hashicorp/terraform-json v0.10.0/go.mod h1:3defM4kkMfttwiE7VakJDwCd4R+umhSQnvJwORXbprE= -github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s= -github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= -github.com/hashicorp/terraform-plugin-docs v0.13.0 h1:6e+VIWsVGb6jYJewfzq2ok2smPzZrt1Wlm9koLeKazY= -github.com/hashicorp/terraform-plugin-docs v0.13.0/go.mod h1:W0oCmHAjIlTHBbvtppWHe8fLfZ2BznQbuv8+UD8OucQ= github.com/hashicorp/terraform-plugin-sdk v1.17.2 h1:V7DUR3yBWFrVB9z3ddpY7kiYVSsq4NYR67NiTs93NQo= github.com/hashicorp/terraform-plugin-sdk v1.17.2/go.mod h1:wkvldbraEMkz23NxkkAsFS88A1R9eUiooiaUZyS6TLw= github.com/hashicorp/terraform-plugin-test/v2 v2.2.1/go.mod h1:eZ9JL3O69Cb71Skn6OhHyj17sLmHRb+H6VrDcJjKrYU= @@ -541,7 +525,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= -github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= @@ -614,9 +597,6 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/f github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= -github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= -github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= -github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= @@ -673,7 +653,6 @@ github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLE github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.2.1/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8= github.com/zclconf/go-cty v1.8.2/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= -github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk= github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA= github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= @@ -702,7 +681,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= @@ -894,7 +872,6 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/opslevel/Taskfile.yml b/opslevel/Taskfile.yml index 843987a4..ea17e769 100644 --- a/opslevel/Taskfile.yml +++ b/opslevel/Taskfile.yml @@ -4,6 +4,14 @@ version: '3' tasks: + fix: + desc: Fix formatting and linting of go code + deps: [install-gofumpt, install-golangci-lint] + cmds: + - gofumpt -w . + - go mod tidy + - golangci-lint run --fix + lint: desc: Check formatting and linting of go code deps: [install-gofumpt, install-golangci-lint] @@ -12,14 +20,6 @@ tasks: - go vet ./... - golangci-lint run - lintfix: - desc: Fix formatting and linting of go code - deps: [install-gofumpt, install-golangci-lint] - cmds: - - gofumpt -w . - - go mod tidy - - golangci-lint run --fix - setup: desc: Setup go linter, formatter, and opslevel-go submodule cmds: @@ -29,9 +29,9 @@ tasks: setup-opslevel-go: desc: Setup go workspace to import opslevel-go + internal: true cmds: - - git submodule update --init - - git submodule update --remote + - git submodule update --init --remote - go work init || true - go work use . submodules/opslevel-go - echo "Workspace ready!" diff --git a/submodules/opslevel-go b/submodules/opslevel-go index 4d44122b..5c2b8b0f 160000 --- a/submodules/opslevel-go +++ b/submodules/opslevel-go @@ -1 +1 @@ -Subproject commit 4d44122b92578ea596c953a8ee9cedc6de4fb00a +Subproject commit 5c2b8b0fd3dacb2769be7c57efa085a48249b1e7 diff --git a/workspace/Taskfile.yml b/workspace/Taskfile.yml deleted file mode 100644 index 62ddbb02..00000000 --- a/workspace/Taskfile.yml +++ /dev/null @@ -1,104 +0,0 @@ -# https://taskfile.dev/ - -version: '3' - -tasks: - - apply: - desc: Run "terraform apply" - cmds: - - task: terraform-command - vars: { TF_COMMAND: "apply", TF_CMD_DIR: "{{.TASKFILE_DIR}}" } - - clean: - desc: Clean up terraform files from "workspace" - prompt: Remove '*.tfstate .terraform.lock.hcl ./terraform.* .terraform/**' from 'workspace' directory? - cmds: - - cmd: rm -rf *.tfstate .terraform.lock.hcl ./terraform.* .terraform/ - ignore_error: true - - destroy: - desc: Run "terraform destroy" in "workspace" - cmds: - - task: terraform-command - vars: { TF_COMMAND: "destroy", TF_CMD_DIR: "{{.TASKFILE_DIR}}" } - - init: - desc: Initialize terraform workspace - cmds: - - task: install-terraform - - './make_backend_tf.sh' - - touch main.tf - - task: terraform-command - vars: { TF_COMMAND: "init -upgrade", TF_CMD_DIR: "{{.TASKFILE_DIR}}" } - - lint: - desc: Validate and check format of terraform files in current directory - cmds: - - task: validate - - task: format - - lintfix: - desc: Format terraform files in current directory - cmds: - - task: format-fix - - plan: - desc: Run "terraform plan" in "workspace" - cmds: - - task: terraform-command - vars: { TF_COMMAND: "plan", TF_CMD_DIR: "{{.TASKFILE_DIR}}" } - - ######################################## - # internal (not directly called) tasks # - ######################################## - - format: - internal: true - desc: Run terraform format - cmds: - - cmd: echo "Listing all terraform files that need formatting..." - - task: terraform-command - vars: { TF_COMMAND: "fmt -recursive -check", TF_CMD_DIR: "{{.USER_WORKING_DIR}}" } - - format-fix: - internal: true - desc: Run terraform format - cmds: - - task: terraform-command - vars: { TF_COMMAND: "fmt -recursive -write=true", TF_CMD_DIR: "{{.USER_WORKING_DIR}}" } - - install-terraform: - internal: true - aliases: [get] - cmds: - - echo "Installing terraform..." - - task: install-terraform-mac-os - - echo -e "\nSuccess! 'terraform' installed." - - install-terraform-mac-os: - internal: true - platforms: [darwin] - cmds: - - brew tap hashicorp/tap - - brew install hashicorp/tap/terraform - preconditions: - - sh: 'which brew' - msg: '"brew" needed to install terraform - see https://brew.sh' - - terraform-command: - internal: true - cmds: ["terraform -chdir={{.TF_CMD_DIR}} {{.TF_COMMAND}} {{.CLI_ARGS}}"] - requires: - vars: [TF_COMMAND, TF_CMD_DIR] - preconditions: - - sh: 'which terraform' - msg: '"terraform" needed - run "brew install terraform"' - - validate: - internal: true - desc: Run "terraform validate" in current directory - dir: '{{.USER_WORKING_DIR}}' - cmds: - - task: terraform-command - vars: { TF_COMMAND: "validate", TF_CMD_DIR: "{{.USER_WORKING_DIR}}" } From 3893c825879719372d987b8cef70cfd68eb7edbd Mon Sep 17 00:00:00 2001 From: David Bloss Date: Fri, 19 Jan 2024 10:52:15 -0600 Subject: [PATCH 2/6] add task ci, use in Tests github workflow --- .github/workflows/tests.yml | 4 +--- Taskfile.yml | 8 ++++++++ opslevel/Taskfile.yml | 32 +++++++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b4986c7e..6ad37a25 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,9 +26,7 @@ jobs: version: 3.x repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Run Tests - run: |- - task go:setup-opslevel-go - task go:test + run: task ci - name: Upload Coverage run: |- bash <(curl -s https://codecov.io/bash) diff --git a/Taskfile.yml b/Taskfile.yml index 71d6d159..f2ada040 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -33,6 +33,14 @@ tasks: - mkdir -p {{.LOCATION}} - mv {{.BINARY}} {{.LOCATION}}/{{.BINARY}} + ci: + desc: Workflow to run in CI + cmds: + - task: go:setup + - task: go:has-latest-opslevel-go + - task: lint + - task: test + clean: desc: Clean up terraform files from "{{.WORKSPACE_DIR}}" dir: "{{.WORKSPACE_DIR}}" diff --git a/opslevel/Taskfile.yml b/opslevel/Taskfile.yml index ea17e769..5d24c215 100644 --- a/opslevel/Taskfile.yml +++ b/opslevel/Taskfile.yml @@ -1,6 +1,8 @@ # https://taskfile.dev/ version: '3' +env: + OPSLEVEL_GO_PKG: "github.com/opslevel/opslevel-go/v2024" tasks: @@ -8,15 +10,37 @@ tasks: desc: Fix formatting and linting of go code deps: [install-gofumpt, install-golangci-lint] cmds: + - task: update-opslevel-go - gofumpt -w . - go mod tidy - golangci-lint run --fix + has-latest-opslevel-go: + desc: Check if latest release of opslevel-go in go.mod + dir: "{{.ROOT_DIR}}" + silent: true + vars: + GO_WORK: "go.work" + TMP_GO_WORK: "tmp_go.work" + LATEST_OPSLEVEL_GO_VERSION: + sh: go list -u -m -versions github.com/opslevel/opslevel-go/v2024 | awk '{print $NF}' + cmds: + - if [[ -f {{.GO_WORK}} ]]; then mv {{.GO_WORK}} {{.TMP_GO_WORK}}; fi + - defer: if [[ -f {{.TMP_GO_WORK}} ]]; then mv {{.TMP_GO_WORK}} {{.GO_WORK}}; fi + - |- + if [[ {{.LATEST_OPSLEVEL_GO_VERSION}} == $(go list -m --json '{{.OPSLEVEL_GO_PKG}}' | jq -r '.Version') ]]; then + echo "Using latest version of opslevel-go - {{.LATEST_OPSLEVEL_GO_VERSION}}"; + else + echo "WARNING: current version of opslevel-go is behind '{{.LATEST_OPSLEVEL_GO_VERSION}}'" + echo "Run 'task fix' to get latest version" + exit 1 + fi + lint: desc: Check formatting and linting of go code deps: [install-gofumpt, install-golangci-lint] cmds: - - gofumpt -d . + - test -z "$(gofumpt -d -e . | tee /dev/stderr)" - go vet ./... - golangci-lint run @@ -43,6 +67,12 @@ tasks: - grep -v "/enum.go" coverage.out > coverage.txt silent: true + update-opslevel-go: + desc: Update opslevel-go version to latest release + dir: "{{.ROOT_DIR}}" + cmds: + - go get -u "{{.OPSLEVEL_GO_PKG}}" + ######################################## # internal (not directly called) tasks # ######################################## From a8faf13573bb4e7bdf67713e4a067ba27f25d677 Mon Sep 17 00:00:00 2001 From: David Bloss Date: Fri, 19 Jan 2024 10:56:41 -0600 Subject: [PATCH 3/6] run Tests github workflow only if Go code updated --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6ad37a25..5854b4ae 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,6 +4,10 @@ on: push: branches: [ main ] pull_request: + paths: + - '.github/workflows/tests.yml' + - 'go.mod' + - '**.go' jobs: test: From cd0e5e020ab6bd34ab1c6cdf318109dc751c2491 Mon Sep 17 00:00:00 2001 From: David Bloss Date: Mon, 22 Jan 2024 15:47:24 -0600 Subject: [PATCH 4/6] clean up Taskfile --- Taskfile.yml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index f2ada040..f4ccc26a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -130,18 +130,11 @@ tasks: install-terraform: internal: true - aliases: [get] + platforms: [darwin] cmds: - echo "Installing terraform..." - - task: install-terraform-mac-os + - which terraform > /dev/null || brew tap hashicorp/tap && brew install hashicorp/tap/terraform - echo -e "\nSuccess! 'terraform' installed." - - install-terraform-mac-os: - internal: true - platforms: [darwin] - cmds: - - brew tap hashicorp/tap - - brew install hashicorp/tap/terraform preconditions: - sh: 'which brew' msg: '"brew" needed to install terraform - see https://brew.sh' From cd554b36c409a1ad3c0f27fd09b68c50a8d3afcc Mon Sep 17 00:00:00 2001 From: David Bloss Date: Mon, 22 Jan 2024 15:54:59 -0600 Subject: [PATCH 5/6] fix format issues, update go.mod --- go.mod | 2 +- opslevel/common.go | 9 +++++---- opslevel/common_test.go | 3 ++- opslevel/resource_opslevel_filter.go | 1 + submodules/opslevel-go | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 1f3dec20..39202b46 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21 require ( github.com/hashicorp/terraform-plugin-sdk v1.17.2 + github.com/mitchellh/mapstructure v1.5.0 github.com/opslevel/opslevel-go/v2024 v2024.1.13 github.com/rs/zerolog v1.31.0 ) @@ -65,7 +66,6 @@ require ( github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/oklog/run v1.1.0 // indirect github.com/opslevel/moredefaults v0.0.0-20240112142637-078c8ff8ba9c // indirect diff --git a/opslevel/common.go b/opslevel/common.go index e4d8a8ec..0fa92a3e 100644 --- a/opslevel/common.go +++ b/opslevel/common.go @@ -2,13 +2,14 @@ package opslevel import ( "fmt" - "github.com/mitchellh/mapstructure" - "github.com/rs/zerolog/log" "sort" "strconv" "strings" "time" + "github.com/mitchellh/mapstructure" + "github.com/rs/zerolog/log" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/opslevel/opslevel-go/v2024" @@ -278,10 +279,10 @@ func flattenFilterPredicates(input []opslevel.FilterPredicate) []map[string]any if predicate.CaseSensitive == nil { o["case_sensitive"] = false o["case_insensitive"] = false - } else if *predicate.CaseSensitive == true { + } else if *predicate.CaseSensitive { o["case_sensitive"] = true o["case_insensitive"] = false - } else if *predicate.CaseSensitive == false { + } else { o["case_sensitive"] = false o["case_insensitive"] = true } diff --git a/opslevel/common_test.go b/opslevel/common_test.go index a3f492e9..2caf5296 100644 --- a/opslevel/common_test.go +++ b/opslevel/common_test.go @@ -2,9 +2,10 @@ package opslevel import ( "encoding/json" - "github.com/opslevel/opslevel-go/v2024" "reflect" "testing" + + "github.com/opslevel/opslevel-go/v2024" ) func compareKey(t *testing.T, m map[string]interface{}, key string, exp interface{}) { diff --git a/opslevel/resource_opslevel_filter.go b/opslevel/resource_opslevel_filter.go index 9ecf2eb5..4134524e 100644 --- a/opslevel/resource_opslevel_filter.go +++ b/opslevel/resource_opslevel_filter.go @@ -2,6 +2,7 @@ package opslevel import ( "errors" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/opslevel/opslevel-go/v2024" diff --git a/submodules/opslevel-go b/submodules/opslevel-go index 5c2b8b0f..b21e3b9b 160000 --- a/submodules/opslevel-go +++ b/submodules/opslevel-go @@ -1 +1 @@ -Subproject commit 5c2b8b0fd3dacb2769be7c57efa085a48249b1e7 +Subproject commit b21e3b9b5fbf10a2ae97704df766bdc986ecc999 From 0cb89e32482152e9d198eb4923678a8e8ef489f8 Mon Sep 17 00:00:00 2001 From: David Bloss Date: Mon, 22 Jan 2024 15:58:18 -0600 Subject: [PATCH 6/6] add cache to CI --- .github/workflows/release.yml | 9 ++++++++- .github/workflows/tests.yml | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7b9ca8c3..784ba22d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,7 +32,14 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: 1.21 + go-version-file: go.mod + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Ensure Changelog run: | if test -f ./.changes/${{ steps.next_version.outputs.version_tag }}.md diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5854b4ae..d920eb6c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -29,6 +29,13 @@ jobs: with: version: 3.x repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Cache Go modules + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Run Tests run: task ci - name: Upload Coverage