Skip to content

Commit

Permalink
Merge pull request #3 from silinternational/develop
Browse files Browse the repository at this point in the history
Release 0.1.2 - Increase Variable Set limit from 20 to 100
  • Loading branch information
dalenewby committed Aug 6, 2024
2 parents 9e277d0 + a575202 commit dd9cbdb
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 dd9cbdb

Please sign in to comment.