Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: tf-lock-url #211

Draft
wants to merge 103 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
178be87
WIP: tf-lock-url
bukzor May 1, 2024
b87e7df
Merge branch 'main' into kneeyo1/fix-tf-lock-acquire
kneeyo1 May 2, 2024
d10c6f9
updating cache properly
kneeyo1 May 22, 2024
1bc7d30
auto-commit: GHA deps, for test
May 22, 2024
af14332
auto-commit: GHA deps, for test
May 22, 2024
b0971c2
auto-commit: GHA deps, for test
May 22, 2024
456bba5
auto-commit: GHA deps, for test
May 22, 2024
1d6034b
auto-commit: GHA deps, for test
May 22, 2024
c3d2b46
auto-commit: GHA deps, for test
May 22, 2024
2aaf3ee
auto-commit: GHA deps, for test
May 22, 2024
ed1fa44
auto-commit: GHA deps, for test
May 22, 2024
619301a
auto-commit: GHA deps, for test
May 22, 2024
5440e0f
auto-commit: GHA deps, for test
May 22, 2024
2cc802f
auto-commit: GHA deps, for test
May 22, 2024
5a9c760
auto-commit: GHA deps, for test
May 22, 2024
9c2a255
auto-commit: GHA deps, for test
May 22, 2024
60a07e8
auto-commit: GHA deps, for test
May 22, 2024
a84de12
auto-commit: GHA deps, for test
May 22, 2024
2e6c2a4
auto-commit: GHA deps, for test
May 22, 2024
1ecac36
auto-commit: GHA deps, for test
May 22, 2024
866bba9
auto-commit: GHA deps, for test
May 22, 2024
16c6849
auto-commit: GHA deps, for test
May 22, 2024
c14c0b8
debugging github
kneeyo1 May 22, 2024
e9650da
auto-commit: GHA deps, for test
May 22, 2024
ecb7946
auto-commit: GHA deps, for test
May 23, 2024
0406c02
auto-commit: GHA deps, for test
May 23, 2024
2ea3a80
auto-commit: GHA deps, for test
May 23, 2024
71ce342
auto-commit: GHA deps, for test
May 23, 2024
bf390b2
auto-commit: GHA deps, for test
May 23, 2024
af457a8
auto-commit: GHA deps, for test
May 23, 2024
fcb7c3e
auto-commit: GHA deps, for test
May 23, 2024
3081b6d
auto-commit: GHA deps, for test
May 23, 2024
5a4fb5e
auto-commit: GHA deps, for test
May 23, 2024
a70109b
auto-commit: GHA deps, for test
May 23, 2024
9cd064a
auto-commit: GHA deps, for test
May 24, 2024
9e50240
auto-commit: GHA deps, for test
May 24, 2024
b05e6cb
auto-commit: GHA deps, for test
May 24, 2024
4f5ae51
auto-commit: GHA deps, for test
May 28, 2024
e8c4ae9
auto-commit: GHA deps, for test
May 28, 2024
d786221
auto-commit: GHA deps, for test
May 28, 2024
9b755d8
auto-commit: GHA deps, for test
May 28, 2024
d214d8b
auto-commit: GHA deps, for test
May 28, 2024
669eff4
auto-commit: GHA deps, for test
May 28, 2024
a771655
auto-commit: GHA deps, for test
May 28, 2024
cf01060
auto-commit: GHA deps, for test
May 28, 2024
c817650
auto-commit: GHA deps, for test
May 28, 2024
9c9ac5d
auto-commit: GHA deps, for test
May 28, 2024
933876c
auto-commit: GHA deps, for test
May 28, 2024
ae1bf71
auto-commit: GHA deps, for test
May 28, 2024
2c72d59
auto-commit: GHA deps, for test
May 28, 2024
e16a9bd
auto-commit: GHA deps, for test
May 28, 2024
3e10fc0
auto-commit: GHA deps, for test
May 28, 2024
3741c29
auto-commit: GHA deps, for test
May 28, 2024
afcb02c
auto-commit: GHA deps, for test
May 28, 2024
802697f
auto-commit: GHA deps, for test
May 28, 2024
ea0ac96
removing the extra stuff
kneeyo1 May 29, 2024
8a2f58a
added basic setup, handle-tflock-cache, and python formatting
kneeyo1 May 29, 2024
5062017
add the terraformer stuff
kneeyo1 May 29, 2024
7cf1c63
make tf-lock-info use gcloud storage cat
kneeyo1 May 29, 2024
599c30d
fix chmod
kneeyo1 May 29, 2024
28cb2c2
auto-commit: GHA deps, for test
May 29, 2024
04a9d51
auto-commit: GHA deps, for test
May 29, 2024
da2fcc1
auto-commit: GHA deps, for test
May 30, 2024
d4fcea3
oops forgot to add the new file
kneeyo1 May 30, 2024
d973f6a
auto-commit: GHA deps, for test
May 30, 2024
ea3eb66
auto-commit: GHA deps, for test
May 30, 2024
6a89a53
auto-commit: GHA deps, for test
May 30, 2024
89d3a71
auto-commit: GHA deps, for test
May 31, 2024
bf672a9
auto-commit: GHA deps, for test
May 31, 2024
621b024
auto-commit: GHA deps, for test
May 31, 2024
9ebef71
auto-commit: GHA deps, for test
May 31, 2024
f3c4287
auto-commit: GHA deps, for test
May 31, 2024
5941b53
auto-commit: GHA deps, for test
May 31, 2024
ecfb447
chmod
kneeyo1 May 31, 2024
ca3e96e
auto-commit: GHA deps, for test
May 31, 2024
7a690aa
reformat
kneeyo1 May 31, 2024
5cda445
unlock many matrix jobs
kneeyo1 May 31, 2024
c2b0346
list-terraformers now has a gha summary
bukzor May 31, 2024
1ef47e9
set missing DEBUG vars
bukzor May 31, 2024
7eb7b8b
requirements: bump
bukzor May 31, 2024
5e7ea94
global is unused
bukzor May 31, 2024
d5e5a71
unlock: list slices, not lockfiles
bukzor May 31, 2024
6cffdad
debug less noisy
bukzor May 31, 2024
47f3e1b
give chmod
kneeyo1 May 31, 2024
abfc228
add input for matrix
kneeyo1 May 31, 2024
adc491f
we have shorter matrix name now
kneeyo1 Jun 1, 2024
ffe6084
tf step summary already will cd
kneeyo1 Jun 1, 2024
e4432d7
added path to matrix fan in
kneeyo1 Jun 1, 2024
d3a45ff
added path to matrix fan in
kneeyo1 Jun 1, 2024
b91eddb
debug to see if exists
kneeyo1 Jun 2, 2024
c93f1a3
debug to see if exists
kneeyo1 Jun 2, 2024
0bb3293
debug to see if exists
kneeyo1 Jun 2, 2024
3880d9a
debug to see if exists
kneeyo1 Jun 2, 2024
0a09b8e
debug to see if exists
kneeyo1 Jun 3, 2024
08fc784
debug to see if exists
kneeyo1 Jun 3, 2024
ea62fce
auto-commit: GHA deps, for test
Jun 3, 2024
4665d72
auto-commit: GHA deps, for test
Jun 3, 2024
2fa5fe7
auto-commit: GHA deps, for test
Jun 3, 2024
bc45373
hopefully this works?
kneeyo1 Jun 3, 2024
2313c6a
revert matrix-io path; some comments
bukzor Jun 3, 2024
53ad547
auto-commit: GHA deps, for test
Jun 5, 2024
0e68854
Move cache before cd
kneeyo1 Jun 5, 2024
a371bad
find the correct lock id
kneeyo1 Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/actions/basic-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Basic-Setup
# This is derived from the Setup github action.
# It omits several steps, and is mainly used by tacos_unlock.

