Skip to content

Commit

Permalink
Increase Variable Set limit from 20 to 100
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dalenewby committed Aug 5, 2024
1 parent 69b953c commit a575202
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
15 changes: 13 additions & 2 deletions tfc-dump.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

0 comments on commit a575202

Please sign in to comment.