From a575202077667f967bf501122d5e719d26cedea5 Mon Sep 17 00:00:00 2001 From: Dale Newby Date: Mon, 5 Aug 2024 16:03:13 -0400 Subject: [PATCH] Increase Variable Set limit from 20 to 100 By default, the list of Variable Sets is limited to 20. The limit has been increased to 100. An error message is printed if there are more than 100 Variable Sets to be backed up. --- README.md | 2 +- tfc-dump.pl | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c80ca82..d8cf150 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Spaces in the variable set name are replaced with hyphens (`-`). ## Restrictions The code assumes that all of the Terraform Cloud Variable Sets are contained -within the first result page of 20 entries. +within the first result page of 100 entries. ## Docker Hub This image is built automatically on Docker Hub as [silintl/tfc-backup-b2](https://hub.docker.com/r/silintl/tfc-backup-b2/) diff --git a/tfc-dump.pl b/tfc-dump.pl index 935f956..53c034c 100755 --- a/tfc-dump.pl +++ b/tfc-dump.pl @@ -109,16 +109,18 @@ ### WARNING ### # # This code assumes that all of the TFC Variable Sets are contained within -# the first result page of 20 entries. This was true for SIL in December 2022. +# the first result page of 100 entries. This was true for SIL in August 2024. # #### my @vs_names; my @vs_ids; +my $pg_size = 100; +my $total_count; my $tmpfile = `mktemp`; chomp($tmpfile); -$curl_query = "\"https://app.terraform.io/api/v2/organizations/${tfc_org_name}/varsets\""; +$curl_query = "\"https://app.terraform.io/api/v2/organizations/${tfc_org_name}/varsets?page%5Bsize%5D=${pg_size}\""; $curl_cmd = "curl $curl_headers --output $tmpfile $curl_query"; system($curl_cmd); @@ -154,6 +156,15 @@ system($curl_cmd); } +# Get the number of Variable Sets + +$jq_cmd = "cat $tmpfile | jq '.meta.total-count'"; +$total_count = `$jq_cmd`; unlink($tmpfile); +if ($total_count > $pg_size) { + print STDERR "WARNING: ${total_count}-${pg_size} Variable Sets were not backed up.\n"; + exit(1); +} + exit(0);