inputs:
ssh-private-key:
description: "Private SSH key to use for git clone"
type: string
default: ""
user:
description: the username that will be used for following steps
required: false
default: ${{github.triggering_actor}}
shell:
description: "private -- do not use"
default: env ./tacos-gha/lib/ci/default-shell {0}

runs:
using: composite

steps:
- uses: ./tacos-gha/.github/actions/just-the-basics

- name: tell TF username and PR
uses: ./tacos-gha/.github/actions/set-username-and-hostname
with:
user: ${{inputs.user}}

- name: Set up SSH agent
if: inputs.ssh-private-key != ''
uses: webfactory/ssh-agent@v0.8.0
with:
ssh-private-key: ${{ inputs.ssh-private-key }}

# These fix most ownership, permission issues, but the .ssh config files
# still get the wrong ownership, fixed in the next step.
ssh-agent-cmd: |-
./tacos-gha/lib/ci/bin/sudo-ssh-agent
ssh-add-cmd: |-
./tacos-gha/lib/ci/bin/sudo-ssh-add
- name: Fix .ssh permissions
shell: ${{inputs.shell}}
if: inputs.ssh-private-key != ''
run: |
: fix ssh config ownership
sudo chown -v -R "$(id -un):$(id -gn)" ~/.ssh
: Show SSH agent pubkeys
ssh-add -L
: ... hashes too
ssh-add -l
# this should really be default behavior:
- shell: ${{inputs.shell}}
run: |
gha-set-env 'TF_VERSION' < "$(nearest-config-file .terraform-version)"
gha-set-env 'TERRAGRUNT_VERSION' < "$(nearest-config-file .terragrunt-version)"
- name: Setup Terragrunt
uses: autero1/action-terragrunt@v1.3.2
with:
terragrunt_version: ${{env.TERRAGRUNT_VERSION}}

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: ${{ env.TF_VERSION }}
11 changes: 9 additions & 2 deletions .github/actions/matrix-fan-in/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ runs:
uses: actions/download-artifact@v4
with:
pattern: ${{ env.artifact_name }} *${{ inputs.pattern }}*
path: matrix-fan-in.tmp

path: ${{ inputs.path }}
- name: fix up archive files
shell: bash
env:
Expand All @@ -41,3 +40,11 @@ runs:
# note: "$GITHUB_ACTION_PATH" contains this action directory's path
run: |
"$GITHUB_ACTION_PATH/"rename-tmp-dirs.sh "$MATRIX_FAN_OUT_PATH"

## DEBUG:
# - name: Start SSH
# if: always()
# uses: lhotari/action-upterm@v1
# with:
# ## limits ssh access and adds the ssh public keys of the listed GitHub users
# limit-access-to-users: bukzor,kneeyo1
2 changes: 1 addition & 1 deletion .github/actions/matrix-fan-in/rename-tmp-dirs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path="$1"
mkdir -p "$path"

: directory name fixup
find ./matrix-fan-in.tmp \
find "$path"\
-mindepth 1 \
-maxdepth 1 \
-print0 \
Expand Down
5 changes: 4 additions & 1 deletion .github/actions/matrix-fan-out/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
shell:
description: "private -- do not use"
default: bash -euxo pipefail {0}
matrix:
description: defaults to toJSON(matrix)
default: ${{ toJSON(matrix) }}

runs:
using: "composite"
Expand All @@ -19,7 +22,7 @@ runs:
- shell: ${{ inputs.shell }}
env:
MATRIX_FAN_OUT_PATH: ${{ inputs.path }}
GHA_MATRIX_CONTEXT: ${{ toJSON(matrix) }}
GHA_MATRIX_CONTEXT: ${{ inputs.matrix }}
run: |
"$GITHUB_ACTION_PATH/"prepare.sh |
tee -a "$GITHUB_ENV"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/selftest-matrix-io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
exec >&2 # our only output is logging
printf "keys=[10, 27]" >> "$GITHUB_OUTPUT"
# for scale testing:
###seq 30 | shuf | jq -R | jq -cs | tee -a "$GITHUB_OUTPUT"
#seq 30 | shuf | jq -R | jq -cs | tee -a "$GITHUB_OUTPUT"

fan-out:
name: Compute Squares
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tacos_apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:

runs-on: ubuntu-latest
permissions:
contents: read
contents: write
pull-requests: write
id-token: write

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tacos_detect_drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:

runs-on: ubuntu-latest
permissions:
contents: read
contents: write
pull-requests: write
id-token: write

Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/tacos_plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
default: refs/heads/stable
debug:
type: string
default: 0
default: "0"
secrets:
ssh-private-key:
description: "Private SSH key to use for git clone"
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:

runs-on: ubuntu-latest
permissions:
contents: read
contents: write
pull-requests: write
id-token: write

Expand Down Expand Up @@ -128,12 +128,10 @@ jobs:
id: main
run: |
"$TACOS_GHA_HOME/"lib/ci/tacos-plan

- name: Save matrix result
# we need to show any errors to end-users
if: always()
uses: ./tacos-gha/.github/actions/matrix-fan-out

summary:
needs: tacos_plan
# we need to report failures, too
Expand Down
54 changes: 35 additions & 19 deletions .github/workflows/tacos_unlock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ env:
GETSENTRY_SAC_VERB: state-admin

jobs:
determine-tf-root-modules:
name: List Slices
determine-terraformers:
name: list terraformers
if: |
false
|| github.event.action != 'labeled'
|| github.event.label.name == ':taco::unlock'
outputs:
slices: ${{ steps.list-slices.outputs.slices }}

terraformers: ${{ steps.list-terraformers.outputs.terraformers }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- name: Checkout IAC
uses: actions/checkout@v4
Expand All @@ -55,30 +53,32 @@ jobs:
repository: ${{inputs.tacos_gha_repo}}
ref: ${{inputs.tacos_gha_ref}}
path: tacos-gha

- name: List Slices
id: list-slices
uses: ./tacos-gha/.github/actions/list-slices
- name: basic-setup
uses: ./tacos-gha/.github/actions/basic-setup
- name: List Terraformers
id: list-terraformers
run: |
gha-log-as-step-summary \
"$TACOS_GHA_HOME/"lib/ci/list-terraformers

tacos_unlock:
name: TACOS Unlock
needs: [determine-tf-root-modules]
if: |
needs.determine-tf-root-modules.outputs.slices != '[]'
needs: [determine-terraformers]
strategy:
fail-fast: false
matrix:
tf-root-module:
${{ fromJSON(needs.determine-tf-root-modules.outputs.slices) }}

terraformer:
${{ fromJSON(needs.determine-terraformers.outputs.terraformers) }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
id-token: write

env:
TF_ROOT_MODULE: ${{matrix.tf-root-module}}
SUDO_GCP_SERVICE_ACCOUNT: ${{fromJSON(matrix.terraformer).SUDO_GCP_SERVICE_ACCOUNT}}
GETSENTRY_SAC_OIDC: ${{fromJSON(matrix.terraformer).GETSENTRY_SAC_OIDC}}
SLICES: ${{toJSON(fromJSON(matrix.terraformer).slices)}}
steps:
- name: Checkout IAC
uses: actions/checkout@v4
Expand All @@ -88,8 +88,8 @@ jobs:
repository: ${{inputs.tacos_gha_repo}}
ref: ${{inputs.tacos_gha_ref}}
path: tacos-gha
- name: Setup
uses: ./tacos-gha/.github/actions/setup
- name: basic-setup
uses: ./tacos-gha/.github/actions/basic-setup
with:
ssh-private-key: ${{ secrets.ssh-private-key }}
# We explicitly list the low-concern actions, during which users will
Expand All @@ -113,15 +113,28 @@ jobs:
|| github.triggering_actor
}}

- name: gcp auth
id: auth
uses: google-github-actions/auth@v2.1.1
with:
workload_identity_provider: ${{env.GETSENTRY_SAC_OIDC}}
service_account: ${{env.SUDO_GCP_SERVICE_ACCOUNT}}

- name: Unlock
id: main
run: |
tf-step-summary "TACOS Unlock" "$TACOS_GHA_HOME/"lib/tacos/unlock
# release all tfstate locks currently held
jq <<< "$SLICES" -r '.[]' | ./tacos-gha/lib/ci/unlock

- name: Save matrix result
# we need to show any errors to end-users
if: always()
uses: ./tacos-gha/.github/actions/matrix-fan-out
with:
path: |
**/matrix-fan-out
matrix: |
{ "terraformer": "${{env.SUDO_GCP_SERVICE_ACCOUNT}}" }

summary:
needs: tacos_unlock
Expand All @@ -142,6 +155,9 @@ jobs:
uses: ./tacos-gha/.github/actions/just-the-basics
- name: Run matrix-fan-in
uses: ./tacos-gha/.github/actions/matrix-fan-in
with:
path: |
**/matrix-fan-out
- name: Summarize
id: summary
run: |
Expand Down
2 changes: 2 additions & 0 deletions activate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
_here="$(readlink -f "$(dirname "${BASH_SOURCE:-$0}")")"

export TACOS_GHA_HOME="$_here"

export PYTHONPATH="$TACOS_GHA_HOME${PYTHONPATH:+:$PYTHONPATH}"
export PATH="$TACOS_GHA_HOME/bin${PATH:+:$PATH}}"
export DEBUG="${DEBUG:-}"

Expand Down
1 change: 1 addition & 0 deletions bin/tf-lock-url
1 change: 1 addition & 0 deletions lib/ci/bin/default-shell-post-sudo
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -euo pipefail
HERE="$(dirname "$(readlink -f "$0")")"
umask 002 # stuff is group-writable by default

export DEBUG="${DEBUG:-}"
if (( DEBUG > 0 )); then
gha-printenv post-sudo
fi
Expand Down
4 changes: 3 additions & 1 deletion lib/ci/bin/terragrunt-noninteractive
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export DEBUG="${DEBUG:-}"
if (( DEBUG >= 1 )); then
export TF_LOG=debug
export TERRAGRUNT_LOG_LEVEL=info
set -x
fi
if (( DEBUG >= 3 )); then
export TERRAGRUNT_LOG_LEVEL=debug
if (( DEBUG >= 4 )); then
set -x
fi
elif (( DEBUG <= 0 )); then
export TERRAGRUNT_LOG_LEVEL=error
fi
Expand Down
6 changes: 6 additions & 0 deletions lib/ci/bin/unlock-one
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -euo pipefail

export TF_ROOT_MODULE=$1

tf-step-summary "TACOS Unlock" tf-lock-release
10 changes: 10 additions & 0 deletions lib/ci/list-terraformers
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -euo pipefail

python3 -m lib.tacos.terraformers |
jq -R |
jq -cs |
gha-set-output terraformers |
# prettify
jq . \
;
30 changes: 18 additions & 12 deletions lib/ci/tacos_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
FILE_NOT_FOUND = "(file not found: {!r}"

SectionFunction = Callable[[Sequence["SliceSummary"], int], Lines]
TacosSummary = Callable[
[Collection["SliceSummary"], ByteBudget, str, int], Lines
]


def ensmallen(lines: Lines, size_limit: int) -> Lines:
Expand Down Expand Up @@ -318,11 +321,20 @@ def error_section(
return mksection(budget, slices, title="Errors", first=True)


def main_helper(
tacos_summary: Callable[
[Collection[SliceSummary], ByteBudget, str, int], Lines
],
) -> ExitCode:
def process_slices(
tacos_summary: TacosSummary, slices: Collection[SliceSummary]
) -> Iterable[Line]:
budget = ByteBudget(COMMENT_SIZE_LIMIT - 1000)

from os import environ

run_id = int(environ["GITHUB_RUN_ID"])
repository = environ["GITHUB_REPOSITORY"]

return tacos_summary(slices, budget, repository, run_id)


def main_helper(tacos_summary: TacosSummary) -> ExitCode:
from sys import argv

try:
Expand All @@ -332,14 +344,8 @@ def main_helper(

path = OSPath(arg)
slices = tuple(SliceSummary.from_matrix_fan_in(path))
budget = ByteBudget(COMMENT_SIZE_LIMIT - 1000)

from os import environ

run_id = int(environ["GITHUB_RUN_ID"])
repository = environ["GITHUB_REPOSITORY"]

for line in tacos_summary(slices, budget, repository, run_id):
for line in process_slices(tacos_summary, slices):
print(line)

return 0
Loading
Loading